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
Hi @Bibin V Joseph
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.gzstep: 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: - dockerstep: 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
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.)
image: atlassian/default-image:2
definitions:docker:memory: 7128caches:docker: /root/.dockersteps:- step: &build-and-push-STGsize: 2xname: "Build and push to STG"script:- VERSION="${BITBUCKET_BUILD_NUMBER}"- docker build -t name .- pipe: atlassian/aws-ecr-push-image:1.6.2variables: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-PRDname: "Push to ECR 2"script:- echo "Pushing to ECR 2"- pipe: atlassian/aws-ecr-push-image:1.6.2variables: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:- dockerpipelines:custom:Deploy-Pipeline:- step: *build-and-push-STGcaches:- docker- step: *push-to-PRDtrigger: manual
First steps works fine for me , but the second step give errorunable to find the image Name.
Thank You
It looks like you're new here. Sign in or register to get started.