Deploy updated container to existing CDK stack

1

I have a Fargate service deployed with ecs_patterns.ApplicationLoadBalancedFargateService and I'd like it to roll out a new container that has been pushed to the ECR repo used for this service.

I have a pipeline producing the new container for the service but if I run cdk synth and then deploy after, CDK does not detect a change when it generates the CloudFormation changeset as the container tag does not change (latest). I updated it so the build pushes a unique container tag to SecretsManager and resolves this during deploy but this also doesn't work as the reference to the tag isn't picked up during changeset creation (would only pull the tag when deploying).

What's the best way to get CDK to deploy a new version of the container? Pass tag in dynamically or should I just go with CodeDeploy?

AWS
Tom_E
已提问 4 年前2119 查看次数
1 回答
0
已接受的回答

I would find a way to reference the same image tag in your cdk app that you use in your image build/tag/push stage.

For example, if you had a docker stage that pushed an image using the environment variable CODEBUILD_RESOLVED_SOURCE_VERSION as the tag like:

docker build -t $IMAGE_REPO_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION .
docker push $IMAGE_REPO_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION

You could then reference that tag in your CDK app:

const tag = process.env.CODEBUILD_RESOLVED_SOURCE_VERSION;
const image = ecs.ContainerImage.fromEcrRepository(ecrRepo, tag);

new ApplicationLoadBalancedFargateService(this, 'Service', {
  taskImageOptions: {
    image: image,
    ...
  },
  ...
});
AWS
已回答 4 年前
profile picture
专家
已审核 1 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则