Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
BwL1289 opened this issue Sep 30, 2024 · 4 comments
Open
2 tasks
Labels
@aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p3

Comments

@BwL1289
Copy link

BwL1289 commented Sep 30, 2024

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

@BwL1289 BwL1289 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 30, 2024
@BwL1289 BwL1289 changed the title (@aws-cdk/aws-ecr-assets): DockerImageAsset - support --build-context (@aws-cdk/aws-ecr-assets): DockerImageAsset - support --build-context flag Sep 30, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets label Sep 30, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Sep 30, 2024
@khushail khushail self-assigned this Sep 30, 2024
@khushail
Copy link
Contributor

khushail commented Sep 30, 2024

Hi @BwL1289 , thanks for reaching out.

I see this request raised in the past - #3342 but few workaround were suggested - #3342 (comment) as in favor of not implementing this flag. For now, you could use this directory construct prop to mention the path.

However given the context of usage and support, this would be good to have. So I am marking this as P3 which means it won't be immediately addressed by the team but is open for team as well as community contribution.

@khushail khushail added p3 effort/medium Medium work item – several days of effort and removed p3 investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Sep 30, 2024
@khushail khushail removed their assignment Sep 30, 2024
@khushail khushail added p3 and removed p2 labels Sep 30, 2024
@BwL1289
Copy link
Author

BwL1289 commented Sep 30, 2024

@khushail this is different than #3342, and there's no obvious workaround I can think of.

Docker now supports multiple build contexts through the use of the --build-context flag, which is different than specifying a context like what was discussed in #3342.

Per the article I referenced, here's an example:

Additional build contexts can be defined with a new --build-context [name]=[value] flag. The key component defines the name for your build context and the value can be:

Local directory – e.g. --build-context project2=../path/to/project2/src
Git repository – e.g. --build-context qemu-src=https://github.com/qemu/qemu.git
HTTP URL to a tarball – e.g. --build-context src=https://example.org/releases/src.tar
Docker image – Define with a docker-image:// prefix, e.g. --build-context alpine=docker-image://alpine:3.15

Please let me know if this makes sense.

@BwL1289
Copy link
Author

BwL1289 commented Sep 30, 2024

@khushail this doesn't seem that difficult, though buildx is required. Need to add an option for buildContexts (like buildArgs) and link everything up.

I would create a PR but my TS skills are shaky at best. Let me know how I can help.

@khushail
Copy link
Contributor

@BwL1289 , thanks for clarification and volunteering to contribute.

There are many ways for seeking support and help on this request--

  1. I have marked this as P3 which means its a good to have feature. We use +1s to help prioritize our work, and are happy to re-evaluate this issue based on community feedback. So upvotes are requested to prioritise the implementation of this FR. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization.
  2. Follow the contribution guide to started and reach out to slack community on this as well.
  3. Available CDK Youtube tutorial for PR contribution- https://www.youtube.com/watch?v=ZRxDwAvyQGc

hope that would be helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p3
Projects
None yet
Development

No branches or pull requests

2 participants