Skip to content

Instantly share code, notes, and snippets.

@carlok
Last active May 25, 2020 12: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 carlok/18c6ca2a71c464d3af98b80e75ec581f to your computer and use it in GitHub Desktop.
Save carlok/18c6ca2a71c464d3af98b80e75ec581f 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: python:3.7.3
options:
docker: true
pipelines:
tags:
'v*': # the tag is "vSomething" like "v0.4.3"
- 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_BASE_URL=xxx.dkr.ecr.eu-central-1.amazonaws.com # or something like that
# IMAGE_REPOSITORY=repo_name
- pip install awscli
- aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $IMAGE_BASE_URL
- docker build -t $IMAGE_BASE_URL/$IMAGE_REPOSITORY:$BITBUCKET_TAG .
- docker push $IMAGE_BASE_URL/$IMAGE_REPOSITORY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment