Skip to content

Commit 675e174

Browse files
author
Vladimir Kotal
committed
add docker build script from OpenGrok/docker repo
1 parent 6670a14 commit 675e174

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

dev/docker.sh

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

0 commit comments

Comments
 (0)