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

fix(ecr): allow creating repository uri to use tokens like cfn params #32053

Merged
merged 11 commits into from
Nov 8, 2024

Conversation

moelasmar
Copy link
Contributor

Issue # (if applicable)

Closes #31860.

Reason for this change

Currently customers can pass one property tagOrDigest and if the customers pass a CFN parameter, CDK could not know if it is a tag or digest, and so the generated URI is not correct.

Now the same parameter can supports Tokens, and it will generate a CFN condition to check if the value of this token is digest or tag, and then update the uri based on the condition output.

Description of changes

Check if the input is a Token, and so instead of determining if its value is a tag or digest in synth time, we create a CFN condition to do this check in CFN, and then determine how to build the repo uri.

Description of how you validated changes

Added unit test cases, and integration test cases with assertions.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p1 labels Nov 7, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team November 7, 2024 21:43
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 7, 2024
packages/aws-cdk-lib/aws-ecr/lib/repository.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-ecr/lib/repository.ts Outdated Show resolved Hide resolved
this.tokenConditions[tagOrDigest] = isInputDigestCondition;
}

const suffix = Fn.conditionIf(isInputDigestCondition.logicalId, `@${tagOrDigest}`, `:${tagOrDigest}`).toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this line doing? What's the purpose of @${tagOrDigest} and :${tagOrDigest} being passed in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the condition I added checks if the passed Token contains a Tag or Image Digest, if it is a tag the repo uri should be in this format <ecr repo base uri>@<image digest value>, if it is a tag, so the format will be <ecr repo base uri>:<tag value>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tagged you in 2 examples for each use case in the integ testing template

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can update the code as well to make it more clear

Comment on lines 367 to 412
"ImageUri": {
"Fn::Join": [
"",
[
{
"Fn::Select": [
4,
{
"Fn::Split": [
":",
{
"Fn::GetAtt": [
"MyRepoF4F48043",
"Arn"
]
}
]
}
]
},
".dkr.ecr.",
{
"Fn::Select": [
3,
{
"Fn::Split": [
":",
{
"Fn::GetAtt": [
"MyRepoF4F48043",
"Arn"
]
}
]
}
]
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "MyRepoF4F48043"
},
"@sha256:55d873154f78cd9a13487c9539ff380f396b887f4a815d84fd698ed872c74749"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paulhcsun .. this is an example for the image uri in the Image Digest use case

Comment on lines +597 to +643
"ImageUri": {
"Fn::Join": [
"",
[
{
"Fn::Select": [
4,
{
"Fn::Split": [
":",
{
"Fn::GetAtt": [
"MyRepoF4F48043",
"Arn"
]
}
]
}
]
},
".dkr.ecr.",
{
"Fn::Select": [
3,
{
"Fn::Split": [
":",
{
"Fn::GetAtt": [
"MyRepoF4F48043",
"Arn"
]
}
]
}
]
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "MyRepoF4F48043"
},
":testTag"
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paulhcsun .. and this is an example for the image uri in the tag use case

@paulhcsun paulhcsun changed the title fix(ecr): allow creating repository uri suing tokens like cfn params fix(ecr): allow creating repository uri to use tokens like cfn params Nov 7, 2024
@moelasmar moelasmar requested a review from paulhcsun November 8, 2024 09:54
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 8, 2024
@paulhcsun
Copy link
Contributor

@Mergifyio update

Copy link
Contributor

mergify bot commented Nov 8, 2024

update

☑️ Nothing to do

  • #commits-behind > 0 [📌 update requirement]
  • -closed [📌 update requirement]
  • -conflict [📌 update requirement]
  • queue-position = -1 [📌 update requirement]

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 5ec99f4
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

mergify bot commented Nov 8, 2024

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 5648199 into aws:main Nov 8, 2024
13 checks passed
Copy link

github-actions bot commented Nov 8, 2024

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 Nov 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort p1 pr/needs-maintainer-review This PR needs a review from a Core Team Member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lambda.DockerImageCode.fromEcr: imageTagOrDigest field cannot recognize digests supplied as CfnParameter
3 participants