forked from GerritCodeReview/k8s-gerrit
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·132 lines (111 loc) · 2.76 KB
/
build
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
BASE_IMAGE=alpine:3.16.1
usage() {
me=`basename "$0"`
echo >&2 "Usage: $me [--help] [--tag TAG] [--gerrit-url URL] [--base-image IMAGE] [IMAGE]"
exit 1
}
while test $# -gt 0 ; do
case "$1" in
--help)
usage
;;
--tag)
shift
TAG=$1
shift
;;
--gerrit-url)
shift
GERRIT_WAR_URL=$1
shift
;;
--healthcheck-jar-url)
shift
HEALTHCHECK_JAR_URL=$1
shift
;;
--base-image)
shift
BASE_IMAGE=$1
shift
;;
*)
break
esac
done
#Get list of images
source container-images/publish_list
IMAGES=$(get_image_list)
if test -n "$GERRIT_WAR_URL"; then
BUILD_ARGS="--build-arg GERRIT_WAR_URL=$GERRIT_WAR_URL"
fi
if test -n "$HEALTHCHECK_JAR_URL"; then
BUILD_ARGS="$BUILD_ARGS --build-arg HEALTHCHECK_JAR_URL=$HEALTHCHECK_JAR_URL"
fi
export REV="$(git describe --always --dirty)"
docker_build(){
IMAGE=$1
docker build \
--platform=linux/amd64 \
--build-arg TAG=$REV \
-t k8sgerrit/$IMAGE:$TAG \
./container-images/$IMAGE
if test $? -ne 0; then
REPORT="$REPORT Failed: k8sgerrit/$IMAGE.\n"
RETURN_CODE=1
else
REPORT="$REPORT Success: k8sgerrit/$IMAGE:$TAG\n"
fi
}
docker_build_gerrit_base(){
BUILD_ARGS="$BUILD_ARGS --build-arg TAG=$REV"
docker build \
--platform=linux/amd64 \
$BUILD_ARGS \
-t gerrit-base:$REV \
./container-images/gerrit-base
if test $? -ne 0; then
echo -e "\n\nFailed to build gerrit-base image."
exit 1
fi
if test -z "$TAG"; then
export TAG="$(create_image_tag)"
fi
}
create_image_tag(){
GERRIT_VERSION=$(docker run --platform=linux/amd64 --entrypoint "/bin/sh" gerrit-base:$REV \
-c "java -jar /var/gerrit/bin/gerrit.war version")
GERRIT_VERSION=$(echo "${GERRIT_VERSION##*$'\n'}" | cut -d' ' -f3 | tr -d '[:space:]')
echo "$REV-$GERRIT_VERSION"
}
REPORT="Build results: \n"
RETURN_CODE=0
docker build --build-arg BASE_IMAGE="$BASE_IMAGE" --platform=linux/amd64 -t base:$REV ./container-images/base
if test $? -ne 0; then
echo -e "\n\nFailed to build base image."
exit 1
fi
if test $# -eq 0 ; then
docker_build_gerrit_base
for IMAGE in $IMAGES; do
docker_build $IMAGE
done
else
while test $# -gt 0 ; do
if [[ $1 = gerrit-* ]]; then
docker_build_gerrit_base
else
if test -z "$TAG"; then
TAG="$(git describe --always --dirty)-unknown"
fi
echo -e "\nNo Image containing Gerrit will be built." \
"The Gerrit-version can thus not be determinded." \
"Using tag $TAG\n"
fi
docker_build $1
shift
done
fi
echo -e "\n\n$REPORT"
exit $RETURN_CODE