diff --git a/.travis.yml b/.travis.yml index 513e391..80bf8ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ sudo: required language: java -install: true - +jdk: openjdk11 +install: skip services: - docker @@ -9,24 +9,28 @@ services: jobs: include: - stage: build (compile, unit test, package) - language: java - jdk: openjdk11 - install: skip script: travis/build.sh - - stage: container creation and publishing - install: skip - script: travis/containerCreation.sh + - stage: container creation + script: + - travis/containerCreation.sh - stage: smoke and acceptance test + language: minimal install: skip # without this there's a `git clone` and `gradlew assemble` executed! script: travis/acceptanceTest.sh - - stage: release - if: branch = master AND NOT type IN (pull_request) + - stage: release and tag on DockerHub + if: tag =~ ^v[0-9.]*$ + language: minimal install: skip - script: travis/release.sh - post_script: travis/delete-dockerhub-images.sh + deploy: + provider: script + script: travis/release.sh + on: + tags: true + after_deploy: + - travis/delete-dockerhub-images.sh import: - docs/.travis.yml diff --git a/docs/.travis.yml b/docs/.travis.yml index 1da5117..c537a3b 100644 --- a/docs/.travis.yml +++ b/docs/.travis.yml @@ -1,7 +1,9 @@ jobs: include: - stage: generate docs - if: branch = master AND NOT type IN (pull_request) + if: tag =~ ^v[0-9.]*$ + language: minimal + install: skip # Assume that 'docker' service is stated at the Travis global level. It seems that re-stating it here confuses Travis. # services: diff --git a/travis/containerCreation.sh b/travis/containerCreation.sh index 9278c28..c206b89 100755 --- a/travis/containerCreation.sh +++ b/travis/containerCreation.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # fail fast settings from https://dougrichardson.org/2018/08/03/fail-fast-bash-scripting.html -set -euov pipefail +set -eov pipefail # obtain current repository name REPO_LOCAL_PATH=`git rev-parse --show-toplevel` @@ -18,6 +18,10 @@ buildTag=travis_$TRAVIS_BUILD_NUMBER # We use a temporary build number for taggi docker build -t eoepca/${REPO_NAME} . docker tag eoepca/${REPO_NAME} eoepca/${REPO_NAME}:$buildTag # Tags container in EOEPCA repository with buildTag -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - -docker push eoepca/${REPO_NAME}:$buildTag # defaults to docker hub EOEPCA repository +if [ -n "${DOCKER_USERNAME}" -a -n "${DOCKER_PASSWORD}" ] +then + echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + docker push eoepca/${REPO_NAME}:$buildTag # defaults to docker hub EOEPCA repository +else + echo "WARNING: No credentials - Cannot push to docker hub" +fi diff --git a/travis/release.sh b/travis/release.sh index b163ca9..e0f6a09 100755 --- a/travis/release.sh +++ b/travis/release.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # fail fast settings from https://dougrichardson.org/2018/08/03/fail-fast-bash-scripting.html -set -euov pipefail +set -eov pipefail # Check presence of environment variables TRAVIS_BUILD_NUMBER="${TRAVIS_BUILD_NUMBER:-0}" @@ -13,13 +13,18 @@ REPO_NAME=`basename $REPO_LOCAL_PATH` # Create a Docker image and tag it as 'travis_' buildTag=travis_$TRAVIS_BUILD_NUMBER # We use a temporary build number for tagging, since this is a transient artefact -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin -docker pull eoepca/${REPO_NAME}:${buildTag} # have to pull locally in order to tag as a release +if [ -n "${DOCKER_USERNAME}" -a -n "${DOCKER_PASSWORD}" ] +then + echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + docker pull eoepca/${REPO_NAME}:${buildTag} # have to pull locally in order to tag as a release -# Tag and push as a Release following the SemVer approach, e.g. 0.1.1-Alpha -docker tag eoepca/${REPO_NAME}:${buildTag} eoepca/${REPO_NAME}:release_${TRAVIS_TAG} # This recovers the GitHub release/tag number -docker push eoepca/${REPO_NAME}:release_${TRAVIS_TAG} + # Tag and push as a Release following the SemVer approach, e.g. 0.1.1-Alpha + docker tag eoepca/${REPO_NAME}:${buildTag} eoepca/${REPO_NAME}:${TRAVIS_TAG} # This recovers the GitHub release/tag number + docker push eoepca/${REPO_NAME}:${TRAVIS_TAG} -# Tag and push as `latest` -docker tag eoepca/${REPO_NAME}:${buildTag} eoepca/${REPO_NAME}:latest -docker push eoepca/${REPO_NAME}:latest + # Tag and push as `latest` + docker tag eoepca/${REPO_NAME}:${buildTag} eoepca/${REPO_NAME}:latest + docker push eoepca/${REPO_NAME}:latest +else + echo "WARNING: No credentials - Cannot push to docker hub" +fi