All files / services/platformsh-php builder.js

0% Statements 0/14
0% Branches 0/5
0% Functions 0/6
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                                                                                         
'use strict';
 
// Modules
const _ = require('lodash');
 
// Builder
module.exports = {
  name: 'platformsh-php',
  config: {
    confSrc: __dirname,
    legacy: ['7.1', '7.0', '5.5', '5.4', '5.3'],
    supportedIgnore: true,
    volumes: ['/usr/local/bin', '/mnt'],
  },
  parent: '_platformsh_appserver',
  builder: (parent, config) => class LandoPlatformshPhp extends parent {
    constructor(id, options = {}, factory) {
      options = _.merge({}, config, options);
      // Get route for this service
      const primaryRoute = _(_.get(options, '_app.platformsh.routes', []))
        .map((config, url) => _.merge({}, config, {url}))
        .filter(route => route.type === 'upstream')
        .filter(route => route.upstream.split(':')[0] === options.name)
        .orderBy('primary', ['desc'])
        .thru(routes => !_.isEmpty(routes) ? routes[0].url : undefined)
        .value();
      // Get the remote host
      const hostIP = _.get(options, 'runConfig.data.host_ip', 'host.docker.internal');
 
      // Build the php
      const php = {
        image: `docker.registry.platform.sh/php-${options.version}`,
        volumes: options.volumes,
        ports: ['80'],
 
        // Set xdebug things, should be safe to set these regardless of whether
        // the extensions is enabled or not, should also be safe to mix xdebug2
        // and xdebug3
        environment: {
          XDEBUG_CONFIG: `client_host=${hostIP} remote_host=${hostIP}`,
          PHP_IDE_CONFIG: `serverName=${options.name}`,
        },
      };
 
      // Add some stuff if we have a primary route
      if (primaryRoute) php.environment.DRUSH_OPTIONS_URI = primaryRoute;
 
      // Add in the php service and push downstream
      super(id, options, {services: _.set({}, options.name, php)});
    };
  },
};