How to build with AWS CodeBuild and save docker image in AWS Elastic Container Registry — Step 7
This story is part of a series “Initial Commit till Running on Cloud”.
Any code needs to be compiled, packaged and installed in a registry for deployment. We will build all our Java projects using maven commands and then package the Jar inside a Docker container. This Docker container image will be pushed to a registry provided by AWS called Elastic Container Registry. All of these will be done by a service called CodeBuild in AWS. We can also create automated build pipelines and do Continuous delivery.
As we will be producing Docker images of our application we need a registry where we can register our images so that Elastic Container Service can pull and deploy them as Tasks inside Services. Let’s create 1 repository for each of our github repository. Navigate or search ECR and land on Repositories where we have a button to Create repository. Leave everything as it is in the form that appears and type name of the Github repository. Click Create Repository to create the repository in ECR.
Copy the repository URL which resembles 683391730855.dkr.ecr.eu-central-1.amazonaws.com/awesome-app-bff
Now we are ready to create a Build project. Navigate to CodeBuild service and click Create build project
Before we proceed to the next step open a new window with AWS console and navigate to IAM Roles.
Now that we created the CodeBuild role with ECR access lets use it as a service role of CodeBuild. Copy the ARN of this role from IAM page and paste it in Role ARN of CodeBuild. We will reuse this for all our projects.
Add build commands by replacing proper ECR repository URL.
build:
commands:
— $(aws ecr get-login — no-include-email — region eu-central-1)
— mvn package -Dmaven.test.skip=true -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
— docker build -t 683391730855.dkr.ecr.eu-central-1.amazonaws.com/awesome-app-bff:master .
— docker push 683391730855.dkr.ecr.eu-central-1.amazonaws.com/awesome-app-bff:master
Click Create build project to finish.
From the Build projects screen we can select any project and click Start build to start build process. Once the build is completed you will see the below success screen with status Succeeded
In ECR you can also view the successfully pushed image
Awesome :) All Izz Well.
Do this for all our projects by changing the build commands with proper ECR repository url.
Sorry for a tutorial full of screenshots. Only way to do this better is through a youtube video. Which I am planning to do in the near future.
Going good? Please read the next part of this series. Also kindly leave your feedback :)