Amazon Elastic Container Registry (ECR) is a fully managed Docker container registry that makes it easy to store, share, and deploy container images. We will learn how to build docker image for a springboot microservices app using Azure DevOps(ADO) build pipeline and push docker image into AWS ECR.
What are we going to do in this lab?
1. Create a Repository in AWS ECR for storing docker images
2. Create an IAM user and AmazonEC2ContainerRegistryFullAccess policy.
3. Create access keys for IAM user in AWS console
4. Create service connection in AzureDevOps to connect to AWS using IAM user
access & secret keys.
5. Create Azure DevOps Build pipeline with below tasks:
- maven build for building JAR
- build docker image
- push docker image into ECR
6. Verify if docker image has been pushed to AWS ECR
Pre-requisites:
- Azure DevOps Account setup and project is created in ADO
- Install AWS toolkit for Azure DevOps
- Setup springboot app in GitHub (you can fork this repository)
- Create service connection in ADO to connect to GitHub personal access Token
Watch Steps in YouTube channel:
Step 1 - Create a repo in ECR
Go to AWS console, type ECR
Click on Create Repository
Enter name for your repo - all lower case and Click create repository
Create an IAM user
Go to AWS console --> IAM --> Add Users
Enter name for the user
Search for EC2 and choose AmazonEC2ContainerRegistryFullAccess
Click on Create UserCreate security credentials
Click on user name ecr-user
Click on Security credentials
Create Service connection
Go to Project settings --> Service Connections
Enter Access keys and Secret keys
Click on save
Create a classic Azure Build pipeline
Click on use the classic editor
Choose a template for the pipeline, type docker and select docker container
Click on Apply
Choose Ubuntu latest as build agent
Add Maven task for building springboot JAR file
Make sure Maven task is moved up..it should be a first task
enter maven goas as install
Customize build an image Task
start customizing the task, choose the version as 2.0
Enter $(imageName) as Container repository
Select build as command from drop down
Tags as it have shown below
Remove push an image task
Add ECR push task
now configure the task
Select as shown in screenshot
Choose aws service connection from drop down
select region as per your settings.
select Image ID
enter as $(imageName):$(Build.BuildId)
$(Build.BuildId) as tar repo tag
Now make sure build is successful.
Save and Queue
Select ubuntu latest as build agent..do NOT select window
agents.Verify if Docker image has been pushed into AWS ECR
Now login to AWS console --> Go to ECR--> select your repo. verify if
image has been uploaded successfully.
No comments:
Post a Comment