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
Prev Previous commit
Next Next commit
apply comments
  • Loading branch information
moelasmar committed Nov 8, 2024
commit 9ac9788b1afb87c183219b09cf60ac9a8499a668
9 changes: 6 additions & 3 deletions packages/aws-cdk-lib/aws-ecr/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,23 @@ export abstract class RepositoryBase extends Resource implements IRepository {

let isInputDigestCondition;

// Use the existing condition of the same Token is existed, and if not create a new one
// Use the existing condition of the Token if it already exists, and if not create a new one
if (tagOrDigest in this.tokenConditions) {
isInputDigestCondition = this.tokenConditions[tagOrDigest];
} else {
this.conditionsNumber += 1;
isInputDigestCondition = new CfnCondition(this, `IsInputDigest${this.conditionsNumber}`, {
// we split the value of the Token using the delimiter : to check if the first element equals sha256
// to check if it is a digest, or it will be an image tag.
// in order to determine if it is a digest or an image tag.
expression: Fn.conditionEquals(Fn.select(0, Fn.split(':', tagOrDigest)), 'sha256'),
});
this.tokenConditions[tagOrDigest] = isInputDigestCondition;
}

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

const suffix = Fn.conditionIf(isInputDigestCondition.logicalId, imageDigestWithPrefix, imageTagWithPrefix).toString();
return this.repositoryUriWithSuffix(suffix);
} else {
if (tagOrDigest?.startsWith('sha256:')) {
Expand Down