diff --git a/builders/_lagoon.js b/builders/_lagoon.js index 45a75e7..c7e5860 100644 --- a/builders/_lagoon.js +++ b/builders/_lagoon.js @@ -20,8 +20,11 @@ module.exports = { const hostnames = _.get(options, '_app.lagoon.containers', []); // Normalize the dockerfile situation - // We need to do this again since this isnt technically an override - if (_.has(lagoon, 'build.context')) lagoon.build.context = path.join(options.root); + // Resolve build context relative to the project root so non-root contexts + // (eg context: frontend) work correctly instead of always forcing root + if (_.has(lagoon, 'build.context')) { + lagoon.build.context = path.resolve(options.root, lagoon.build.context); + } // Handle portfoward in the usual way if (options.portforward) { diff --git a/examples/drupal9-base/README.md b/examples/drupal9-base/README.md index 3049337..91c282f 100644 --- a/examples/drupal9-base/README.md +++ b/examples/drupal9-base/README.md @@ -41,6 +41,16 @@ docker ps --filter label=com.docker.compose.project | grep Up | grep drupalbase_ docker ps --filter label=com.docker.compose.project | grep Up | grep drupalbase_php_1 docker ps --filter label=com.docker.compose.project | grep Up | grep drupalbase_cli_1 +# Should have built nginx and php from the cli image via CLI_IMAGE build arg +cd drupal +lando ssh -s cli -c "test -f /app/web/index.php" +lando ssh -s nginx -c "test -f /app/web/index.php" +lando ssh -s php -c "test -f /app/web/index.php" + +# Should not have additional_contexts in the generated compose files +cd drupal +cat ~/.lando/compose/drupalbase-* 2>/dev/null | grep "additional_contexts" && exit 1 || true + # Should ssh against the cli container by default cd drupal lando ssh -c "env | grep LAGOON=" | grep cli-drupal diff --git a/lib/config.js b/lib/config.js index 1da63f3..6361af2 100644 --- a/lib/config.js +++ b/lib/config.js @@ -44,11 +44,20 @@ exports.loadConfigFiles = baseDir => { */ exports.parseServices = (services, recipeConfig) => _(services) // Remove unneeded things from the docker config and determine the type of the service - .map((config, name) => _.merge({}, { - name, - type: getLabel(config.labels), - compose: _.omit(config, ['volumes', 'volumes_from', 'networks', 'user']), - config: recipeConfig, - })) + .map((config, name) => { + // Strip additional_contexts from build config since Lando splits services + // into separate compose files and service: refs cant resolve across them + if (_.has(config, 'build.additional_contexts')) { + config = _.cloneDeep(config); + delete config.build.additional_contexts; + } + + return _.merge({}, { + name, + type: getLabel(config.labels), + compose: _.omit(config, ['volumes', 'volumes_from', 'networks', 'user']), + config: recipeConfig, + }); + }) // Return .value();