Skip to content

Instantly share code, notes, and snippets.

@carlok
Created March 28, 2020 17:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save carlok/22f2d56715e1427926465b84431dad92 to your computer and use it in GitHub Desktop.
Save carlok/22f2d56715e1427926465b84431dad92 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