Use travis vars

This commit is contained in:
Josh Baker 2018-04-30 17:54:58 -07:00
parent 1b38bf1993
commit e60191caed
2 changed files with 20 additions and 35 deletions

View File

@ -7,4 +7,4 @@ script:
- make test
after_success:
- ./build.sh docker-push
- ./build.sh travis-docker-push

View File

@ -24,9 +24,7 @@ if [ "$1" == "update-version" ]; then
exit
fi
if [ "$1" == "docker-push" ]; then
# GIT_BRANCH - such as master or something else.
export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$1" == "travis-docker-push" ]; then
# GIT_VERSION - always the last verison number, like 1.12.1.
export GIT_VERSION=$(git describe --tags --abbrev=0)
# GIT_TAG - either a version number, like 1.12.1, or the commit after the version, like 1.12.1-10-a718ef0.
@ -35,26 +33,13 @@ if [ "$1" == "docker-push" ]; then
export GIT_COMMIT_SHORT=$(git rev-parse --short HEAD)
# DOCKER_REPO - the base repository name to push the docker build to.
export DOCKER_REPO=$DOCKER_USER/tile38
if [ "$TRAVIS_PULL_REQUEST" == "true" ]; then
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
# never push from a pull request
echo "Not pushing, on a PR"
exit
fi
if [ "$GIT_BRANCH" != "master" ]; then
echo "Not pushing, on a PR or not running in Travis CI"
elif [ "$TRAVIS_BRANCH" != "master" ]; then
# only the master branch will work
echo "Not pushing, not on master"
exit
fi
if [ "$(git status | grep "nothing to commit, working tree clean")" == "" ]; then
# there's stuff to
echo "Not pushing, local git repo is dirty"
exit
fi
if [ "$(git status | grep "branch is up-to-date")" == "" ]; then
# branch must be up-to-date
echo "Not pushing, branch is not up-to-date with master"
exit
fi
else
push(){
docker tag $DOCKER_REPO:$GIT_COMMIT_SHORT $DOCKER_REPO:$1
docker push $DOCKER_REPO:$1
@ -64,12 +49,12 @@ if [ "$1" == "docker-push" ]; then
echo $DOCKER_PASSWORD | docker login -u $DOCKER_LOGIN --password-stdin
# build the docker image
docker build -f Dockerfile -t $DOCKER_REPO:$GIT_COMMIT_SHORT .
if [ "$GIT_VERSION" == "$GIT_TAG" ]; then
push "$GIT_VERSION"
push "latest"
fi
push "edge"
fi
exit
fi