2020-02-05 20:53:52 +00:00
|
|
|
#!/bin/bash
|
2020-04-03 13:53:47 +00:00
|
|
|
|
2020-06-16 15:09:48 +00:00
|
|
|
#########################################################################
|
|
|
|
# Builds the Docker image for the current git branch on Travis CI and
|
|
|
|
# publishes it to Docker Hub.
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# $1: Docker Hub repository to publish to
|
|
|
|
#
|
|
|
|
# Required environment variables (place in Settings menu on Travis CI):
|
|
|
|
# $DOCKER_USERNAME: Docker Hub username
|
|
|
|
# $DOCKER_TOKEN: Docker Hub access token
|
|
|
|
#########################################################################
|
|
|
|
|
|
|
|
echo 'Building Docker image...'
|
|
|
|
DOCKER_REPO="$1"
|
|
|
|
|
2020-05-14 01:15:13 +00:00
|
|
|
function branch_to_tag () {
|
2020-06-16 15:09:48 +00:00
|
|
|
if [ "$1" == "master" ]; then echo "latest"; else echo "$1" ; fi
|
2020-05-14 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function branch_to_deploy_group() {
|
|
|
|
if [[ $1 =~ ^(rrt\/.*)$ ]]; then echo "rrt"; else echo "crconnect" ; fi
|
|
|
|
}
|
|
|
|
|
2020-06-16 15:09:48 +00:00
|
|
|
DOCKER_TAG=$(branch_to_tag "$TRAVIS_BRANCH")
|
2020-05-07 17:49:17 +00:00
|
|
|
|
2020-05-14 01:15:13 +00:00
|
|
|
DEPLOY_GROUP=$(branch_to_deploy_group "$TRAVIS_BRANCH")
|
|
|
|
|
|
|
|
if [ "$DEPLOY_GROUP" == "rrt" ]; then
|
|
|
|
IFS='/' read -ra ARR <<< "$TRAVIS_BRANCH" # Split branch on '/' character
|
2020-06-16 15:09:48 +00:00
|
|
|
DOCKER_TAG=$(branch_to_tag "rrt_${ARR[1]}")
|
2020-05-14 01:15:13 +00:00
|
|
|
fi
|
|
|
|
|
2020-06-16 15:09:48 +00:00
|
|
|
echo "DOCKER_REPO = $DOCKER_REPO"
|
|
|
|
echo "DOCKER_TAG = $DOCKER_TAG"
|
2020-05-14 01:15:13 +00:00
|
|
|
|
|
|
|
echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin || exit 1
|
2020-06-16 15:09:48 +00:00
|
|
|
docker build -f Dockerfile -t "$DOCKER_REPO:$DOCKER_TAG" . || exit 1
|
2020-04-03 13:53:47 +00:00
|
|
|
|
2020-04-23 18:47:07 +00:00
|
|
|
|
2020-06-16 15:09:48 +00:00
|
|
|
# Push Docker image to Docker Hub
|
|
|
|
echo "Publishing to Docker Hub..."
|
|
|
|
docker push "$DOCKER_REPO" || exit 1
|
|
|
|
echo "Done."
|