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

chore(ecr): expose registryUri #32176

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/aws-cdk-lib/aws-ecr/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export interface IRepository extends IResource {
*/
readonly repositoryUri: string;

/**
* The URI of this repository's registry:
*
* ACCOUNT.dkr.ecr.REGION.amazonaws.com
*
* @attribute
*/
readonly registryUri: string;

/**
* Returns the URI of the repository for a certain tag. Can be used in `docker push/pull`.
*
Expand Down Expand Up @@ -191,6 +200,17 @@ export abstract class RepositoryBase extends Resource implements IRepository {
return this.repositoryUriForTag();
}

/**
* The URI of this repository's registry:
*
* ACCOUNT.dkr.ecr.REGION.amazonaws.com
*
*/
public get registryUri(): string {
const parts = this.stack.splitArn(this.repositoryArn, ArnFormat.SLASH_RESOURCE_NAME);
return `${parts.account}.dkr.ecr.${parts.region}.${this.stack.urlSuffix}`;
}

/**
* Returns the URL of the repository. Can be used in `docker push/pull`.
*
Expand Down
24 changes: 24 additions & 0 deletions packages/aws-cdk-lib/aws-ecr/test/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,30 @@ describe('repository', () => {
});
});

test('calculate registry URI', () => {
// GIVEN
const stack = new cdk.Stack();
const repo = new ecr.Repository(stack, 'Repo');

new cdk.CfnOutput(stack, 'RegistryUri', {
value: repo.registryUri,
});

// THEN
const arnSplit = { 'Fn::Split': [':', { 'Fn::GetAtt': ['Repo02AC86CF', 'Arn'] }] };
Template.fromStack(stack).hasOutput('*', {
'Value': {
'Fn::Join': ['', [
{ 'Fn::Select': [4, arnSplit] },
'.dkr.ecr.',
{ 'Fn::Select': [3, arnSplit] },
'.',
{ Ref: 'AWS::URLSuffix' },
]],
},
});
});

test('import with concrete arn', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
Loading