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

(ecr-assets): image with variable buildArgs being rebuilt every time #15936

Closed
1 of 2 tasks
amirfireeye opened this issue Aug 7, 2021 · 3 comments · Fixed by #16070
Closed
1 of 2 tasks

(ecr-assets): image with variable buildArgs being rebuilt every time #15936

amirfireeye opened this issue Aug 7, 2021 · 3 comments · Fixed by #16070
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p2

Comments

@amirfireeye
Copy link
Contributor

amirfireeye commented Aug 7, 2021

#5705 made DockerImageAsset generate the asset hash based on, among other things, the buildArgs argument. This means that if build arg is used for anything dynamic the image will be rebuilt for every synth.

Can we have another argument allowing to control the hashing of buildArgs? Maybe hashBuildArgs that defaults to true?

Use Case

  • We pass a CodeArtifact token as a build argument so we can download private packages while building the image.
  • The official Docker documentation gives HTTP proxy as an example of a build argument. They say:
  • Users want to specify variables differently depending on which host they build an image on.

When CDK keeps hashing these build-machine specific arguments, it keeps generating new assets even though the intention is to have the same hash across build machines.

Proposed Solution

hashBuildArgs argument that defaults to true to maintain the current behavior. It can then be used here.

if (props.hashBuildArgs && props.buildArgs) { extraHash.buildArgs = props.buildArgs; }

Other

The PR that made this caused this issue is #5705

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@amirfireeye amirfireeye added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Aug 7, 2021
@github-actions github-actions bot added @aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets labels Aug 7, 2021
@richgiuli
Copy link

sourceHash is readonly. Would making it modifiable fix the issue, then it can be modified post construction?

amirfireeye added a commit to amirfireeye/aws-cdk that referenced this issue Aug 16, 2021
Docker build args are meant for build system specific configuration like http proxy or CodeArtifact tokens. Give the user an option to not hash build args so the DockerImageAsset hash can remain consistent. An inconsistent hash means the asset is built every synth and that wastes time and space.

closes aws#15936
@eladb
Copy link
Contributor

eladb commented Aug 17, 2021

A hashBuildArgs flag sounds like a reasonable thing to support. Contributions are welcome.

@eladb eladb added effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2 and removed needs-triage This issue or PR still needs to be triaged. labels Aug 17, 2021
@eladb eladb removed their assignment Aug 17, 2021
@mergify mergify bot closed this as completed in #16070 Oct 7, 2021
mergify bot pushed a commit that referenced this issue Oct 7, 2021
Docker build args are meant for build system specific configuration like http proxy or CodeArtifact tokens. Give the user an option to not hash build args so the DockerImageAsset hash can remain consistent even when using build args. An inconsistent hash means the asset is built every synth and that wastes time and space.

This change is backwards compatible as the default hashing behavior remains the same.

closes #15936


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Oct 7, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

njlynch pushed a commit that referenced this issue Oct 11, 2021
Docker build args are meant for build system specific configuration like http proxy or CodeArtifact tokens. Give the user an option to not hash build args so the DockerImageAsset hash can remain consistent even when using build args. An inconsistent hash means the asset is built every synth and that wastes time and space.

This change is backwards compatible as the default hashing behavior remains the same.

closes #15936


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
Docker build args are meant for build system specific configuration like http proxy or CodeArtifact tokens. Give the user an option to not hash build args so the DockerImageAsset hash can remain consistent even when using build args. An inconsistent hash means the asset is built every synth and that wastes time and space.

This change is backwards compatible as the default hashing behavior remains the same.

closes aws#15936


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants