Skip to content

Commit 3e788c1

Browse files
author
Vladimir Kotal
committed
always build Docker image
fixes #2867
1 parent 3185e59 commit 3e788c1

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ jobs:
8282
dist: xenial
8383
jdk: openjdk8
8484
install: true
85-
if: repo = "oracle/opengrok" AND tag IS present
8685
services:
8786
- docker
8887
before_install: dev/before_install

dev/docker.sh

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22

33
#
4-
# Build and push new image to Docker hub.
4+
# Build and optionally push new image to Docker hub.
55
#
6-
# Uses the following Travis secure variables:
6+
# When pushing, this script uses the following Travis secure variables:
77
# - DOCKER_USERNAME
88
# - DOCKER_PASSWORD
99
#
@@ -13,31 +13,14 @@
1313
set -x
1414
set -e
1515

16-
# Travis can only work on master since it needs encrypted variables.
17-
if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then
18-
echo "Not building docker image for pull requests"
19-
exit 0
16+
if [[ -n $TRAVIS_TAG ]]; then
17+
VERSION="$TRAVIS_TAG"
18+
VERSION_SHORT=$( echo $VERSION | cut -d. -f1,2 )
19+
else
20+
VERSION="latest"
21+
VERSION_SHORT="latest"
2022
fi
2123

22-
# Allow Docker builds for release builds only.
23-
if [[ -z $TRAVIS_TAG ]]; then
24-
echo "TRAVIS_TAG is empty"
25-
exit 0
26-
fi
27-
28-
if [[ -z $DOCKER_USERNAME ]]; then
29-
echo "DOCKER_USERNAME is empty"
30-
exit 1
31-
fi
32-
33-
if [[ -z $DOCKER_PASSWORD ]]; then
34-
echo "DOCKER_PASSWORD is empty"
35-
exit 1
36-
fi
37-
38-
VERSION="$TRAVIS_TAG"
39-
VERSION_SHORT=$( echo $VERSION | cut -d. -f1,2 )
40-
4124
if [[ -z $VERSION ]]; then
4225
echo "empty VERSION"
4326
exit 1
@@ -61,6 +44,34 @@ docker build \
6144
docker run -d opengrok/docker
6245
docker ps -a
6346

47+
# Travis can only work on master since it needs encrypted variables.
48+
if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then
49+
echo "Not publishing docker image for pull requests"
50+
exit 0
51+
fi
52+
53+
# The push only works on the main repository.
54+
if [[ "${TRAVIS_REPO_SLUG}" != "oracle/opengrok" ]]; then
55+
echo "Not publishing docker image for non main repository"
56+
exit 0
57+
fi
58+
59+
# Allow Docker publish for release builds only.
60+
if [[ -z $TRAVIS_TAG ]]; then
61+
echo "TRAVIS_TAG is empty"
62+
exit 0
63+
fi
64+
65+
if [[ -z $DOCKER_USERNAME ]]; then
66+
echo "DOCKER_USERNAME is empty"
67+
exit 1
68+
fi
69+
70+
if [[ -z $DOCKER_PASSWORD ]]; then
71+
echo "DOCKER_PASSWORD is empty"
72+
exit 1
73+
fi
74+
6475
# Publish the image to Docker hub.
6576
if [ -n "$DOCKER_PASSWORD" -a -n "$DOCKER_USERNAME" -a -n "$VERSION" ]; then
6677
echo "Logging into docker"

0 commit comments

Comments
 (0)