In a pipeline yml i need total of two step In first step i want to build a docker images and push to a ecr repo in aws account 1. In second step i need the same image build on the first step to be pushed to another ecr repo in aws account 2
Thank you for your question!
It's a good DevOps practice to follow "build once and deploy many".
So, the solution could be:
step:
script:
# build the image
- docker build -t $IMAGE_NAME:$IMAGE_VERSION -t $IMAGE_NAME:latest .
- docker save --output my-docker-image.tar.gz $IMAGE_NAME
services:
- docker
artifacts:
- my-docker-image.tar.gz
step:
script:
# load previously saved image that will available as an artifact
docker load --input docker-image.tar.gz
# use the pipe to push the image to AWS ECR
- pipe: atlassian/aws-ecr-push-image:2.0.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_1
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_1
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_1
IMAGE_NAME: $IMAGE_NAME
services:
- docker
step:
script:
# load previously saved image that will available as an artifact
docker load --input docker-image.tar.gz
# use the pipe to push the image to AWS ECR
- pipe: atlassian/aws-ecr-push-image:2.0.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_2
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY_2
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION_2
IMAGE_NAME: $IMAGE_NAME
services:
- docker
Best regards,
Oleksandr Kyrdan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Because you want to store the build artifact (a Docker image) externally, there is no real difficulty here.
Notes:
Alternatively, you could try the Docker image as a temporary Bitbucket download. (We use this technique.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
image: atlassian/default-image:2
definitions:
docker:
memory: 7128
caches:
docker: /root/.docker
steps:
- step: &build-and-push-STG
size: 2x
name: "Build and push to STG"
script:
- VERSION="${BITBUCKET_BUILD_NUMBER}"
- docker build -t name .
- pipe: atlassian/aws-ecr-push-image:1.6.2
variables:
AWS_DEFAULT_REGION: 'Region'
AWS_ACCESS_KEY_ID: '${EKS_NP_ACCESS_KEY_ID}'
AWS_SECRET_ACCESS_KEY: '${EKS_NP_SECRET_ACCESS_KEY}'
IMAGE_NAME: "Name"
TAGS: '${VERSION} latest'
ECR_REPOSITORY_URL: 'xxxxx.dkr.ecr.ca-central-1.amazonaws.com/repo'
services:
- docker
- step: &push-to-PRD
name: "Push to ECR 2"
script:
- echo "Pushing to ECR 2"
- pipe: atlassian/aws-ecr-push-image:1.6.2
variables:
AWS_DEFAULT_REGION: 'Region'
AWS_ACCESS_KEY_ID: '${AWS_ACCESS_KEY_ID}'
AWS_SECRET_ACCESS_KEY: '${AWS_SECRET_ACCESS_KEY}'
IMAGE_NAME: "Name"
TAGS: '${BITBUCKET_BUILD_NUMBER} latest'
ECR_REPOSITORY_URL: 'xxxxxx.dkr.ecr.ca-central-1.amazonaws.com/repo'
services:
- docker
pipelines:
custom:
Deploy-Pipeline:
- step: *build-and-push-STG
caches:
- docker
- step: *push-to-PRD
trigger: manual
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First steps works fine for me , but the second step give error
unable to find the image Name.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.