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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南