1675e1740SVladimir Kotal#!/bin/bash 2675e1740SVladimir Kotal 3675e1740SVladimir Kotal# 4675e1740SVladimir Kotal# Build and push new image to Docker hub. 5675e1740SVladimir Kotal# 6675e1740SVladimir Kotal# Uses the following Travis secure variables: 7675e1740SVladimir Kotal# - DOCKER_USERNAME 8675e1740SVladimir Kotal# - DOCKER_PASSWORD 9675e1740SVladimir Kotal# 10675e1740SVladimir Kotal# These are set via https://travis-ci.com/OpenGrok/docker/settings 11675e1740SVladimir Kotal# 12675e1740SVladimir Kotal 13675e1740SVladimir Kotalset -x 14675e1740SVladimir Kotalset -e 15675e1740SVladimir Kotal 16675e1740SVladimir Kotal# Travis can only work on master since it needs encrypted variables. 17675e1740SVladimir Kotalif [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then 18c0e56161SVladimir Kotal print "Not build docker image for pull requests" 19675e1740SVladimir Kotal exit 0 20675e1740SVladimir Kotalfi 21675e1740SVladimir Kotal 22*f9bac693SVladimir Kotal# Allow Docker builds for release builds only. 23*f9bac693SVladimir Kotalif [[ -z $TRAVIS_TAG ]]; then 24*f9bac693SVladimir Kotal print "TRAVIS_TAG is empty" 25*f9bac693SVladimir Kotal exit 1 26*f9bac693SVladimir Kotalfi 27*f9bac693SVladimir Kotal 28*f9bac693SVladimir KotalVERSION="$TRAVIS_TAG" 29*f9bac693SVladimir Kotal 30c0e56161SVladimir Kotal# Build the image. 31675e1740SVladimir Kotaldocker build -t opengrok/docker:$VERSION -t opengrok/docker:latest . 32c0e56161SVladimir Kotal# 33c0e56161SVladimir Kotal# Run the image in container. This is not strictly needed however 34c0e56161SVladimir Kotal# serves as additional test in automatic builds. 35c0e56161SVladimir Kotal# 36675e1740SVladimir Kotaldocker run -d opengrok/docker 37675e1740SVladimir Kotaldocker ps -a 38675e1740SVladimir Kotal 39675e1740SVladimir Kotal# Publish the image to Docker hub. 40675e1740SVladimir Kotalif [ -n "$DOCKER_PASSWORD" -a -n "$DOCKER_USERNAME" -a -n "$VERSION" ]; then 41c0e56161SVladimir Kotal echo "Logging into docker" 42675e1740SVladimir Kotal echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin 43c0e56161SVladimir Kotal 44c0e56161SVladimir Kotal # All the tags need to be pushed individually: 45c0e56161SVladimir Kotal echo "Pushing docker image for tag $VERSION" 46675e1740SVladimir Kotal docker push opengrok/docker:$VERSION 47c0e56161SVladimir Kotal echo "Pushing docker image for tag latest" 48675e1740SVladimir Kotal docker push opengrok/docker:latest 49675e1740SVladimir Kotalfi 50