I’m trying to push docker images to AWS ECR but I seem to be running into a bit of a problem. My objective it to push on master
and any tag to ECR. However, I seem to be ending up with <untagged>
images in ECR.
In my .travis.yml
I have:
deploy:
provider: script
script: bash ./scripts/aws_ecr_push.sh
My understand is that deploy
is triggered on master
builds and any tag, however, my understanding might be wrong.
My deployment script looks like this:
#!/bin/bash
NAME=my-app
AWS_REPO_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${NAME}"
eval $(aws ecr get-login --no-include-email --region $AWS_REGION)
# this tags and pushes the branch/tag.
docker tag "${NAME}" "${AWS_REPO_URL}:${TRAVIS_BRANCH}"
docker push "${AWS_REPO_URL}:${TRAVIS_BRANCH}"
if [ ! -z "${TRAVIS_TAG}" ]
then
# in case of tag, tag and push as latest.
docker tag "${NAME}" "${AWS_REPO_URL}:latest"
docker push "${AWS_REPO_URL}:latest"
fi
The images are build during the script
stage and they are there. From the docs I understand that TRAVIS_BRANCH
is always set (could be the tag name in case of a tag) and that TRAVIS_TAG
is set (not empty) when a tag is build.