aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(ecr-deployment): new aws-ecr-deployment module

Open jabrennem opened this issue 5 years ago • 38 comments

🚀🚀🚀 The CDK team is picking up this feature request! Check below for more details!

We understand this is a highly desirable feature. Until we are able to integrate it into the CDK, we recommend considering the cdk-ecr-deployment library.

Let us know what you think! ❤️


Allow users to publish docker image assets to arbitrary ECR repositories. Similar to how s3-deployment works for S3:

const image = new DockerImageAsset(...);
const myRepo = new ecr.Repository(...);

new RepositoryDeployment(this, 'MyDeployment', {
  from: image,
  to: myRepo
});

I've been trying to identify if this is already supported. I am adding as a feature request. Let me know otherwise.

For this code snippet, is there a way to specify an image and tag that I want my local docker image to deploy to? I am posting the code in javascript since the example in the API reference is in JS, but my team uses python.

import { DockerImageAsset } from '@aws-cdk/aws-ecr-assets';

const asset = new DockerImageAsset(this, 'MyBuildImage', {
  directory: path.join(__dirname, 'my-image')
});

Use Case

I would like to use this feature to completely deploy my local image source code to ECR for me using an ECR repo that I have previously created in my CDK app or more importantly outside the app using an arn. The biggest problem is that the image cannot be completely abstracted into the assets repo because of auditing and semantic versioning.

Proposed Solution

Here is my proposed solution.

import { DockerImageAsset } from '@aws-cdk/aws-ecr-assets';

const asset = new DockerImageAsset(this, 'MyBuildImage', {
  directory: path.join(__dirname, 'my-image')
  repo_name: 'company/my-image',
  tag: '1.2.0'
});

Other

  • [ ] :wave: I may be able to implement this feature request
  • [ ] :warning: This feature might incur a breaking change

This is a :rocket: Feature Request

jabrennem avatar Jan 19 '21 16:01 jabrennem

Repurposed this issue as "ecr-deployment".

CDK assets (s3/ECR) are designed to be referenced from within CDK apps and not as a tool to publish docker images for external consumption. There are multiple places in the CDK and CDK pipelines which rely on the idea that all docker assets are published to the same repository.

I can see a use case for something like "s3-deployment" for docker images (which will replicate a docker image asset to a specific ECR repository), but this is currently not something we have. Happy to accept contributions.

eladb avatar Feb 15 '21 08:02 eladb

I see. Thanks for the response. It does seem better to refocus this issue towards an "ecr-deployment" module rather than change how assets are handled.

jabrennem avatar Feb 15 '21 15:02 jabrennem

I'm not sure that I agree with that. For example - I want a standardized image to support the lambda functions my company produces. It sounds to me like there would be a separate repository then for each lambda/image. How would we reference the image repository if CDK munges the name, because we can't set it?

MHacker9404 avatar Feb 16 '21 12:02 MHacker9404

This is something we will not likely support. CDK assets (s3/ECR) are designed to be referenced from within CDK apps and not as a tool to publish docker images for external consumption. There are multiple places in the CDK and CDK pipelines which rely on the idea that all docker assets are published to the same repository.

@elad Did we decide that we will try to support this approach after all, given your https://github.com/aws/aws-cdk/issues/2663#issuecomment-789537323 in #2663?

SoManyHs avatar Mar 15 '21 21:03 SoManyHs

@SoManyHs yes, it was a comment on the issue before it was repurposed. Edited.

eladb avatar Mar 16 '21 06:03 eladb

People on this thread, make sure to +1 so that we are able to prioritize this.

eladb avatar Mar 18 '21 06:03 eladb

@eladb @jabrennem I wrote a cdk-ecr-deployment https://github.com/wchaws/cdk-ecr-deployment. See if this can help you. With this you can replicate your ECR to another location

const image = new DockerImageAsset(this, 'CDKDockerImage', {
  directory: path.join(__dirname, 'docker'),
});

new ecrDeploy.ECRDeployment(this, 'DeployDockerImage', {
  src: new ecrDeploy.DockerImageName(image.imageUri),
  dest: new ecrDeploy.DockerImageName(`${cdk.Aws.ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/test:nginx`),
});

wchaws avatar Apr 20 '21 14:04 wchaws

@eladb @jabrennem I wrote a cdk-ecr-deployment https://github.com/wchaws/cdk-ecr-deployment. See if this can help you. With this you can replicate your ECR to another location

const image = new DockerImageAsset(this, 'CDKDockerImage', {
  directory: path.join(__dirname, 'docker'),
});

new ecrDeploy.ECRDeployment(this, 'DeployDockerImage', {
  src: new ecrDeploy.DockerImageName(image.imageUri),
  dest: new ecrDeploy.DockerImageName(`${cdk.Aws.ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/test:nginx`),
});

Hi, can you help approve this PR there? https://github.com/wchaws/cdk-ecr-deployment/pull/31

TRANTANKHOA avatar Apr 30 '21 08:04 TRANTANKHOA

@wchaws https://github.com/aws/aws-cdk/pull/14488 calls out your awesome library as a way to deploy to ECR.

eladb avatar May 02 '21 10:05 eladb

@wchaws #14488 calls out your awesome library as a way to deploy to ECR.

Thank you @eladb

wchaws avatar May 02 '21 14:05 wchaws

What happened to this project? https://github.com/wchaws/cdk-ecr-deployment. It doesn't exist now.

chrisbirster avatar May 18 '21 14:05 chrisbirster

What happened to this project? https://github.com/wchaws/cdk-ecr-deployment. It doesn't exist now.

This project is going to move into official cdklabs org. Some process is on going. Stay tuned.


2021/06/03 Updated

https://github.com/wchaws/cdk-ecr-deployment has been moved to cdklabs.

wchaws avatar May 19 '21 02:05 wchaws

This project is going to move into official cdklabs org. Some process is on going. Stay tuned.

Does that affect whether or not there would still be a possibility for having a more "official" solution?

I'd love a cdk ecr-deployment module that also supported "OCI Articacts" as described here

https://aws.amazon.com/blogs/containers/oci-artifact-support-in-amazon-ecr/

pseudo-su avatar Jul 03 '21 07:07 pseudo-su

This project is going to move into official cdklabs org. Some process is on going. Stay tuned.

Does that affect whether or not there would still be a possibility for having a more "official" solution?

I'd love a cdk ecr-deployment module that also supported "OCI Articacts" as described here

https://aws.amazon.com/blogs/containers/oci-artifact-support-in-amazon-ecr/

I believe cdk-ecr-deployment does support OCI image because it's based on https://github.com/containers/skopeo

wchaws avatar Jul 04 '21 13:07 wchaws

Admittedly I haven't had a chance to look into it exhaustively yet but there is an open feature request on the skopeo repo to support OCI Artifacts https://github.com/containers/skopeo/issues/931

pseudo-su avatar Jul 04 '21 14:07 pseudo-su

Admittedly I haven't had a chance to look into it exhaustively yet but there is an open feature request on the skopeo repo to support OCI Artifacts containers/skopeo#931

But from https://github.com/containers/skopeo project README. It says it supports OCI image. (I'm confused)

wchaws avatar Jul 04 '21 14:07 wchaws

My understanding is the OCI Image spec is distinct from the OCI Artifact spec

EG from here https://github.com/opencontainers/distribution-spec/blob/main/spec.md#introduction

While OCI Image is the most prominent, the specification is designed to be agnostic of content types. Concepts such as "manifests" and "digests", are currently defined in the Open Container Initiative Image Format Specification (a.k.a. "OCI Image Spec").

To support other artifact types, please see the Open Container Initiative Artifact Authors Guide (a.k.a. "OCI Artifacts").

pseudo-su avatar Jul 04 '21 14:07 pseudo-su

If the idea here is that everything is self-contained in CDK, what's the recommended way to move artifacts (S3/ECR Images) between accounts? Surely the recommendation is not to rebuild an artifact after we've already tested it in a lower environment :)

automartin5000 avatar Nov 03 '21 17:11 automartin5000

Use case: bootstrapping an ECR repo.

Say I want to have a stack which contains both an ECR repository and the ECS Cluster that uses it. Currently I'm stuck doing stupid tricks like having a bootstrap mode. If I can stuff a HelloWorld container in there, I have a viable starting point.

ahammond avatar Nov 28 '21 01:11 ahammond

The CDK should not even send assets to a central repo. So it might have to do a v2 of DockerImageAsset, as right now it sends it to aws-cdk/assets, which is just icky.

TrentonAdams avatar Dec 01 '21 23:12 TrentonAdams