Skip to content

Commit

Permalink
added Docker Hub push automation
Browse files Browse the repository at this point in the history
  • Loading branch information
simplesteph committed Mar 7, 2018
1 parent 0baa827 commit 0dfd05d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
17 changes: 16 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
language: scala
sudo: required

services:
- docker

scala:
- 2.12.4

script:
- ./test.sh
- ./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
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ parallelExecution in Test := false

// Docker stuff
dockerRepository := Some("simplesteph")
dockerUpdateLatest := true
File renamed without changes.
29 changes: 29 additions & 0 deletions docker_push.sh
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 0dfd05d

Please sign in to comment.