Skip to content

(aws-ecr): Expose repository domain or hostname #31631

@moltar

Description

@moltar

Describe the feature

Expose the repository domain/hostname as a prop.

Use Case

The Docker credentials helper (e.g. docker-credential-ecr-login) expects a hostname in the configuration.

{
	"credHelpers": {
		"public.ecr.aws": "ecr-login",
		"<aws_account_id>.dkr.ecr.<region>.amazonaws.com": "ecr-login"
	}
}

Docs: https://github.com/awslabs/amazon-ecr-credential-helper?tab=readme-ov-file#docker

Proposed Solution

Extract the hostname part from this method:

/**
* Returns the repository URI, with an appended suffix, if provided.
* @param suffix An image tag or an image digest.
* @private
*/
private repositoryUriWithSuffix(suffix?: string): string {
const parts = this.stack.splitArn(this.repositoryArn, ArnFormat.SLASH_RESOURCE_NAME);
return `${parts.account}.dkr.ecr.${parts.region}.${this.stack.urlSuffix}/${this.repositoryName}${suffix}`;
}

And make it public:

  /**
   * Returns the domain of the repository. Can be used in Docker credentials helper.
   *
   *    ACCOUNT.dkr.ecr.REGION.amazonaws.com
   *
   * @param tagOrDigest Optional image tag or digest (digests must start with `sha256:`)
   */
  public get repositoryDomain(): string {
    return "";
  }

Other Information

This helper already ships with some CodeBuild images:

aws/aws-codebuild-docker-images#743

Acknowledgements

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

CDK version used

2.x

Environment details (OS name and version, etc.)

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ecrRelated to Amazon Elastic Container Registryeffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions