-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_docker.sh
291 lines (285 loc) · 11 KB
/
build_docker.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/bin/sh
# script to build the docker images which is also part of the synology spk tool-chain
#set -euo pipefail
LOGIN=$(whoami)
if [ $# -eq 0 ]
then
echo "Usage: build_docker.sh all | old | core | wmeet | help, get-repo | web-repo, clean."
exit 1
fi
if [ $# -gt 0 ] && [ "$1" = "help" ]
then
echo "Usage: build_docker.sh all | core | wmeet | help, get-repo | web-repo, clean."
echo "1st parameter defines what to build (all, core, wmeet); 2nd if to get the repo or work from web-repo; 3rd to clean cache."
echo "Web-repo has to be created by get-repo first and then copied to /repo in web-server. This option saves time and image space."
exit 0
fi
if [ "$LOGIN" != "root" ]
then
echo "Switching in sudo mode. You may need to provide root password at initial call.."
SUDO="sudo"
else
SUDO=""
fi
B_OLD=0
B_CORE=0
B_WMEET=0
if [ $# -gt 0 ] && [ "$1" = "old" ]
then
B_OLD=1
fi
if [ $# -gt 0 ] && [ "$1" = "all" ]
then
B_CORE=1
B_WMEET=1
fi
if [ $# -gt 0 ] && [ "$1" = "core" ]
then
B_CORE=1
fi
if [ $# -gt 0 ] && [ "$1" = "webmeet" ]
then
B_WMEET=1
fi
if [ -z "$K_EDITION" ]
then
read -p "Pleae provide Kopano K_EDITION to build (Community) : " K_EDITION
if [ -z "$K_EDITION" ] ; then K_EDITION="Community" ; fi
fi
BUILD_PARAMS="--build-arg EDITION=${K_EDITION}"
if [ "$K_EDITION" = "Migration" ]
# old migration running on stretch with php-7.0
then
BUILD_PARAMS="$BUILD_PARAMS --build-arg DEBIAN_VER=stretch --build-arg PHP_VER=7.0"
# debian buster with php-7.3
else
BUILD_PARAMS="$BUILD_PARAMS --build-arg DEBIAN_VER=buster --build-arg PHP_VER=7.3"
fi
if [ "$K_EDITION" != "Community" ] && [ -z "$K_SNR" ]
then
read -p "Pleae provide Kopano subscription Serial-Nr: " K_SNR
fi
echo "Building image for kopano4s $K_EDITION you need to provide sudo pwd at initial start.."
MYDIR=$(dirname "$0")
if [ -z "$DOCKER_PATH" ]
then
if [ -n $(command -v synoshare) ] ; then DOCKER_PATH="$($SUDO synoshare --get docker | grep $'\t Path' | sed 's/.*\[\(.*\)].*/\1/')" ; fi
fi
if [ -z "$DOCKER_HOST" ]
then
DOCKER_HOST=$(ip address show docker0 | grep inet | awk '{print $2}' | cut -f1 -d/ | head -n 1)
fi
"$SUDO" mkdir -p "$DOCKER_PATH"/kopano4s
"$SUDO" mkdir -p "$DOCKER_PATH"/kopano4s/container
# copy over dockerfile and cfg for packages to remove post build, then conatiner init, robot.png
"$SUDO" cp -f "$MYDIR"/SPK-PKG/scripts/container/Dockerfile* "$DOCKER_PATH/kopano4s"
"$SUDO" cp -f "$MYDIR"/SPK-PKG/scripts/container/init* "$DOCKER_PATH/kopano4s/container"
"$SUDO" cp -f "$MYDIR"/SPK-PKG/scripts/container/*.sh "$DOCKER_PATH/kopano4s/container"
"$SUDO" cp -f "$MYDIR"/SPK-PKG/scripts/container/pfloglist "$DOCKER_PATH/kopano4s/container"
"$SUDO" cp -f "$MYDIR"/SPK-PKG/scripts/container/dpkg-remove* "$DOCKER_PATH/kopano4s/container"
"$SUDO" cp -f "$MYDIR"/SPK-APP/merge/kopano-cfg.tgz "$DOCKER_PATH/kopano4s/container"
"$SUDO" cp -f "$MYDIR"/SPK-APP/merge/kinit.tgz "$DOCKER_PATH/kopano4s/container"
"$SUDO" cp -f "$MYDIR"/SPK-APP/ui/images/robot.png "$DOCKER_PATH/kopano4s/container"
echo "Calling kopano4s Dockerfile build at $(date "+%Y%m%d-%H:%M:%S").."
GET_K_DOWNLOAD_RELEASE_TAG()
{
local URL="$1"
local TAG="[[:graph:]]*${2}[[:graph:]]*"
# get basename from download URL for tag (e.g. Debian_9) which is recognized in between double-brackets
local DOWNL=$(curl --silent "$URL" | grep -o "$TAG" | head -1 | cut -f2 -d \")
if [ -z "$DOWNL" ]
then
echo ""
fi
DOWNL_FILE=$(basename "$DOWNL")
if [ -n "$DOWNL_FILE" ]
then
# based on download file split off as major release only the 1st 3 secions on . delimiter
local MAJ_REL=$(echo "$DOWNL_FILE" | grep -o "$TAG" | grep -o "[0-9.]*" | head -1 | cut -f1-3 -d .)
echo "$MAJ_REL"
else
echo ""
fi
}
if [ "$K_EDITION" = "Community" ]
then
TAG1=$( GET_K_DOWNLOAD_RELEASE_TAG "https://download.kopano.io/community/core:/" "Debian_10" )
if [ -z "$TAG1" ]
then
echo "Could not evaluate Kopano core release tag from download; exiting.."
exit 1
fi
#TAG1=8.7.85
TAG2=$( GET_K_DOWNLOAD_RELEASE_TAG "https://download.kopano.io/community/webapp:/" "Debian_10" )
if [ -z "$TAG2" ]
then
echo "Could not evaluate Kopano webapp release tag from download; exiting.."
exit 1
fi
#TAG2=4.2
# currently we cut of 3rd suffix as it is 3 digit number
TAG2=$(echo $TAG2 | cut -f1-2 -d .)
TAG3=$( GET_K_DOWNLOAD_RELEASE_TAG "https://repo.z-hub.io/z-push:/final/Debian_10/all/" "z-push-kopano_" )
if [ -z "$TAG3" ]
then
echo "Could not evaluate Kopano z-push release tag from download; exiting.."
exit 1
fi
TAG4=$( GET_K_DOWNLOAD_RELEASE_TAG "https://download.kopano.io/community/webmeetings:/" "Debian_10" )
if [ -z "$TAG4" ]
then
echo "Could not evaluate Kopano webmeetings release tag from download; exiting.."
exit 1
fi
IMG_TAG="Core-${TAG1}_Webapp-${TAG2}_Z-Push-${TAG3}"
VER_TAG="C-${IMG_TAG}"
C_IMG_TAG="$TAG1"
C_VER_TAG="C-${C_IMG_TAG}"
WM_IMG_TAG="$TAG4"
WM_VER_TAG="C-${WM_IMG_TAG}"
BUILD_PARAMS="$BUILD_PARAMS --build-arg COMMUNITY_BUILD=1"
fi
if [ "$K_EDITION" = "Supported" ]
then
TAG1=$( GET_K_DOWNLOAD_RELEASE_TAG "https://serial:${K_SNR}@download.kopano.io/supported/core:/final/tarballs/" "Debian_9.0" )
if [ -z "$TAG1" ]
then
echo "Could not evaluate Kopano core release tag from download; exiting.."
exit 1
fi
#TAG1=8.7.16
TAG2=$( GET_K_DOWNLOAD_RELEASE_TAG "https://serial:${K_SNR}@download.kopano.io/supported/webapp:/final/tarballs/" "Debian_9.0" )
if [ -z "$TAG2" ]
then
echo "Could not evaluate Kopano webapp release tag from download; exiting.."
exit 1
fi
#TAG2=4.2
# currently we cut of 3rd suffix as it is 3 digit number
TAG2=$(echo $TAG2 | cut -f1-2 -d .)
TAG3=$( GET_K_DOWNLOAD_RELEASE_TAG "https://repo.z-hub.io/z-push:/final/Debian_10/all/" "z-push-kopano_" )
if [ -z "$TAG3" ]
then
echo "Could not evaluate Kopano z-push release tag from download; exiting.."
exit 1
fi
TAG4=$( GET_K_DOWNLOAD_RELEASE_TAG "https://serial:${K_SNR}@download.kopano.io/supported/webmeetings:/final/tarballs/" "Debian_9.0" )
if [ -z "$TAG4" ]
then
echo "Could not evaluate Kopano webmeetings release tag from download; exiting.."
exit 1
fi
IMG_TAG="Core-${TAG1}_Webapp-${TAG2}_Z-Push-${TAG3}"
VER_TAG="S-${IMG_TAG}"
C_IMG_TAG="$TAG1"
C_VER_TAG="S-${C_IMG_TAG}"
WM_IMG_TAG="$TAG4"
WM_VER_TAG="S-${WM_IMG_TAG}"
# passing SNR for download via arg http_proxy not found in docker history.
BUILD_PARAMS="$BUILD_PARAMS --build-arg SUPPORTED_BUILD=1 --build-arg K_SNR=${K_SNR}"
fi
if [ "$K_EDITION" = "Default" ]
then
TAG1="8.7.16"
TAG2="4.4"
TAG3=$( GET_K_DOWNLOAD_RELEASE_TAG "https://repo.z-hub.io/z-push:/final/Debian_10/all/" "z-push-kopano_" )
if [ -z "$TAG3" ]
then
echo "Could not evaluate Kopano z-push release tag from download; exiting.."
exit 1
fi
IMG_TAG="Core-${TAG1}_Webapp-${TAG2}_Z-Push-${TAG3}"
VER_TAG="D-${IMG_TAG}"
C_IMG_TAG="$TAG1"
C_VER_TAG="D-${C_IMG_TAG}"
BUILD_PARAMS="$BUILD_PARAMS --build-arg DEFAULT_BUILD=1 --build-arg K_SNR=${K_SNR}"
fi
if [ "$K_EDITION" = "Migration" ]
then
IMG_TAG="Core-8.4.5.0_Webapp-3.4.2_Z-Push-2.4.5"
VER_TAG="M-${IMG_TAG}"
C_IMG_TAG="8.4.5.0"
C_VER_TAG="M-${C_IMG_TAG}"
BUILD_PARAMS="$BUILD_PARAMS --build-arg MIGRATION_BUILD=1 --build-arg K_SNR=${K_SNR}"
fi
DATE_BUILD=$(date "+%Y-%m-%d")
# in get repo mode only run the k4s-intermediate build and extract repo from container
if [ $# -gt 1 ] && [ "$2" = "get-repo" ]
then
# get the repo from intermediate image aka stop at the stage and copy from container
O_BUILD_PARAMS="$BUILD_PARAMS --target k4s-intermediate --tag tosoboso/k4s-repo:${VER_TAG}"
C_BUILD_PARAMS="$BUILD_PARAMS --target k4s-intermediate --tag tosoboso/k4s-repo:${C_VER_TAG}"
WM_BUILD_PARAMS="$BUILD_PARAMS --target k4s-intermediate --tag tosoboso/k4s-repo:${WM_VER_TAG}"
else
O_BUILD_PARAMS="$BUILD_PARAMS --build-arg PARENT=${DOCKER_HOST} --build-arg BUILD=${DATE_BUILD} --build-arg TAG=${IMG_TAG} --tag tosoboso/kopano4s:${VER_TAG}"
C_BUILD_PARAMS="$BUILD_PARAMS --build-arg PARENT=${DOCKER_HOST} --build-arg BUILD=${DATE_BUILD} --build-arg TAG=${C_IMG_TAG} --tag tosoboso/kopano4s:${C_VER_TAG}"
WM_BUILD_PARAMS="$BUILD_PARAMS --build-arg PARENT=${DOCKER_HOST} --build-arg BUILD=${DATE_BUILD} --build-arg TAG=${WM_IMG_TAG} --tag tosoboso/kopano4s:${WM_VER_TAG}"
fi
# in use repo mode only run the k4-main build and use extracted repo from local webserver
if [ $# -gt 1 ] && [ "$2" = "web-repo" ]
then
WEBREPO=${DOCKER_HOST}/repo
echo "Building from web-repo $WEBREPO assuming you did run get-repo before and put the artifacts to this location.."
# in Dockerfile we comment of the copy from interactive which is skipped anyway via target k4s-main
#sed -i -e 's~^COPY --from=k4s-intermediate~#COPY --from=k4s-intermediate'~ "$DOCKER_PATH"/kopano4s/Dockerfile
O_BUILD_PARAMS="$O_BUILD_PARAMS --build-arg ENV_BUILD=web-repo --build-arg WEBREPO=${WEBREPO}"
C_BUILD_PARAMS="$C_BUILD_PARAMS --build-arg ENV_BUILD=web-repo --build-arg WEBREPO=${WEBREPO}"
WM_BUILD_PARAMS="$WM_BUILD_PARAMS --build-arg ENV_BUILD=web-repo --build-arg WEBREPO=${WEBREPO}"
fi
# remove old image if exists
if $SUDO docker images | grep -q "$VER_TAG"
then
"$SUDO" docker rmi tosoboso/kopano4s:"$VER_TAG"
fi
if ( [ $# -gt 1 ] && [ "$2" = "clean" ] ) || ( [ $# -eq 3 ] && [ "$3" = "clean" ] )
then
# deleting all containers with status exit if no exists error is ok
"$SUDO" docker rm -v $($SUDO docker ps -a -q -f status=exited)
# deleting all images with status dangling - if no exists error is ok
"$SUDO" docker rmi $($SUDO docker images -f "dangling=true" -q)
# searching and deleting images with none as name
LIST=`$SUDO docker images | grep none | grep -o [0-f][0-f][0-f][0-f][0-f][0-f][0-f][0-f][0-f][0-f][0-f][0-f]`
for L in $LIST ; do "$SUDO" docker rmi -f $L ; done
O_BUILD_PARAMS="$O_BUILD_PARAMS --no-cache"
C_BUILD_PARAMS="$C_BUILD_PARAMS --no-cache"
WM_BUILD_PARAMS="$WM_BUILD_PARAMS --no-cache"
fi
if [ $B_OLD -gt 0 ]
then
echo "Build-Args Old: ${O_BUILD_PARAMS}"
"$SUDO" docker build ${DOCKER_PATH}/kopano4s ${O_BUILD_PARAMS}
fi
if [ $B_CORE -gt 0 ]
then
echo "Build-Args Core: ${C_BUILD_PARAMS}"
"$SUDO" docker build ${DOCKER_PATH}/kopano4s -f ${DOCKER_PATH}/kopano4s/Dockerfile.core ${C_BUILD_PARAMS}
fi
if [ $B_WMEET -gt 0 ]
then
echo "Build-Args WebMeetings: ${WM_BUILD_PARAMS}"
"$SUDO" docker build ${DOCKER_PATH}/kopano4s -f ${DOCKER_PATH}/kopano4s/Dockerfile.wmeet ${WM_BUILD_PARAMS}
fi
# if we created image with repo copy it over to place it on a webserver e.g. for wget $PARENT/repo/k4s-${K_EDITION}-repo.tgz
if [ $# -gt 1 ] && [ "$2" = "get-repo" ]
then
if [ $B_OLD -gt 0 ]
then
"$SUDO" docker create -ti --name k4s-repo tosoboso/k4s-repo:${VER_TAG} bash
"$SUDO" docker cp k4s-repo:/root/k4s-${K_EDITION}-repo.tgz .
"$SUDO" docker rm -fv k4s-repo
fi
if [ $B_CORE -gt 0 ]
then
"$SUDO" docker create -ti --name k4s-repo tosoboso/k4s-repo:${C_VER_TAG} bash
"$SUDO" docker cp k4s-repo:/root/k4s-${K_EDITION}-repo.tgz .
"$SUDO" docker rm -fv k4s-repo
fi
if [ $B_WMEET -gt 0 ]
then
"$SUDO" docker create -ti --name k4s-repo tosoboso/k4s-repo:${WM_VER_TAG} bash
"$SUDO" docker cp k4s-repo:/root/k4s-${K_EDITION}-wmeet-repo.tgz .
"$SUDO" docker rm -fv k4s-repo
fi
echo "collected k4s-repo with deb files:"
ls -al k4s-*repo*
fi