Skip to content

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

Open
@BwL1289

Description

@BwL1289

Describe the feature

We use CDK Pipelines to deploy our infrastructure to dev, staging, and prod accounts.

When we are building dockerfiles using DockerImageAssets, 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ecr-assetsRelated to AWS CDK Docker Image Assetseffort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions