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
전문가
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠