Description
Describe the feature
We use CDK Pipelines to deploy our infrastructure to dev, staging, and prod accounts.
When we are building dockerfiles using DockerImageAsset
s, if there are any files/directories the dockerfile needs while being built, we currently have to copy them over any files/directories to the directory where the dockerfile is being built. This is cumbersome and error prone.
Docker now supports (since 2022) the ability to specify multiple build contexts via the --build-context
flag.
It would be great to add --build-context
to the flags supported here.
Here's an example:
from aws_cdk import aws_ecr_assets as ecr_assets
ecr_docker_image_asset = ecr_assets.DockerImageAsset(
self,
"EcrDockerImageAsset",
directory=<dir>,
file="Dockerfile",
build_args=<build_args>,
build_contexts=["example_build_context_1", "example_build_context_2", ...]
)
Then, we can use the following in the dockerfile like so:
COPY --from=example_build_context_1 ...
Use Case
With --build-context
now supported, It's unnecessary to copy any additional files/directories into the build context where you are building your image.
Proposed Solution
Support the --build-context
flag.
Other Information
No response
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
CDK version used
2.158.0
Environment details (OS name and version, etc.)
macOS Sonoma 14.5, AWS CodeBuild