diff --git a/.travis.yml b/.travis.yml index f4436b4..9649845 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,22 @@ language: scala +sudo: required + +services: + - docker scala: - 2.12.4 script: - - ./test.sh \ No newline at end of file + - ./test.sh + +# Improvement: move logic out of docker_push.sh into .travis.yml +deploy: + provider: script + script: bash docker_push.sh + skip_cleanup: true +# on: +# all_branches: true +# tags: true / false => has precendence over the branch condition +# condition: "foo == bar && baz==bat" +# repo: simplesteph/kafka-security-manager \ No newline at end of file diff --git a/build.sbt b/build.sbt index a2e638d..ddbbe1b 100644 --- a/build.sbt +++ b/build.sbt @@ -39,3 +39,4 @@ parallelExecution in Test := false // Docker stuff dockerRepository := Some("simplesteph") +dockerUpdateLatest := true diff --git a/build-docker.sh b/docker_build.sh old mode 100755 new mode 100644 similarity index 100% rename from build-docker.sh rename to docker_build.sh diff --git a/docker_push.sh b/docker_push.sh new file mode 100644 index 0000000..3a13191 --- /dev/null +++ b/docker_push.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +./docker_build.sh + +docker_push(){ + echo "Pushing tag $1 to docker hub" + docker tag "simplesteph/kafka-security-manager:latest" "simplesteph/kafka-security-manager:$1" + docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"; + docker push "simplesteph/kafka-security-manager:$1" +} + +# TRAVIS_TAG: If the current build is for a git tag, this variable is set to the tag’s name. +# TRAVIS_PULL_REQUEST_BRANCH: if the current job is a pull request, the name of the branch from which the PR originated. + +if [[ "$TRAVIS_PULL_REQUEST_BRANCH" == "" ]]; then + if [[ "$TRAVIS_TAG" =! "" ]]; then + # Tagging should trigger a release in Docker Hub, that's immutable. + echo "git tag action, push the tag" + docker_push "$TRAVIS_TAG-release" + elif [[ "$TRAVIS_BRANCH" == "master" ]]; then + # we push to latest when master is built and that's not a pull request + echo "master build, push to latest" + docker_push "latest" + elif [[ "$TRAVIS_BRANCH" ~= "v*" ]]; then + # this is a version branch and we push it. + echo "branch build, push to branch-latest" + docker_push "$TRAVIS_BRANCH-latest" + fi; +fi; \ No newline at end of file