Skip to content

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

Merged
mergify[bot] merged 1 commit intoaws:mainfrom
cogwirrel:feat/docker-build-context
Mar 25, 2026
Merged

feat(ecr-assets): add support for docker build context#36930
mergify[bot] merged 1 commit intoaws:mainfrom
cogwirrel:feat/docker-build-context

Conversation

@cogwirrel
Copy link
Copy Markdown
Member

@cogwirrel cogwirrel commented Feb 10, 2026

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.

The necessary changes to the CLI have been released: aws/aws-cdk-cli#1128

Describe any new or updated permissions being added

N/A

Description of how you validated changes

Integration test

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
Copy Markdown
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
Copy Markdown
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.
This security report is NOT a review blocker. 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
Copy Markdown
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.
This security report is NOT a review blocker. 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
@cogwirrel cogwirrel force-pushed the feat/docker-build-context branch from 1b3bd62 to a60f41a Compare February 18, 2026 00:58
@cogwirrel cogwirrel force-pushed the feat/docker-build-context branch from a60f41a to 24a6f37 Compare February 27, 2026 02:04
@cogwirrel
Copy link
Copy Markdown
Member Author

aws/aws-cdk-cli#1128 has been merged and released:

Updated this PR to depend on the latest versions.

@cogwirrel cogwirrel force-pushed the feat/docker-build-context branch 2 times, most recently from aad409c to 91f648b Compare February 27, 2026 05:11
@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

1 similar comment
@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

Copy link
Copy Markdown
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

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

@cogwirrel Happy with this once the build passes. Thanks for the contribution! Might be easier to split the package updates out into a separate PR. Feel free to ping me internally to move this forward.

mergify bot pushed a commit that referenced this pull request Mar 25, 2026
…de docker build context (#37350)

### Issue # (if applicable)

References #31598

### Reason for this change

Splitting dependency updates out of #36930

### Description of changes

Update the following dependencies:
- @aws-cdk/integ-runner: ^2.196.1 -> ^2.197.1
- @aws-cdk/cloud-assembly-api: ^2.1.1 -> ^2.2.0
- @aws-cdk/cloud-assembly-schema: ^52.1.0 -> ^53.0.0
- yarn.lock transitive dependency updates

Fix the integration tests due to the update. Details below from our friend Kiro:

> The PR that introduced the @aws-cdk/aws-eks:useNativeOidcProvider feature flag is #36589
> This PR added the EKS_USE_NATIVE_OIDC_PROVIDER flag with `recommendedValue: true`. Because it's a recommended flag, it was automatically included in the `@aws-cdk/integ-runner`'s auto-generated `recommended-feature-flags.json` when the integ-runner was built against a version of aws-cdk-lib containing this change. This is why `@aws-cdk/[email protected]` includes the flag but `@aws-cdk/[email protected]` does not — `v2.197.1` was the first integ-runner release built after PR #36589 was merged.

### Describe any new or updated permissions being added

None

### Description of how you validated changes

#36930

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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 ae42ed4 to 6afbb85 Compare March 25, 2026 08:36
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Mar 25, 2026
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Mar 25, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 25, 2026

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit c0849ea into aws:main Mar 25, 2026
41 of 42 checks passed
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 25, 2026

Merge Queue Status

  • Entered queue2026-03-25 09:27 UTC · Rule: default-squash
  • Checks skipped · PR is already up-to-date
  • Merged2026-03-25 09:27 UTC · at 6afbb85e30bbf18831cf4261bbd13a1c79f0df01

This pull request spent 6 seconds in the queue, with no time running CI.

Required conditions to merge

@github-actions
Copy link
Copy Markdown
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

3 participants