-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_docker_image
executable file
·102 lines (86 loc) · 3.04 KB
/
build_docker_image
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
set -euxo pipefail
APP_ID="ox-connector"
APP_VERSION="$(grep -E '^Version' app/ini | cut -f 3 -d ' ')"
DOCKERFILE="$(basename "$(readlink -f Dockerfile)")"
DOCKERFILE_TEST="$DOCKERFILE-test"
BASE_IMG="$(egrep ^FROM "$DOCKERFILE" | cut -d ' ' -f 2-)"
APP_IMG_NO_VERSION="docker-test-upload.software-univention.de/${APP_ID}"
APP_IMG="${APP_IMG_NO_VERSION}:${APP_VERSION}"
APP_IMG_TEST="${APP_IMG_NO_VERSION}:${APP_VERSION}-test"
DOCKER_REGISTRY_SERVER="docker.knut.univention.de"
APPSUITE_REPO_DIR="appsuite"
APPSUITE_BRANCH="dwiesent/ox-provisioning-app"
GIT_ARGS="-c http.sslVerify=false"
#GIT_REPO_URI="https://git.knut.univention.de/univention/open-xchange/appsuite.git"
OUR_PYTHON_PACKAGES="univention-ox-soap-api univention-ox-provisioning"
BUILD_ARGS=""
PROXY_ARGS=""
RELEASE=0
if [ "${1:-}" = "--release" ] || [ "${2:-}" = "--release" ] || [ "${3:-}" = "--release" ]; then
RELEASE=1
fi
PUSH_DEV=0
if [ "${1:-}" = "--push" ] || [ "${2:-}" = "--push" ] || [ "${3:-}" = "--push" ]; then
PUSH_DEV=1
fi
if [ "${1:-}" = "--yes" ] || [ "${2:-}" = "--yes" ] || [ "${3:-}" = "--yes" ]; then
PUSH_YES=1
fi
if [ "$PUSH_DEV" = 1 ] && [ "$(hostname -f)" != "$DOCKER_REGISTRY_SERVER" ]; then
echo "Pushing image to docker registry only possible on $DOCKER_REGISTRY_SERVER."
exit 1
fi
if [ -n "${http_proxy:-}" ]; then
PROXY_ARGS="--build-arg http_proxy=$http_proxy --build-arg https_proxy=$http_proxy"
fi
echo "APP_ID=$APP_ID"
echo "APP_VERSION=$APP_VERSION"
echo "BASE_IMG=$BASE_IMG"
echo "APP_IMG=$APP_IMG"
echo "DOCKERFILE: $DOCKERFILE"
echo "PROXY_ARGS: $PROXY_ARGS"
echo "Updating base image..."
docker pull "$BASE_IMG"
if [ "$RELEASE" = 1 ]; then
echo "Removing old final image..."
docker rmi -f "$APP_IMG" || true
fi
#echo "Updating 'appsuite' git repo submodule..."
#if [ -e .git ]; then
# # developer system
# git $GIT_ARGS submodule update --init --recursive
# (cd "$APPSUITE_REPO_DIR" && git checkout "$APPSUITE_BRANCH")
# git $GIT_ARGS submodule foreach --recursive git pull
#else
# # docker build host
# if ! [ -d "$APPSUITE_REPO_DIR" ]; then
# git $GIT_ARGS clone --depth=1 -b "$APPSUITE_BRANCH" "$GIT_REPO_URI" "$APPSUITE_REPO_DIR"
# fi
# (cd "$APPSUITE_REPO_DIR" && git checkout "$APPSUITE_BRANCH" && git $GIT_ARGS pull)
#fi
echo "Collecting all Python dependencies..." # to minimize Docker image by installing and uninstalling in one step
find $OUR_PYTHON_PACKAGES -name 'requirements.txt' -exec cat {} + | \
egrep -v 'univention' | \
grep -v 'six' | \
sort | \
uniq > requirements_all.txt
echo "Building docker image..."
if [ "$RELEASE" = 1 ]; then
BUILD_ARGS="--no-cache"
fi
docker build $PROXY_ARGS $BUILD_ARGS --build-arg version="$APP_VERSION" -t "$APP_IMG" .
echo "Local Docker images:"
docker images "$APP_IMG_NO_VERSION"
if [ "$PUSH_DEV" = 1 ]; then
if [ -z "$PUSH_YES" ]; then
read -p "Push 'Y' if you are sure you want to push '$APP_IMG' to the docker registry. " -n 1 -r
else
REPLY="y"
fi
echo
if [[ $REPLY =~ ^[yY]$ ]]; then
echo "Pushing image to docker registry..."
docker push "$APP_IMG"
fi
fi