Skip to content

Instantly share code, notes, and snippets.

@secmohammed
Forked from carlok/bitbucket-pipelines.yml
Created August 2, 2023 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secmohammed/f33645ec1c228cf420d1b8a3d5a7e915 to your computer and use it in GitHub Desktop.
Save secmohammed/f33645ec1c228cf420d1b8a3d5a7e915 to your computer and use it in GitHub Desktop.
How to force BitBucket to push a Docker image to AWS ECR after a git tag
#image: atlassian/default-image:2
image: python:3.7.3
pipelines:
tags:
'v*': # the tag is "vSomthing" like "v-0.4.2"
- step:
name: Build docker image and push to AWS ECR
services:
- docker
caches:
- pip
script:
# BitBucket > Settings > Pipelines > Repository variables =>
# AWS_ACCESS_KEY_ID=xxx
# AWS_SECRET_ACCESS_KEY=xxx
# AWS_REGION=xxx
# IMAGE_REPOSITORY=xxx.dkr.ecr.eu-central-1.amazonaws.com/repo_name # or something like that
# IMAGE_NAME=xxx
- pip install awscli
- eval $(aws ecr get-login --region $AWS_REGION --no-include-email)
- docker build -t $IMAGE_NAME .
- export IMAGE_ID=`docker images -q $IMAGE_NAME`
- docker tag $IMAGE_ID $IMAGE_REPOSITORY:$BITBUCKET_TAG
- docker push $IMAGE_REPOSITORY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment