简体   繁体   English

aws cdk 将图像推送到 ecr

[英]aws cdk push image to ecr

I am trying to do something that seems fairly logical and straight forward.我正在尝试做一些看起来相当合乎逻辑和直截了当的事情。

I am using the AWS CDK to provision an ecr repo:我正在使用 AWS CDK 来预置一个 ecr 存储库:

     repository = ecr.Repository(
                            self, 
                            id="Repo", 
                            repository_name=ecr_repo_name,
                            removal_policy=core.RemovalPolicy.DESTROY
                            )

I then have a Dockerfile which lives at the root of my project that I am trying to push to the same ECR repo in the deployment.然后我有一个 Dockerfile,它位于我的项目的根目录中,我试图在部署中推送到同一个 ECR 存储库。

I do this in the same service code with:我在相同的服务代码中执行此操作:

    assets = DockerImageAsset(
            self, 
            "S3_text_image", 
            directory=str(Path(__file__).parent.parent),
            repository_name=ecr_repo_name
            )

The deployment is fine and goes ahead and the ECR Repo is created, but the image is pushed to a default location aws-cdk/assets部署正常并继续进行并创建 ECR 存储库,但映像被推送到默认位置aws-cdk/assets

How do I make the deployment send my Dockerfile to the exact ECR repo I want it to live in?如何使部署将我的 Dockerfile 发送到我希望它所在的确切 ECR 存储库?

AWS CDK depricated the repositoryName property on DockerImageAsset . AWS CDK 弃用了DockerImageAsset上的repositoryName属性。 There are a few issues on GitHub referencing the problem. GitHub 上存在一些引用该问题的问题。 See this comment from one of the developers:请参阅其中一位开发人员的评论

At the moment the CDK comes with 2 asset systems:目前 CDK 带有 2 个资产系统:

The legacy one (currently still the default), where you get to specify a repositoryName per asset, and the CLI will create and push to whatever ECR repository you name.旧版(目前仍然是默认设置),您可以在其中为每个资产指定一个 repositoryName,CLI 将创建并推送到您命名的任何 ECR 存储库。

The new one (will become the default in the future), where a single ECR repository will be created by doing cdk bootstrap and all images will be pushed into it.新的(将来将成为默认),其中将通过执行 cdk 引导创建单个 ECR 存储库,并将所有图像推送到其中。 The CLI will not create the repository any more, it must already exist. CLI 将不再创建存储库,它必须已经存在。 IIRC this was done to limit the permissions required for deployments. IIRC 这样做是为了限制部署所需的权限。 @eladb, can you help me remember why we chose to do it this way? @eladb,你能帮我记住为什么我们选择这样做吗?

There is a request for a new construct that will allow you to deploy to a custom ECR repository at (aws-ecr-assets) ecr-deployment #12597 .有一个新构造请求,允许您部署到(aws-ecr-assets) ecr-deployment #12597的自定义 ECR 存储库。

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.我想使用此功能将我的本地图像源代码完全部署到 ECR,使用我之前在我的 CDK 应用程序中创建的 ECR 存储库或更重要的是在应用程序外部使用 arn 创建。 The biggest problem is that the image cannot be completely abstracted into the assets repo because of auditing and semantic versioning.最大的问题是由于审计和语义版本控制,图像无法完全抽象到资产仓库中。

There is also a third party solution at https://github.com/wchaws/cdk-ecr-deployment if you do not want to wait for the CDK team to implement the new construct.如果您不想等待 CDK 团队实施新结构,在https://github.com/wchaws/cdk-ecr-deployment也有第三方解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM