Skip to content

Comments

feat(ecr-assets): add support for docker build context#36930

Open
cogwirrel wants to merge 1 commit intoaws:mainfrom
cogwirrel:feat/docker-build-context
Open

feat(ecr-assets): add support for docker build context#36930
cogwirrel wants to merge 1 commit intoaws:mainfrom
cogwirrel:feat/docker-build-context

Conversation

@cogwirrel
Copy link
Member

Issue # (if applicable)

Fixes #31598

Reason for this change

Add support for docker's --build-context flag in docker builds. This is useful for a few reasons outlined in the linked issue (and other similar issues), such as:

  • Sharing files from directories outside the Docker build directory
  • Using specific image versions as build contexts (docker-image://alpine:latest)
  • Referencing remote URLs as build contexts

Description of changes

Adds support for Docker's --build-context flag when building Docker image assets. This allows users to specify additional named build contexts that can be referenced in Dockerfiles via COPY --from=<name>.

  • Added buildContexts (optional Record<string, string>) to DockerBuildOptions, DockerImageAssetOptions, DockerImageAssetInvalidationOptions, and DockerImageAssetSource
  • Updated DockerImage.fromBuild() to pass --build-context key=value flags to the docker build command
  • Wired buildContexts through the full asset pipeline: DockerImageAsset → synthesizer → asset manifest → cloud assembly schema
  • Added token validation for buildContexts keys and values (same as buildArgs)
  • Added buildContexts to asset hash invalidation (controllable via invalidation.buildContexts)
  • Added ASSET_RESOURCE_METADATA_DOCKER_BUILD_CONTEXTS_KEY metadata constant
  • Updated the aws-ecr-assets README with documentation and usage example

In terms of design decisions, this follows the same pattern as buildArgs.

This requires the CLI changes in aws/aws-cdk-cli#1128 to be released first.

Describe any new or updated permissions being added

N/A

Description of how you validated changes

Integration test, using linked local AWS CDK CLI with changes from aws/aws-cdk-cli#1128

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@cogwirrel cogwirrel requested a review from a team as a code owner February 10, 2026 06:09
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Feb 10, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team February 10, 2026 06:09
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results48 ran48 passed
TestResult
No test annotations available

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates48 ran48 passed
TestResult
No test annotations available

@cogwirrel cogwirrel changed the title feat(aws-ecr-assets): add support for docker build context feat(ecr-assets): add support for docker build context Feb 10, 2026
@aws-cdk-automation aws-cdk-automation dismissed their stale review February 10, 2026 06:16

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@cogwirrel cogwirrel force-pushed the feat/docker-build-context branch from 520b1c1 to 329214b Compare February 17, 2026 19:51
Add support for docker's --build-context flag in docker builds.

Fixes aws#31598
@cogwirrel cogwirrel force-pushed the feat/docker-build-context branch from 1b3bd62 to a60f41a Compare February 18, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(@aws-cdk/aws-ecr-assets): DockerImageAsset - support --build-context flag

2 participants