Search code examples
amazon-web-servicesamazon-ecs

AWS ECS Continuous Deployment issue with CodePipeline


While deploying ECS using codepipeline like specified in aws official document, two docker image is pushing into ECR. One image contain both Commit id and latest tag and other image is untagged like specified below image.

enter image description here

In "buildspec.yml" file i can see, docker is pushing two image one with "latest tag and other one with commit id tag like given below

 - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
 - IMAGE_TAG=${COMMIT_HASH:=latest}
 - docker push $REPOSITORY_URI:latest
 - docker push $REPOSITORY_URI:$IMAGE_TAG

My question is

1) In ECR there must be two image one with "commit id" tag and other one with "latest" tag after the docker push complete. But in ECR, it is showing with wrong tag name, please check the above attached image.Why one image is showing with untagged ?

2) Why i need to push two image with commit id and latest tag, when my task definition is using only latest tag to build the container. Didn't i have to push only docker image with "latest" tag , why i need to push image with commit id tag ?


Solution

  • Answering my own Post, hope someine find this information useful :

    1) In ECR there must be two image one with "commit id" tag and other one with "latest" tag after the docker push complete as per the aws document. But in ECR, it is showing with wrong tag name, please check the attached image. Why one image is showing with untagged ?

    The reason why there is a untagged image is because when an existing image with a tag latest already exists its tag will be removed when a new image called latest is pushed to ECR, only one image will result from the 2 docker push commands, this is because they are tagged together. This helps when reviewing which latest image is in use by looking at the commit hash.

    2) Why i need to push two image with commit id and latest tag, when my task definition is using only latest tag to build the container. Didn't i have to push only docker image with "latest" tag , why i need to push image with commit id tag ?

    Pushing the second image adds the commit hash as a tag. Overtime as more images are added to the ECR repository it helps to have the commit hash as a tag to differentiate between previous latest images especially if a particular image is needed for a rollback.