1*675e1740SVladimir Kotal#!/bin/bash 2*675e1740SVladimir Kotal 3*675e1740SVladimir Kotal# 4*675e1740SVladimir Kotal# Build and push new image to Docker hub. 5*675e1740SVladimir Kotal# 6*675e1740SVladimir Kotal# Uses the following Travis secure variables: 7*675e1740SVladimir Kotal# - DOCKER_USERNAME 8*675e1740SVladimir Kotal# - DOCKER_PASSWORD 9*675e1740SVladimir Kotal# - GITHUB_TOKEN 10*675e1740SVladimir Kotal# 11*675e1740SVladimir Kotal# These are set via https://travis-ci.com/OpenGrok/docker/settings 12*675e1740SVladimir Kotal# 13*675e1740SVladimir Kotal 14*675e1740SVladimir Kotalset -x 15*675e1740SVladimir Kotalset -e 16*675e1740SVladimir Kotal 17*675e1740SVladimir Kotal# Travis can only work on master since it needs encrypted variables. 18*675e1740SVladimir Kotalif [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then 19*675e1740SVladimir Kotal exit 0 20*675e1740SVladimir Kotalfi 21*675e1740SVladimir Kotal 22*675e1740SVladimir KotalJSON_OUT="ver.out" 23*675e1740SVladimir Kotal 24*675e1740SVladimir Kotal# 25*675e1740SVladimir Kotal# Get the latest OpenGrok version string. Use authenticated request to avoid 26*675e1740SVladimir Kotal# rate limiting induced errors. 27*675e1740SVladimir Kotal# 28*675e1740SVladimir Kotalcurl -sS -o "$JSON_OUT" \ 29*675e1740SVladimir Kotal -H "Authorization: token $GITHUB_TOKEN" \ 30*675e1740SVladimir Kotal https://api.github.com/repos/oracle/opengrok/releases/latest 31*675e1740SVladimir Kotalcat "$JSON_OUT" 32*675e1740SVladimir KotalVERSION=`jq -er .tag_name ver.out` 33*675e1740SVladimir Kotalecho "Latest OpenGrok tag: $VERSION" 34*675e1740SVladimir Kotal 35*675e1740SVladimir Kotal# Embed the tarball URL into the Dockerfile. 36*675e1740SVladimir Kotaltarball=`jq -er '.assets[]|select(.name|test("opengrok-.*tar.gz"))|.browser_download_url' "$JSON_OUT"` 37*675e1740SVladimir Kotalecho "Tarball URL: $tarball" 38*675e1740SVladimir Kotalsed "s%OPENGROK_DOWNLOAD_LINK%$tarball%" Dockerfile.tmpl > Dockerfile 39*675e1740SVladimir Kotal 40*675e1740SVladimir Kotal# Build and run the image in container. 41*675e1740SVladimir Kotaldocker build -t opengrok/docker:$VERSION -t opengrok/docker:latest . 42*675e1740SVladimir Kotaldocker run -d opengrok/docker 43*675e1740SVladimir Kotaldocker ps -a 44*675e1740SVladimir Kotal 45*675e1740SVladimir Kotal# Publish the image to Docker hub. 46*675e1740SVladimir Kotalif [ -n "$DOCKER_PASSWORD" -a -n "$DOCKER_USERNAME" -a -n "$VERSION" ]; then 47*675e1740SVladimir Kotal echo "Pushing image for version $VERSION" 48*675e1740SVladimir Kotal echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin 49*675e1740SVladimir Kotal docker push opengrok/docker:$VERSION 50*675e1740SVladimir Kotal docker push opengrok/docker:latest 51*675e1740SVladimir Kotalfi 52