Created
March 28, 2020 17:14
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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