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
preguntada hace 4 años2119 visualizaciones
1 Respuesta
0
Respuesta aceptada

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
respondido hace 4 años
profile picture
EXPERTO
revisado hace un mes

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas