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
Hashicorp's Terraform is an open-source tool for provisioning and managing cloud infrastructure. Terraform can provision resources on any cloud platform.
Terraform allows you to create infrastructure in configuration files(tf files) that describe the topology of cloud resources. These resources include virtual machines, storage accounts, and networking interfaces. The Terraform CLI provides a simple mechanism to deploy and version the configuration files to Azure.
Watch the steps in YouTube:
Advantages of using Terraform:
Reduce manual human errors while deploying and managing infrastructure.
Deploys the same template multiple times to create identical development, test, and production environments.
Reduces the cost of development and test environments by creating them on-demand.
How to Authenticate with Azure?
Terraform can authenticate with Azure in many ways, in this example we will use Azure CLI to authenticate with Azure and then we will create resources using Terraform.
The above command will open the browser and will ask your Microsoft account details. Once you logged in, you can see the account info by executing below command:
az account list
Now create a directory to store Terraform files.
mkdir tf-acr
cd tf-acr
Let's create a terraform file to use azure provider. To configure Terraform to use the Default Subscription defined in the Azure CLI, use the below cod.
Now initialize the working directory
sudo vi create-acr.tf
provider "azurerm" { features {} } resource "azurerm_resource_group" "rg" { name = "rg-tf-acr" location = "southcentralus" } resource "azurerm_container_registry" "acr" { name = "azcontainerregistry321" resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location sku = "Basic" admin_enabled = true } output "admin_password" { value = azurerm_container_registry.acr.admin_password description = "The object ID of the user" sensitive = true }
Perform the below command to initialize the directory.
terraform init
Once directory is initialized, you can start writing code for setting up the infrastructure. Now Perform the below command to validate terraform files.
terraform validate
perform plan command to see how many resources will be created.
terraform plan
terraform apply
Do you want to perform these actions?
type yes
Now Login into Azure Cloud to see the resources created.
How to destroy the resources ?
Execute terraform destroy
The above command to destroy both resource group and container registry created before.
AKS allows you to quickly deploy a production ready Kubernetes cluster in Azure, deploy and manage containerized applications more easily with a fully
managed Kubernetes service.
AKS reduces the complexity and operational overhead of managing
Kubernetes by offloading much of that responsibility to Azure. As a
hosted Kubernetes service, Azure handles critical tasks like health
monitoring and maintenance for you. The Kubernetes masters are managed
by Azure. You only manage and maintain the agent nodes. As a managed
Kubernetes service, AKS is free - you only pay for the agent nodes
within your clusters, not for the masters.
We will see how to create AKS cluster in portal Azure.
Amazon Elastic Container Registry (ECR) is a fully managed container registry service provided by Amazon Web Services (AWS). It allows users to store, manage, and deploy Docker container images. Amazon ECR uses Amazon S3 for storage to make your container images highly available and accessible, allowing you to reliably deploy new containers for your applications. We will learn how to create ECR in AWS, will create a docker image and upload docker image into ECR.
You can watch the steps on YouTube as well:
What are we going to do in this lab?
1. Create a Repository in AWS ECR
2. Create an IAM role with ContainerRegistryFullAccess
Where your_acct_id is from AWS ECR in the above picture.
You must get a message says Login succeeded. Now let's build a docker image, I have already created a public repo in Bitbucket. All you need to do is perform the below command to clone my repo: