forked from openhab/openhab-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-docker-files.sh
executable file
·419 lines (371 loc) · 11.3 KB
/
update-docker-files.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#!/bin/bash
set -eo pipefail
. update-functions.sh
# Distribution download URLs
openhab1_release_url='https://bintray.com/artifact/download/openhab/bin/distribution-${version}-runtime.zip'
openhab2_release_url='https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F${version}%2Fopenhab-${version}.zip'
openhab2_milestone_url='https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab/${version}/openhab-${version}.zip'
openhab2_snapshot_url='https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${version}.zip'
openhab3_snapshot_url='https://ci.openhab.org/job/openHAB3-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${version}.zip'
# Zulu 8 download URLs
zulu8_amd64_url='https://cdn.azul.com/zulu/bin/zulu8.42.0.23-ca-jdk8.0.232-linux_x64.tar.gz'
zulu8_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.42.0.195-ca-jdk1.8.0_232-linux_aarch32hf.tar.gz'
zulu8_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.42.0.195-ca-jdk1.8.0_232-linux_aarch64.tar.gz'
# Zulu 11 download URLs
zulu11_amd64_url='https://cdn.azul.com/zulu/bin/zulu11.37.17-ca-jdk11.0.6-linux_x64.tar.gz'
zulu11_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.37.48-ca-jdk11.0.6-linux_aarch32hf.tar.gz'
zulu11_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.37.48-ca-jdk11.0.6-linux_aarch64.tar.gz'
zulu_url_vars=(zulu8_amd64_url zulu8_armhf_url zulu8_arm64_url zulu11_amd64_url zulu11_armhf_url zulu11_arm64_url)
# Generate header
print_header() {
cat > $1 <<-EOI
# openhab image
#
# ------------------------------------------------------------------------------
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
# ------------------------------------------------------------------------------
#
EOI
}
# Print selected image
print_baseimage() {
# Set download URL for openHAB version
case $version in
1.*)
openhab_url=$(eval "echo $openhab1_release_url")
;;
2.*.M*|2.*.RC*|3.*.M*|3.*.RC*)
openhab_url=$(eval "echo $openhab2_milestone_url")
;;
2.*-snapshot)
openhab_url=$(eval "echo $openhab2_snapshot_url" | sed 's/snapshot/SNAPSHOT/g')
;;
3.*-snapshot)
openhab_url=$(eval "echo $openhab3_snapshot_url" | sed 's/snapshot/SNAPSHOT/g')
;;
2.*|3.*)
openhab_url=$(eval "echo $openhab2_release_url")
;;
*)
openhab_url="error"
;;
esac
# Set Java version based on openHAB versions
case $version in
1.*|2.*)
java_version="8"
;;
3.*)
java_version="11"
;;
*)
java_version="error"
;;
esac
# Set Docker base image based on distributions
case $base in
alpine)
base_image="alpine:3.11.5"
;;
debian)
base_image="debian:10.3-slim"
;;
*)
base_image="error"
;;
esac
cat >> $1 <<-EOI
FROM $base_image
# Set download urls
ENV \\
JAVA_VERSION="$java_version" \\
OPENHAB_URL="$openhab_url" \\
OPENHAB_VERSION="$version"
EOI
}
# Print metadata
print_basemetadata() {
cat >> $1 <<-'EOI'
# Set variables and locales
ENV \
CRYPTO_POLICY="limited" \
EXTRA_JAVA_OPTS="" \
GROUP_ID="9001" \
KARAF_EXEC="exec" \
LC_ALL="en_US.UTF-8" \
LANG="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8" \
OPENHAB_BACKUPS="/openhab/userdata/backup" \
OPENHAB_CONF="/openhab/conf" \
OPENHAB_HOME="/openhab" \
OPENHAB_HTTP_PORT="8080" \
OPENHAB_HTTPS_PORT="8443" \
OPENHAB_LOGDIR="/openhab/userdata/logs" \
OPENHAB_USERDATA="/openhab/userdata" \
USER_ID="9001"
# Set arguments on build
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
# Basic build-time metadata as defined at http://label-schema.org
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.docker.dockerfile="/Dockerfile" \
org.label-schema.license="EPL-2.0" \
org.label-schema.name="openHAB" \
org.label-schema.vendor="openHAB Foundation e.V." \
org.label-schema.version=$VERSION \
org.label-schema.description="An open source, technology agnostic home automation platform" \
org.label-schema.url="https://www.openhab.com/" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-type="Git" \
org.label-schema.vcs-url="https://github.com/openhab/openhab-docker.git" \
maintainer="openHAB <[email protected]>"
EOI
}
# Print basepackages for Alpine
print_basepackages_alpine() {
cat >> $1 <<-'EOI'
# Install basepackages
RUN apk update --no-cache && \
apk add --no-cache \
arping \
bash \
ca-certificates \
curl \
fontconfig \
libcap \
nss \
shadow \
su-exec \
tini \
ttf-dejavu \
openjdk${JAVA_VERSION} \
unzip \
wget \
zip && \
chmod u+s /usr/sbin/arping && \
rm -rf /var/cache/apk/*
EOI
}
# Print basepackages for Debian
print_basepackages_debian() {
cat >> $1 <<-'EOI'
# Install basepackages
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
arping \
ca-certificates \
curl \
fontconfig \
gosu \
libcap2-bin \
locales \
locales-all \
netbase \
procps \
tini \
unzip \
wget \
zip && \
chmod u+s /usr/sbin/arping && \
ln -s -f /bin/true /usr/bin/chfn && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
EOI
}
# Configure Java for Alpine
print_java_alpine() {
cat >> $1 <<-'EOI'
# Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography
ENV JAVA_HOME='/usr/lib/jvm/default-jvm'
RUN if [ "${JAVA_VERSION}" = "8" ]; then \
sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \
elif [ "${JAVA_VERSION}" = "11" ]; then \
sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \
fi
EOI
}
# Install Java for Debian
print_java_debian() {
cat >> $1 <<-'EOI'
# Install java
ENV JAVA_HOME='/usr/lib/jvm/default-jvm'
# Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography
RUN mkdir -p "${JAVA_HOME}" && \
EOI
for zulu_url_var in ${zulu_url_vars[@]}
do
cat >> $1 <<-EOI
$zulu_url_var='${!zulu_url_var}' && \\
EOI
done
cat >> $1 <<-'EOI'
url_var="zulu${JAVA_VERSION}_$(dpkg --print-architecture)_url" && \
eval "java_url=\$$url_var" && \
wget -nv -O /tmp/java.tar.gz "${java_url}" && \
tar --exclude='demo' --exclude='sample' --exclude='src.zip' -xf /tmp/java.tar.gz --strip-components=1 -C "${JAVA_HOME}" && \
if [ "${JAVA_VERSION}" = "8" ]; then \
sed -i 's/^#crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \
elif [ "${JAVA_VERSION}" = "11" ]; then \
sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \
fi && \
rm /tmp/java.tar.gz && \
update-alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 50 && \
update-alternatives --install /usr/bin/javac javac "${JAVA_HOME}/bin/javac" 50
EOI
}
# Install openHAB 1.x
print_openhab_install_oh1() {
cat >> $1 <<-'EOI'
# Install openHAB
RUN wget -nv -O /tmp/openhab.zip "${OPENHAB_URL}" && \
unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" && \
rm /tmp/openhab.zip && \
mkdir -p "${OPENHAB_HOME}/dist" && \
cp -a "${OPENHAB_HOME}/configurations" "${OPENHAB_HOME}/dist" && \
echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc
EOI
}
# Install openHAB 2.x
print_openhab_install_oh2() {
cat >> $1 <<-'EOI'
# Install openHAB
# Set permissions for openHAB. Export TERM variable. See issue #30 for details!
RUN wget -nv -O /tmp/openhab.zip "${OPENHAB_URL}" && \
unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \
rm /tmp/openhab.zip && \
if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \
if [ ! -f "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" ]; then wget -nv -O "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" "https://raw.githubusercontent.com/openhab/openhab-distro/2.4.0/distributions/openhab/src/main/resources/bin/userdata_sysfiles.lst"; fi && \
mkdir -p "${OPENHAB_LOGDIR}" && \
touch "${OPENHAB_LOGDIR}/openhab.log" && \
mkdir -p "${OPENHAB_HOME}/dist" && \
cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \
echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc
COPY update.sh ${OPENHAB_HOME}/runtime/bin/update
RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update
EOI
}
# Add volumes for openHAB 1.x
print_volumes_oh1() {
cat >> $1 <<-'EOI'
# Expose volume with configuration and userdata dir
VOLUME ${OPENHAB_HOME}/configurations ${OPENHAB_HOME}/addons
EOI
}
# Add volumes for openHAB 2.x
print_volumes_oh2() {
cat >> $1 <<-'EOI'
# Expose volume with configuration and userdata dir
VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons
EOI
}
print_expose_ports() {
case $version in
1.*)
expose_comment="Expose HTTP and HTTPS ports"
expose_ports="8080 8443"
;;
2.0.0|2.1.0)
expose_comment="Expose HTTP, HTTPS and Console ports"
expose_ports="8080 8443 8101"
;;
2.*|3.*)
expose_comment="Expose HTTP, HTTPS, Console and LSP ports"
expose_ports="8080 8443 8101 5007"
;;
*)
expose_comment="Error"
expose_ports="error"
;;
esac
cat >> $1 <<-EOI
# $expose_comment
EXPOSE $expose_ports
EOI
}
# Set working directory and entrypoint
print_entrypoint() {
cat >> $1 <<-'EOI'
# Set working directory and entrypoint
WORKDIR ${OPENHAB_HOME}
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# Execute command
EOI
}
# Set command
print_command() {
case $base in
alpine)
cat >> $1 <<-'EOI'
CMD ["su-exec", "openhab", "tini", "-s", "./start.sh"]
EOI
;;
debian)
cat >> $1 <<-'EOI'
CMD ["gosu", "openhab", "tini", "-s", "./start.sh"]
EOI
;;
*)
cat >> $1 <<-'EOI'
CMD ["./start.sh"]
EOI
;;
esac
}
generate_docker_files() {
# Generate Dockerfile
file="$version/$base/Dockerfile"
mkdir -p $(dirname $file) 2>/dev/null
echo -n "Writing $file... "
print_header $file;
print_baseimage $file;
print_basemetadata $file;
case $base in
alpine)
print_basepackages_alpine $file;
print_java_alpine $file;
;;
debian)
print_basepackages_debian $file;
print_java_debian $file;
;;
esac
case $version in
1.*)
print_openhab_install_oh1 $file;
print_volumes_oh1 $file
;;
2.*|3.*)
print_openhab_install_oh2 $file;
print_volumes_oh2 $file
;;
esac
print_expose_ports $file
print_entrypoint $file
print_command $file
echo "done"
}
# Remove previously generated container files
rm -rf ./1.* ./2.* ./3.*
# Generate new container files
for version in $(build_versions)
do
for base in $(bases)
do
# Generate Dockerfile per architecture
generate_docker_files
# Copy base specific entrypoint.sh
case $base in
alpine) cp "entrypoint-alpine.sh" "$version/$base/entrypoint.sh";;
debian) cp "entrypoint-debian.sh" "$version/$base/entrypoint.sh";;
esac
# Copy version specific update script
case $version in
2.*|3.*) cp "openhab2-update.sh" "$version/$base/update.sh";;
esac
done
done