A developer wants to use CodeBuild to build a docker image and push the image to ECR.
Then CodePipeline uses CodeDeploy to deploy the latest docker image on EC2 clusters via ECS.
Click on the arrows to vote for the correct answer
A. B. C. D.Correct Answer B.
The below is an example of what the buildspec.yml should look like for this case:
Pre-build stage:
Log in to Amazon ECR.
Set the repository URI to your ECR image and add an image tag with the first seven characters of the Git commit ID of the source.
Build stage:
Build the Docker image and tag the image both as latest and with the Git commit ID.Post-build stage:
Push the image to your ECR repository with both tags.
Write a file called imagedefinitions.json in the build root that has your Amazon ECS service's container name and the image and tag.
The deployment stage of your CD pipeline uses this information to create a new revision of your service's task definition, and then it updates the service to use the new task definition.
The imagedefinitions.json file is required for the AWS CodeDeploy ECS job worker.
The details can be found in https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-cd-pipeline.html.
Option? ?A & C are ?incorrect because under Pre-build stage, you need to Log in to Amazon ECR and Set the repository URI.
Option? D? ?is? ?incorrect.
Although the descriptions of Pre-build are correct, for Post-build stage, the CLI command should be “docker push $REPOSITORY_URI:latest”
Refer to https://docs.aws.amazon.com/cli/latest/reference/ecr/index.html for the supported ECR cli commands.
After “aws ecr get-login” in the Pre-build stage, the following steps need the docker commands.
The correct answer is D.
The developer wants to use AWS CodeBuild to build a Docker image and push the image to Amazon Elastic Container Registry (ECR). Then, AWS CodePipeline uses AWS CodeDeploy to deploy the latest Docker image to EC2 clusters via Amazon Elastic Container Service (ECS).
Here's the step-by-step process for this scenario:
In this step, the AWS CLI command "aws ecr get-login" is used to retrieve an authentication token from Amazon ECR that is used to authenticate Docker to your registry. The token is then used to log in to the ECR registry. The repository URI is then set, which is the location of the ECR repository.
The developer needs to write the buildspec.yml file, which contains a series of build commands that CodeBuild uses to run a build. In this case, the build commands are used to build the Docker image.
After the Docker image is built, the developer uses the AWS CLI command "aws ecr push" to push the Docker image to the ECR repository. The $REPOSITORY_URI:latest is the location where the image will be pushed. "latest" is the tag for the Docker image. If the developer wants to use a specific tag, they can set an image tag in the Pre-build stage.
In this stage, AWS CodePipeline uses AWS CodeDeploy to deploy the latest Docker image to EC2 clusters via ECS. CodeDeploy is a deployment service that automates application deployments to Amazon EC2 instances, on-premises instances, serverless Lambda functions, or Amazon ECS services. In this scenario, CodeDeploy deploys the Docker image to ECS.
Therefore, the correct answer is D: Login into ECR using “aws ecr get-login” and set the repository URI in the Pre-build stage. Push the image to your ECR repository such as “aws ecr push $REPOSITORY_URI:latest” in the Post-build stage.