How does CodePipeline's ECR source action detect a change to an image in ECR?

Viewed 412

I am setting up a pipeline with an Amazon ECR source to ECS deploy. Have been following the steps in the tutorial here.

My issue is when my private ECR is updated with a docker image the pipeline is not triggered. I am not applying the latest tag on the image, just using a semantic versioning tag which includes a build number and a short Git commit hash, for eg:

  1. myserver:b21-6d22b379a
  2. myserver:b20-c90b134a
  3. etc..

In the Image Tag option in the ECR source action it says: Choose the image tag that triggers your pipeline when a change occurs in the image repository.

If I leave it blank and just specify the ECR repository name such as myserver, will it look for a new image only if the latest tag is moved to another image with a different SHS digest in ECR?

Or is it smart enough to detect the change in ECR based on the timestamp + SHA digest of a new image even if the image did not have the latest tag applied?

I want to avoid using the latest image tag, as with an ECS Fargate cluster my understanding is a new container will simply pull the latest tag irrespective of if CodeDeploy has published a new task def with a new image tag.

So how does one specify the Image & Tag in the ECR source action if not using the latest tag on the docker image in ECR? Does it require a fixed tag to be used for the auto deploy from ECR to ECS to work?

1 Answers

As per https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-ECR.html#action-reference-ECR-config :

If a value for ImageTag is not specified, the value defaults to latest

So if you leave "ImageTag" empty, only images with the "latest" tag will get deployed.

And yes it requires a fixed tag for deployment to work. As such the use of tags is limited - you can, for example, use tags to ensure a specific image only gets deployed in a specific environment (e.g. images tagged "staging" get deployed in staging environment, and images tagged "production" get deployed in production environment) - but you can't use tags dynamically.

Related