The task is to create an
See the next part – Jenkins: Docker Compose deployment from Ansible with ECR authentication.
Contents
AWS ECR
Go to the ECR, click Get Started, set a new repository name:
Lave Mutable, so you’ll be able to push images with the same tag if it is already present in the repository:
Done:
IAM
Go to the IAM, create an additional user:
Attach the AmazonEC2ContainerRegistryFullAccess
policy:
Save users access keys:
Configure AWS CLI profile:
Get access token:
Log in:
Find any existing Docker image on your workstation:
Tag it with the new repository URL and name:
Push this image:
Oak y – everything works here.
Jenkins
The next step will be to create a Jenkins job to build and push images.
Amazon ECR authentication
For ECR authentication – need to execute an AWS CLI aws ecr get-login
command to get a token to used during docker login
.
To avoid calling aws ecr get-login
each time – the Amazon ECR plugin can be used here.
Install it:
Add new credentials – go to the Credentials – Add credentials, chose type AWS Credentials:
Create a new Pipeline-job:
And script:
node { def app stage('Clone repository') { git branch: "master", url: "git@github.com:example-dev/go-queue-consumer.git", credentialsId: "jenkins-example-github" } stage('Build image') { sh "docker build --build-arg APP_NAME=receipts -t 534***385.dkr.ecr.us-east-2.amazonaws.com/bttrm-receipt-consumer:latest -f docker/prod/Dockerfile ." } stage('Push image') { docker.withRegistry('https://534***385.dkr.ecr.us-east-2.amazonaws.com', 'ecr:us-east-2:bttrm-backend-ecr') { sh "docker push 534***385.dkr.ecr.us-east-2.amazonaws.com/bttrm-receipt-consumer:latest" } } }
In the ‘ecr:us-east-2:bttrm-backend-ecr‘ we specify that we are looking for ECR access in the US-EAST-2 region for the bttrm-backend-ecr Jenkins CredentialsID.
Run the build:
Done.