-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdocker.sh
executable file
·480 lines (397 loc) · 12.8 KB
/
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
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#!/bin/bash
# shellcheck disable=SC2155
# This script is primarily for checking and handling releases. If you are
# looking to build ECWolf then you should build manually.
# This script takes a single argument which specifies which configuration to
# use. Running with no arguments will list out config names, but you can also
# look at the bottom of this script.
# Anything that the configs write out to /results (logs, build artifacts) will
# be copied back to the hosts results directory.
# Infrastructure ---------------------------------------------------------------
# Build our clean environment if we don't have one built already
check_environment() {
declare -n Config=$1
shift
declare DockerTag="${Config[dockerimage]}:${Config[dockertag]}"
if ! docker image inspect "$DockerTag" &> /dev/null; then
declare Dockerfile=$(mktemp -p .)
"${Config[dockerfile]}" > "${Dockerfile}"
docker build -t "$DockerTag" -f "$Dockerfile" . || {
rm "$Dockerfile"
echo 'Failed to create build environment' >&2
return 1
}
rm "$Dockerfile"
fi
return 0
}
# Recursively build docker environments
check_environment_prereq() {
declare ConfigName=$1
shift
[[ $ConfigName ]] || return 0
declare -n Config=$ConfigName
if [[ ${Config[prereq]} ]]; then
check_environment_prereq "${Config[prereq]}" || return
fi
check_environment "$ConfigName"
}
run_config() {
declare ConfigName=$1
shift
declare -n Config=$ConfigName
check_environment_prereq "$ConfigName" || return
declare Container
Container=$(docker create -i -v "$(pwd):/mnt:ro" "${Config[dockerimage]}:${Config[dockertag]}" bash -s --) || return
{
declare -fx
echo "\"${Config[entrypoint]}\" \"\$@\""
} | docker start -i "$Container"
declare Ret=$?
# Copy out any logs or build artifacts we might be interested in
mkdir -p "results/${ConfigName}"
docker cp "$Container:/results/." "results/${ConfigName}"
docker rm "$Container" > /dev/null
return "$Ret"
}
main() {
declare SelectedConfig=$1
shift
declare ConfigName
# List out configs
if [[ -z $SelectedConfig ]]; then
declare -A ConfigGroups=([all]=1)
for ConfigName in "${ConfigList[@]}"; do
declare -n Config=$ConfigName
ConfigGroups[${Config[type]}]=1
done
echo 'Config list:'
printf '%s\n' "${ConfigList[@]}" | sort
echo
echo 'Config groups:'
printf '%s\n' "${!ConfigGroups[@]}" | sort
return 0
fi
declare ConfigName
if [[ -v "$SelectedConfig""[@]" ]]; then
# Full name
ConfigName=$SelectedConfig
else
# Short name
ConfigName=${ConfigList[$SelectedConfig]}
fi
# Run by type
if [[ -z $ConfigName ]]; then
declare -a FailedCfgs=()
for ConfigName in "${ConfigList[@]}"; do
declare -n Config=$ConfigName
if [[ $SelectedConfig == "${Config[type]}" || $SelectedConfig == 'all' ]]; then
run_config "${ConfigName}" || FailedCfgs+=("$ConfigName")
fi
done
if (( ${#FailedCfgs} > 0 )); then
echo 'Failed configs:'
printf '%s\n' "${FailedCfgs[@]}"
return 1
else
echo 'All configs passed!'
return 0
fi
fi
# Run the specific config
run_config "${ConfigName}"
}
# Minimum supported configuration ----------------------------------------------
dockerfile_ubuntu_minimum() {
cat <<-'EOF'
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install g++ cmake git pax-utils lintian sudo \
libsdl1.2-dev libsdl-net1.2-dev \
libsdl2-dev libsdl2-net-dev \
libflac-dev libogg-dev libvorbis-dev libopus-dev libopusfile-dev libmodplug-dev libfluidsynth-dev \
zlib1g-dev libbz2-dev libgtk-3-dev -y && \
useradd -rm ecwolf && \
echo "ecwolf ALL=(ALL) NOPASSWD: /usr/bin/make install" >> /etc/sudoers && \
mkdir /home/ecwolf/results && \
chown ecwolf:ecwolf /home/ecwolf/results && \
ln -s /home/ecwolf/results /results
USER ecwolf
EOF
}
dockerfile_ubuntu_minimum_i386() {
dockerfile_ubuntu_minimum | sed 's,FROM ,FROM i386/,'
}
# Performs a build of ECWolf. Extra CMake args can be passed as args.
build_ecwolf() {
declare SrcDir=/mnt
cd ~ || return
# Check for previous invocation
if [[ -d build ]]; then
rm -rf build
fi
# Only matters on CMake 3.5+
export CLICOLOR_FORCE=1
mkdir build &&
cd build &&
cmake "$SrcDir" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr "$@" &&
touch install_manifest.txt && # Prevent root from owning this file
make -j "$(nproc)" || return
}
export -f build_ecwolf
test_build_ecwolf_cfg() {
declare BuildCfg=$1
shift
build_ecwolf "$@" 2>&1 | tee "/results/buildlog-$BuildCfg.log"
(( PIPESTATUS[0] == 0 )) || return "${PIPESTATUS[0]}"
cd ~/build &&
sudo make install 2>&1 | tee "/results/installlog-$BuildCfg.log"
(( PIPESTATUS[0] == 0 )) || return "${PIPESTATUS[0]}"
lddtree /usr/games/ecwolf | tee "/results/lddtree-$BuildCfg.txt"
}
export -f test_build_ecwolf_cfg
# Tests that supported configs compile and install
test_build_ecwolf() {
declare -a FailedCfgs=()
test_build_ecwolf_cfg SDL2 || FailedCfgs+=(SDL2)
test_build_ecwolf_cfg SDL1 -DFORCE_SDL12=ON -DINTERNAL_SDL_MIXER=ON || FailedCfgs+=(SDL1)
if (( ${#FailedCfgs} > 0 )); then
echo 'Failed builds:'
printf '%s\n' "${FailedCfgs[@]}"
return 1
else
echo 'All passed!'
fi
}
export -f test_build_ecwolf
# shellcheck disable=SC2034
declare -A ConfigUbuntuMinimum=(
[dockerfile]=dockerfile_ubuntu_minimum
[dockerimage]='ecwolf-ubuntu'
[dockertag]=4
[entrypoint]=test_build_ecwolf
[prereq]=''
[type]=test
)
# shellcheck disable=SC2034
declare -A ConfigUbuntuMinimumI386=(
[dockerfile]=dockerfile_ubuntu_minimum_i386
[dockerimage]='i386/ecwolf-ubuntu'
[dockertag]=4
[entrypoint]=test_build_ecwolf
[prereq]=''
[type]=test
)
# Ubuntu packaging -------------------------------------------------------------
dockerfile_ubuntu_package() {
echo "FROM ${ConfigUbuntuMinimum[dockerimage]}:${ConfigUbuntuMinimum[dockertag]}"
# Packaging requires CMake 3.11 or newer
cat <<-'EOF'
RUN cd ~ && \
curl https://cmake.org/files/v3.15/cmake-3.15.3.tar.gz | tar xz && \
cd cmake-3.15.3 && \
./configure --parallel="$(nproc)" && \
make -j "$(nproc)" && \
sudo make install && \
cd .. && \
rm -rf cmake-3.15.3
EOF
}
dockerfile_ubuntu_package_i386() {
dockerfile_ubuntu_package | sed 's,FROM ,FROM i386/,'
}
package_ecwolf() {
{
build_ecwolf &&
make package &&
lintian --suppress-tags embedded-library ecwolf_*.deb &&
cp ecwolf_*.deb /results/
} 2>&1 | tee '/results/build.log'
return "${PIPESTATUS[0]}"
}
export -f package_ecwolf
# shellcheck disable=SC2034
declare -A ConfigUbuntuPackage=(
[dockerfile]=dockerfile_ubuntu_package
[dockerimage]='ecwolf-ubuntu-package'
[dockertag]=4
[entrypoint]=package_ecwolf
[prereq]=ConfigUbuntuMinimum
[type]=build
)
# shellcheck disable=SC2034
declare -A ConfigUbuntuPackageI386=(
[dockerfile]=dockerfile_ubuntu_package_i386
[dockerimage]='i386/ecwolf-ubuntu-package'
[dockertag]=4
[entrypoint]=package_ecwolf
[prereq]=ConfigUbuntuMinimumI386
[type]=build
)
# Clang ------------------------------------------------------------------------
dockerfile_clang() {
cat <<-'EOF'
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install clang-4.0 libc++-dev cmake git pax-utils lintian sudo \
libsdl2-dev libsdl2-net-dev \
libflac-dev libogg-dev libvorbis-dev libopus-dev libopusfile-dev libmodplug-dev libfluidsynth-dev \
zlib1g-dev libbz2-dev libgtk-3-dev -y && \
useradd -rm ecwolf && \
echo "ecwolf ALL=(ALL) NOPASSWD: /usr/bin/make install" >> /etc/sudoers && \
mkdir /home/ecwolf/results && \
chown ecwolf:ecwolf /home/ecwolf/results && \
ln -s /home/ecwolf/results /results
USER ecwolf
EOF
}
# Test that ECWolf is buildable with Clang and libc++
clang_build_ecwolf() {
CC=clang-4.0 CXX=clang++-4.0 build_ecwolf -DCMAKE_CXX_FLAGS="-stdlib=libc++" 2>&1 | tee "/results/buildlog.log"
(( PIPESTATUS[0] == 0 )) || return "${PIPESTATUS[0]}"
cd ~/build &&
sudo make install 2>&1 | tee "/results/installlog.log"
(( PIPESTATUS[0] == 0 )) || return "${PIPESTATUS[0]}"
lddtree /usr/games/ecwolf | tee "/results/lddtree.txt"
}
export -f clang_build_ecwolf
# shellcheck disable=SC2034
declare -A ConfigClang=(
[dockerfile]=dockerfile_clang
[dockerimage]='ecwolf-clang'
[dockertag]=4
[entrypoint]=clang_build_ecwolf
[prereq]=''
[type]=test
)
# Ubuntu MinGW-w64 -------------------------------------------------------------
dockerfile_mingw() {
cat <<-'EOF'
FROM ubuntu:18.04
RUN apt-get update && \
apt-get install g++ cmake git g++-mingw-w64-i686 g++-mingw-w64-x86-64 \
libsdl2-dev libsdl2-mixer-dev libsdl2-net-dev zlib1g-dev libbz2-dev libjpeg-turbo8-dev -y && \
useradd -rm ecwolf && \
echo "ecwolf ALL=(ALL) NOPASSWD: /usr/bin/make install" >> /etc/sudoers && \
mkdir /home/ecwolf/results && \
chown ecwolf:ecwolf /home/ecwolf/results && \
ln -s /home/ecwolf/results /results
USER ecwolf
EOF
}
build_mingw() {
declare SrcDir=/mnt
# Build native tools
build_ecwolf || return
declare Arch
for Arch in i686 x86_64; do
{
mkdir ~/build-mgw-"$Arch" &&
cd ~/build-mgw-"$Arch" &&
CXX="$Arch-w64-mingw32-g++-posix" CC="$Arch-w64-mingw32-gcc-posix" cmake "$SrcDir" \
-DCMAKE_BUILD_TYPE=Release \
-DFORCE_CROSSCOMPILE=ON \
-DIMPORT_EXECUTABLES=../build/ImportExecutables.cmake \
-DINTERNAL_SDL{_MIXER,_MIXER_CODECS,_NET}=ON \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_FIND_ROOT_PATH="/usr/$Arch-w64-mingw32" \
-DCMAKE_RC_COMPILER="$Arch-w64-mingw32-windres" \
-DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lpthread -Wl,-Bdynamic,--no-whole-archive" &&
make -j "$(nproc)" -O &&
make package &&
cp ecwolf-*.zip /results/
} 2>&1 | tee "/results/build-$Arch.log"
(( PIPESTATUS[0] == 0 )) || return "${PIPESTATUS[0]}"
done
}
export -f build_mingw
# shellcheck disable=SC2034
declare -A ConfigMinGW=(
[dockerfile]=dockerfile_mingw
[dockerimage]='ecwolf-mingw'
[dockertag]=2
[entrypoint]=build_mingw
[prereq]=''
[type]=build
)
# Ubuntu Android ---------------------------------------------------------------
dockerfile_android() {
cat <<-'EOF'
FROM ubuntu:18.04
RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get install libc6:i386 libstdc++6:i386 zlib1g:i386 \
g++ cmake git openjdk-8-jdk-headless p7zip-full curl \
libsdl2-dev libsdl2-mixer-dev libsdl2-net-dev zlib1g-dev libbz2-dev libjpeg-turbo8-dev -y && \
useradd -rm ecwolf && \
echo "ecwolf ALL=(ALL) NOPASSWD: /usr/bin/make install" >> /etc/sudoers && \
mkdir /home/ecwolf/results && \
chown ecwolf:ecwolf /home/ecwolf/results && \
ln -s /home/ecwolf/results /results && \
mkdir sdk && \
cd sdk && \
curl https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip -o sdk-tools-linux.zip && \
curl https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip -o android-ndk.zip && \
7za x sdk-tools-linux.zip && \
7za x android-ndk.zip && \
rm sdk-tools-linux.zip android-ndk.zip && \
mv android-ndk-r14b ndk-bundle && \
sed -i 's/__USE_FILE_OFFSET64)/__USE_FILE_OFFSET64) \&\& __ANDROID_API__ >= 24/' /sdk/ndk-bundle/sysroot/usr/include/stdio.h && \
yes | tools/bin/sdkmanager --licenses && \
tools/bin/sdkmanager 'platforms;android-26' 'build-tools;19.1.0' 'extras;android;m2repository' && \
keytool -genkey -keystore untrusted.keystore -storepass untrusted -keypass untrusted -alias untrusted -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=Untrusted,OU=Untrusted,O=Untrusted,L=Untrusted,S=Untrusted,C=US" -noprompt
USER ecwolf
EOF
}
build_android() {
declare SrcDir=/mnt
# Build native tools
build_ecwolf || return
declare Arch
for Arch in x86 x86_64 armeabi-v7a arm64-v8a; do
{
declare NDKVersion=12
[[ $Arch =~ 64 ]] && NDKVersion=21
mkdir ~/build-mgw-"$Arch" &&
cd ~/build-mgw-"$Arch" &&
cmake "$SrcDir" \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION="$NDKVersion" \
-DCMAKE_ANDROID_NDK=/sdk/ndk-bundle \
-DCMAKE_ANDROID_ARCH_ABI="$Arch" \
-DCMAKE_BUILD_TYPE=Release \
-DFORCE_CROSSCOMPILE=ON \
-DIMPORT_EXECUTABLES=~/build/ImportExecutables.cmake \
-DANDROID_SDK=/sdk/platforms/android-26 \
-DANDROID_SDK_TOOLS=/sdk/build-tools/19.1.0 \
-DANDROID_SIGN_KEYNAME=untrusted \
-DANDROID_SIGN_KEYSTORE=/sdk/untrusted.keystore \
-DANDROID_SIGN_STOREPASS=untrusted \
-DINTERNAL_SDL{,_MIXER,_MIXER_CODECS,_NET}=ON
make -j "$(nproc)" &&
cp ecwolf.apk /results/ecwolf-"$Arch".apk
} 2>&1 | tee "/results/build-$Arch.log"
(( PIPESTATUS[0] == 0 )) || return "${PIPESTATUS[0]}"
done
}
export -f build_android
# shellcheck disable=SC2034
declare -A ConfigAndroid=(
[dockerfile]=dockerfile_android
[dockerimage]='ecwolf-android'
[dockertag]=3
[entrypoint]=build_android
[prereq]=''
[type]=build
)
# ------------------------------------------------------------------------------
declare -A ConfigList=(
[android]=ConfigAndroid
[clang]=ConfigClang
[mingw]=ConfigMinGW
[ubuntumin]=ConfigUbuntuMinimum
[ubuntumini386]=ConfigUbuntuMinimumI386
[ubuntupkg]=ConfigUbuntuPackage
[ubuntupkgi386]=ConfigUbuntuPackageI386
)
main "$@"; exit