Pushing images to AWS ECR

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:

  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:




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}" ]
  # in case of tag, tag and push as latest.
  docker tag "${NAME}" "${AWS_REPO_URL}:latest"
  docker push "${AWS_REPO_URL}:latest"

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.

The docker arguments have different format from what https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html suggests.

You are also using the tag name my-app every time which may or may not be what you want.

By default, only master commits are deployed. To deploy on master OR tags, use

  condition: $TRAVIS_BRANCH == "master" || -n $TRAVIS_TAG