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

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

Closed
1 of 2 tasks
moltar opened this issue Oct 3, 2024 · 5 comments · Fixed by #32176
Closed
1 of 2 tasks

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

moltar opened this issue Oct 3, 2024 · 5 comments · Fixed by #32176
Labels
@aws-cdk/aws-ecr Related to Amazon Elastic Container Registry effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@moltar
Copy link
Contributor

moltar commented Oct 3, 2024

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

@moltar moltar added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 3, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ecr Related to Amazon Elastic Container Registry label Oct 3, 2024
@ashishdhingra ashishdhingra self-assigned this Oct 3, 2024
@ashishdhingra ashishdhingra added p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Oct 3, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Oct 3, 2024

If we examine Push commands for an ECR repository, the 1st step is to Retrieve an authentication token and authenticate your Docker client to your registry. Use the AWS CLI:

aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin <<ACCOUNT>>.dkr.ecr.<<REGION>>.amazonaws.com`

So it is useful to expose a property, let's say registryUri, in IRepository interface (similar to repositoryUri):

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

Then introduce property below in RepositoryBase class:

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

@ashishdhingra ashishdhingra removed the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Oct 3, 2024
@ashishdhingra ashishdhingra removed their assignment Oct 3, 2024
@moltar
Copy link
Contributor Author

moltar commented Oct 3, 2024

@ashishdhingra Good point. Luckily, that command seems to work with the full repositoryUri value, too!

@moltar
Copy link
Contributor Author

moltar commented Oct 3, 2024

Altho I'd be careful with the registryUri nomenclature, as URI implies that there must be a scheme. What we have is truly just a domain or a hostname. But if we forget the implementation detail, it might just be a name. 🤷🏼

https://en.wikipedia.org/wiki/Uniform_Resource_Identifier

Copy link

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.

1 similar comment
Copy link

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 Dec 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-ecr Related to Amazon Elastic Container Registry effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants