(ecr-deployment): new aws-ecr-deployment module
🚀🚀🚀 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
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.
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.
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?
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 yes, it was a comment on the issue before it was repurposed. Edited.
People on this thread, make sure to +1 so that we are able to prioritize this.
@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`),
});
@eladb @jabrennem I wrote a
cdk-ecr-deploymenthttps://github.com/wchaws/cdk-ecr-deployment. See if this can help you. With this you can replicate your ECR to another locationconst 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
@wchaws https://github.com/aws/aws-cdk/pull/14488 calls out your awesome library as a way to deploy to ECR.
@wchaws #14488 calls out your awesome library as a way to deploy to ECR.
Thank you @eladb
What happened to this project? https://github.com/wchaws/cdk-ecr-deployment. It doesn't exist now.
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.
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/
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
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
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)
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").
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 :)
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.
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.