xref: /OpenGrok/dev/docker.sh (revision c0e56161cde25a904cfdaae770d20a8fd42c76ce)
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
18*c0e56161SVladimir Kotal	print "Not build docker image for pull requests"
19675e1740SVladimir Kotal	exit 0
20675e1740SVladimir Kotalfi
21675e1740SVladimir Kotal
22*c0e56161SVladimir Kotal# Build the image.
23675e1740SVladimir Kotaldocker build -t opengrok/docker:$VERSION -t opengrok/docker:latest .
24*c0e56161SVladimir Kotal#
25*c0e56161SVladimir Kotal# Run the image in container. This is not strictly needed however
26*c0e56161SVladimir Kotal# serves as additional test in automatic builds.
27*c0e56161SVladimir Kotal#
28675e1740SVladimir Kotaldocker run -d opengrok/docker
29675e1740SVladimir Kotaldocker ps -a
30675e1740SVladimir Kotal
31675e1740SVladimir Kotal# Publish the image to Docker hub.
32675e1740SVladimir Kotalif [ -n "$DOCKER_PASSWORD" -a -n "$DOCKER_USERNAME" -a -n "$VERSION" ]; then
33*c0e56161SVladimir Kotal	echo "Logging into docker"
34675e1740SVladimir Kotal	echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
35*c0e56161SVladimir Kotal
36*c0e56161SVladimir Kotal	# All the tags need to be pushed individually:
37*c0e56161SVladimir Kotal	echo "Pushing docker image for tag $VERSION"
38675e1740SVladimir Kotal	docker push opengrok/docker:$VERSION
39*c0e56161SVladimir Kotal	echo "Pushing docker image for tag latest"
40675e1740SVladimir Kotal	docker push opengrok/docker:latest
41675e1740SVladimir Kotalfi
42