-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins-docker-build-and-push.sh
executable file
·44 lines (37 loc) · 1.33 KB
/
jenkins-docker-build-and-push.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
#
# Build docker image with tag based on git revision or tag if it exists
# and push it to the registry. The script is called from .jenkins.yaml.
#
# We also pass on this version string as a --build-arg to the docker
# build so that the resulting binary in the container uses that same
# version string for logs etc.
#
# When modifiying this script run it through shellcheck
# (https://www.shellcheck.net/) before commiting.
#
set -e
script_name=$(basename "$0")
project_name=$(basename "$(pwd)")
image_name="geteduroam-ocsp"
echo "running SUNET/${project_name}/${script_name}"
# We expect Jenkins to have set GIT_COMMIT for us.
if [ "$GIT_COMMIT" = "" ]; then
echo "$script_name: GIT_COMMIT is not set, exiting"
exit 1
fi
VERSION=$(git tag --contains "${GIT_COMMIT}" | head -1)
if [ "$VERSION" = "" ]; then
echo "${script_name}: did not find a tag related to revision ${GIT_COMMIT}, using rev as version"
VERSION=${GIT_COMMIT}
fi
BASE_TAG="docker.sunet.se/${image_name}"
DOCKER_TAG="${BASE_TAG}:${VERSION}"
LATEST_TAG="${BASE_TAG}:latest"
echo "${script_name}: building DOCKER_TAG ${DOCKER_TAG} ${LATEST_TAG}"
docker build --tag "${DOCKER_TAG}" --tag "${LATEST_TAG}" .
#docker push --all-tags ${BASE_TAG}
# Workaround for old docker verison on CI
for tag in ${DOCKER_TAG} ${LATEST_TAG}; do
docker push "${tag}"
done