diff --git a/.travis.yml b/.travis.yml index d037b25dc..6143214f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,32 +4,19 @@ services: - docker jdk: - oraclejdk8 +env: + - TEST_PHASE=unit + - TEST_PHASE=system-broccoli-only + - TEST_PHASE=system-broccoli-nomad + - TEST_PHASE=system-broccoli-nomad-consul script: - - uname -r - - sbt test - - sbt dist - - unzip target/universal/cluster-broccoli*.zip - - cp -R cluster-broccoli-* docker/test/cluster-broccoli-dist - - cp -R cluster-broccoli-* docker/prod/cluster-broccoli-dist - - cp -R templates docker/test/ - - cp -R templates docker/prod/ - - docker build -t frosner/cluster-broccoli-test docker/test/ - - bash <(curl -s https://raw.githubusercontent.com/FRosner/http-api-tester/master/http-api-tester) -v -d http-api-tests/broccoli-only - - bash <(curl -s https://raw.githubusercontent.com/FRosner/http-api-tester/master/http-api-tester) -v -d http-api-tests/broccoli-nomad - - bash <(curl -s https://raw.githubusercontent.com/FRosner/http-api-tester/master/http-api-tester) -v -d http-api-tests/broccoli-nomad-consul - + - travis/test cache: directories: - $HOME/.m2 - $HOME/.ivy2 - -after_success: - - bash <(curl -s https://codecov.io/bash) - - docker login -u $DOCKER_USER -p $DOCKER_PASSWORD - - export COMMIT=${TRAVIS_COMMIT::8} - - export REPO=frosner/cluster-broccoli - - export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH ; fi` - - docker build -t $REPO:$COMMIT docker/prod/ - - docker tag $REPO:$COMMIT $REPO:$TAG - - docker tag $REPO:$COMMIT $REPO:travis-$TRAVIS_BUILD_NUMBER - - docker push $REPO +deploy: + provider: script + script: travis/deploy + on: + all_branches: true diff --git a/travis/deploy b/travis/deploy new file mode 100755 index 000000000..808675026 --- /dev/null +++ b/travis/deploy @@ -0,0 +1,25 @@ +#!/bin/bash +# https://docs.travis-ci.com/user/deployment/script/ + +set -e +set -o pipefail + +echo "Building Broccoli distribution" +sbt dist +unzip target/universal/cluster-broccoli*.zip +cp -R cluster-broccoli-* docker/prod/cluster-broccoli-dist +cp -R templates docker/prod/ + +echo "Logging into docker registry" +docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + +echo "Building docker image" +export COMMIT=${TRAVIS_COMMIT::8} +export REPO=frosner/cluster-broccoli +export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH ; fi` +docker build -t $REPO:$COMMIT docker/prod/ + +echo "Pushing docker image" +docker tag $REPO:$COMMIT $REPO:$TAG +docker tag $REPO:$COMMIT $REPO:travis-$TRAVIS_BUILD_NUMBER +docker push $REPO diff --git a/travis/test b/travis/test new file mode 100755 index 000000000..cd4313ff5 --- /dev/null +++ b/travis/test @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e +set -o pipefail + +echo "Selected TEST_PHASE is $TEST_PHASE" + +unit_tests() { + echo "Starting unit tests" + sbt test +} + +system_tests() { + echo "Preparing system tests" + sbt dist + unzip target/universal/cluster-broccoli*.zip + cp -R cluster-broccoli-* docker/test/cluster-broccoli-dist + cp -R templates docker/test/ + docker build -t frosner/cluster-broccoli-test docker/test/ + if [ "${TEST_PHASE}" = "system-broccoli-only" ]; then + echo "Starting broccoli-only tests" + bash <(curl -s https://raw.githubusercontent.com/FRosner/http-api-tester/master/http-api-tester) -v -d http-api-tests/broccoli-only + elif [ "${TEST_PHASE}" = "system-broccoli-nomad" ]; then + echo "Starting broccoli-nomad tests" + bash <(curl -s https://raw.githubusercontent.com/FRosner/http-api-tester/master/http-api-tester) -v -d http-api-tests/broccoli-nomad + elif [ "${TEST_PHASE}" = "system-broccoli-nomad-consul" ]; then + echo "Starting broccoli-nomad-consul tests" + bash <(curl -s https://raw.githubusercontent.com/FRosner/http-api-tester/master/http-api-tester) -v -d http-api-tests/broccoli-nomad-consul + else + echo "Test phase '$TEST_PHASE' not recognized" + exit 1 + fi +} + +if [ "${TEST_PHASE}" = "unit" ]; then + unit_tests +elif [[ "$TEST_PHASE" == system* ]]; then + system_tests +else + echo '$TEST_PHASE not set correctly' + exit 1 +fi