0

I'm using GitHub, Jenkins, AWS ECR, AWS ECS.

I want to deploy automatically when GitHub has a new commit. When GitHub, have new commit, GitHub, sent webhook to Jenkins, Jenkins build images and push to ECR with tag 'latest'.

I wonder how can I make my ECS service restart task and redeploy images automatically when ECR image changed?

zero323
  • 322,348
  • 103
  • 959
  • 935

1 Answers1

2

Don't use latest in this setup. Have Jenkins pick a tag for the image (maybe based off a source control commit ID, a source control tag name, or a timestamp). Give it the ability to update the ECS tasks, and then (once a build has happened and gone through appropriate pre-launch testing) have Jenkins change the image tag in the task to what it's just built. ECS will see that the image has changed, pull the new image, and launch containers accordingly.

Two other good reasons to do things this way: if you have explicit versions, you can have a pre-production cluster, deploy things there, run tests, and then deploy the same version to production; and if a deploy goes bad, you can straightforwardly roll back by manually setting the tag back to yesterday's build, which is impossible if the only version you have is latest.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • How Jenkins change the image tag in the task? – Yeonsuk Choi Nov 28 '18 at 02:11
  • it's also possible to use the --force-new-deployment parameter, which will tell ECS to pull the latest container image from ECR, without the need to create new tasks. https://docs.aws.amazon.com/cli/latest/reference/ecs/update-service.html – Tamas Kalman Dec 08 '20 at 06:55