Skip to content

fix: strip additional_contexts and resolve relative build contexts#107

Open
AaronFeledy wants to merge 3 commits intomainfrom
fix/additional-contexts-build-context
Open

fix: strip additional_contexts and resolve relative build contexts#107
AaronFeledy wants to merge 3 commits intomainfrom
fix/additional-contexts-build-context

Conversation

@AaronFeledy
Copy link
Member

@AaronFeledy AaronFeledy commented Mar 10, 2026

Problem

Two related build issues with the Lagoon plugin:

  1. additional_contexts with service: references fail — Upstream lagoon-examples/drupal-base added additional_contexts in Aug 2025 to enforce BuildKit build ordering. Lando splits services into separate compose files, so Docker can't resolve service:cli across files and treats it as a filesystem path (~/.lando/compose/drupalbase/service:cli), causing all leia-tests to fail.

  2. build.context always forced to project root_lagoon.js rewrites build.context to path.join(options.root) regardless of the original value, breaking monorepo setups where services use non-root contexts (e.g. context: frontend).

Fix

  • Strip build.additional_contexts in lib/config.js during service parsing. The CLI_IMAGE build arg already handles cross-service image references (ARG CLI_IMAGEFROM ${CLI_IMAGE} AS cli), making additional_contexts redundant for local dev.

  • Use path.resolve instead of path.join in _lagoon.js so relative build contexts resolve correctly against the project root. context: . still resolves to root (no regression), but context: frontend now correctly resolves to <root>/frontend.

Testing

  • Unit tests pass
  • The leia-test failures in CI (drupal9-base, all-services, proxy-tests) should be resolved by this fix since the upstream drupal-base example now uses additional_contexts

Fixes #7
Fixes #53


Note

Medium Risk
Touches Lagoon service build configuration, which can affect how images are built and may break projects relying on current (incorrect) context rewriting or on additional_contexts behavior. Scope is limited to local compose/service parsing and build context normalization (no auth/data handling).

Overview
Fixes Lagoon build compatibility in two places.

builders/_lagoon.js now resolves build.context relative to the project root (instead of forcing root), enabling non-root build contexts in monorepos. lib/config.js strips build.additional_contexts during service parsing to avoid Docker service: context references that can’t resolve when Lando splits services into separate compose files.

Updates the Drupal 9 base example README with verification steps to confirm images build via the shared CLI image and that generated compose files do not contain additional_contexts.

Written by Cursor Bugbot for commit 13c609d. This will update automatically on new commits. Configure here.

- Strip build.additional_contexts from parsed service config since Lando
  splits services into separate compose files and service: refs cannot
  resolve across them. The CLI_IMAGE build arg handles cross-service
  image references instead.

- Use path.resolve instead of path.join for build.context so relative
  contexts (eg context: frontend for monorepos) resolve correctly
  against the project root instead of always being forced to root.

Fixes #7, fixes #53
@netlify
Copy link

netlify bot commented Mar 10, 2026

Deploy Preview for lando-lagoon failed. Why did it fail? →

Name Link
🔨 Latest commit 13c609d
🔍 Latest deploy log https://app.netlify.com/projects/lando-lagoon/deploys/69af976f2358b9000821142e

… stripping

Adds assertions to drupal9-base leia test:
- Verify nginx and php services have /app/web/index.php (copied from
  cli via CLI_IMAGE build arg, proving cross-service builds work)
- Verify additional_contexts is stripped from generated compose files
grep -c exits non-zero when count is 0, causing the test to fail
even though the assertion is correct. Use grep + exit 1 pattern instead.
@tobybellwood
Copy link
Collaborator

Not sure if you want a formal review from us, but this makes sense - when users first encountered this with Lando, we told them to remove the additional_contexts, so I can't foresee it causing too many issues. Obviously, any newcomers can use the templates straight OOTB now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker Compose v2 orchestrator doesn't work with Lando start Lando doesn't seem to respect build context with Lagoon

2 participants