-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·157 lines (125 loc) · 4.84 KB
/
build.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
#!/bin/bash
# Apache
# An Apache container with an improved configuration structure.
#
# Copyright (c) 2021 SGS Serious Gaming & Simulations GmbH
#
# This work is licensed under the terms of the MIT license.
# For a copy, see LICENSE file or <https://opensource.org/licenses/MIT>.
#
# SPDX-License-Identifier: MIT
# License-Filename: LICENSE
set -eu -o pipefail
export LC_ALL=C.UTF-8
shopt -s nullglob
[ -v CI_TOOLS ] && [ "$CI_TOOLS" == "SGSGermany" ] \
|| { echo "Invalid build environment: Environment variable 'CI_TOOLS' not set or invalid" >&2; exit 1; }
[ -v CI_TOOLS_PATH ] && [ -d "$CI_TOOLS_PATH" ] \
|| { echo "Invalid build environment: Environment variable 'CI_TOOLS_PATH' not set or invalid" >&2; exit 1; }
source "$CI_TOOLS_PATH/helper/common.sh.inc"
source "$CI_TOOLS_PATH/helper/common-traps.sh.inc"
source "$CI_TOOLS_PATH/helper/container.sh.inc"
source "$CI_TOOLS_PATH/helper/container-alpine.sh.inc"
source "$CI_TOOLS_PATH/helper/git.sh.inc"
BUILD_DIR="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
source "$BUILD_DIR/container.env"
readarray -t -d' ' TAGS < <(printf '%s' "$TAGS")
APACHE_MODULES=(
"mpm_event"
"authn_file"
"authn_core"
"authz_host"
"authz_groupfile"
"authz_user"
"authz_core"
"auth_basic"
"reqtimeout"
"mime"
"log_config"
"headers"
"http2"
"rewrite"
"setenvif"
"unixd"
"autoindex"
"dir"
"alias"
)
APACHE_CONFIGS=(
"charset"
"connection"
"errors"
"htaccess"
"lookups"
"security"
"ssl"
"ssl-ocsp-stapling"
"ssl-security"
)
git_clone "$MERGE_IMAGE_GIT_REPO" "$MERGE_IMAGE_GIT_REF" "$BUILD_DIR/vendor" "./vendor"
con_build --tag "$IMAGE-base" \
--from "$BASE_IMAGE" --check-from "$MERGE_IMAGE_BASE_IMAGE_PATTERN" \
"$BUILD_DIR/vendor/$MERGE_IMAGE_BUD_CONTEXT" "./vendor/$MERGE_IMAGE_BUD_CONTEXT"
echo + "CONTAINER=\"\$(buildah from $(quote "$IMAGE-base"))\"" >&2
CONTAINER="$(buildah from "$IMAGE-base")"
echo + "MOUNT=\"\$(buildah mount $(quote "$CONTAINER"))\"" >&2
MOUNT="$(buildah mount "$CONTAINER")"
user_add "$CONTAINER" apache2 65536 "/usr/local/apache2"
pkg_install "$CONTAINER" --virtual .apache-run-deps \
inotify-tools \
openssl
echo + "MIME_TMP_DIR=\"\$(mktemp -d)\"" >&2
MIME_TMP_DIR="$(mktemp -d)"
trap_exit rm -rf "$MIME_TMP_DIR"
echo + "cp -t '\$MIME_TMP_DIR/' …/usr/local/apache2/conf/{magic,mime.types}" >&2
cp -t "$MIME_TMP_DIR/" \
"$MOUNT/usr/local/apache2/conf/magic" \
"$MOUNT/usr/local/apache2/conf/mime.types"
echo + "rm -rf …/usr/local/apache2/conf" >&2
rm -rf "$MOUNT/usr/local/apache2/conf"
echo + "rm -rf …/usr/local/apache2/htdocs" >&2
rm -rf "$MOUNT/usr/local/apache2/htdocs"
echo + "rsync -v -rl --exclude .gitignore ./src/ …/" >&2
rsync -v -rl --exclude '.gitignore' "$BUILD_DIR/src/" "$MOUNT/"
echo + "rsync -v -rl '\$MIME_TMP_DIR/' …/etc/apache2/" >&2
rsync -v -rl "$MIME_TMP_DIR/" "$MOUNT/etc/apache2/"
for MODULE_PATH in "$MOUNT/usr/local/apache2/modules/mod_"*".so"; do
MODULE="$(basename "$MODULE_PATH" ".so")"
MODULE="${MODULE:4}"
echo + "echo \"LoadModule ${MODULE}_module /usr/local/apache2/modules/mod_$MODULE.so\"" \
"> $(quote "…/etc/apache2/mods-available/$MODULE.load")" >&2
echo "LoadModule ${MODULE}_module /usr/local/apache2/modules/mod_$MODULE.so" \
> "$MOUNT/etc/apache2/mods-available/$MODULE.load"
done
cmd buildah run "$CONTAINER" -- \
a2enmod "${APACHE_MODULES[@]}"
cmd buildah run "$CONTAINER" -- \
a2enconf "${APACHE_CONFIGS[@]}"
cleanup "$CONTAINER"
cmd buildah config \
--port "80/tcp" \
--port "443/tcp" \
"$CONTAINER"
cmd buildah config \
--volume "/etc/apache2/ssl" \
--volume "/var/log/apache2" \
--volume "/var/www" \
"$CONTAINER"
cmd buildah config \
--entrypoint '[ "/entrypoint.sh" ]' \
--cmd '[ "httpd-foreground" ]' \
"$CONTAINER"
echo + "APACHE_VERSION=\"\$(buildah run $CONTAINER -- /bin/sh -c 'echo \"\$HTTPD_VERSION\"')\"" >&2
APACHE_VERSION="$(buildah run "$CONTAINER" -- /bin/sh -c 'echo "$HTTPD_VERSION"')"
cmd buildah config \
--annotation org.opencontainers.image.title="Apache" \
--annotation org.opencontainers.image.description="An Apache container with an improved configuration structure." \
--annotation org.opencontainers.image.version="$APACHE_VERSION" \
--annotation org.opencontainers.image.url="https://github.com/SGSGermany/apache" \
--annotation org.opencontainers.image.authors="SGS Serious Gaming & Simulations GmbH" \
--annotation org.opencontainers.image.vendor="SGS Serious Gaming & Simulations GmbH" \
--annotation org.opencontainers.image.licenses="MIT" \
--annotation org.opencontainers.image.base.name="$BASE_IMAGE" \
--annotation org.opencontainers.image.base.digest="$(podman image inspect --format '{{.Digest}}' "$BASE_IMAGE")" \
"$CONTAINER"
con_commit "$CONTAINER" "$IMAGE" "${TAGS[@]}"