forked from nginxinc/docker-nginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·208 lines (179 loc) · 5.13 KB
/
update.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
#!/usr/bin/env bash
set -Eeuo pipefail
shopt -s nullglob
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
declare branches=(
"stable"
"mainline"
)
# Current nginx versions
# Remember to update pkgosschecksum when changing this.
declare -A nginx=(
[mainline]='1.25.4'
[stable]='1.24.0'
)
# Current njs versions
declare -A njs=(
[mainline]='0.8.3'
[stable]='0.8.0'
)
# Current package patchlevel version
# Remember to update pkgosschecksum when changing this.
declare -A pkg=(
[mainline]=1
[stable]=1
)
declare -A debian=(
[mainline]='bookworm'
[stable]='bullseye'
)
declare -A alpine=(
[mainline]='3.18'
[stable]='3.18'
)
# When we bump njs version in a stable release we don't move the tag in the
# mercurial repo. This setting allows us to specify a revision to check out
# when building alpine packages on architectures not supported by nginx.org
# Remember to update pkgosschecksum when changing this.
declare -A rev=(
[mainline]='${NGINX_VERSION}-${PKG_RELEASE}'
[stable]='e5d85b3424bb'
)
# Holds SHA512 checksum for the pkg-oss tarball produced by source code
# revision/tag in the previous block
# Used in alpine builds for architectures not packaged by nginx.org
declare -A pkgosschecksum=(
[mainline]='79bf214256bf55700c776a87abfc3cf542323a267d879e89110aa44b551d12f6df7d56676a68f255ebbb54275185980d1fa37075f000d98e0ecac28db9e89fe3'
[stable]='4f33347bf05e7d7dd42a52b6e7af7ec21e3ed71df05a8ec16dd1228425f04e4318d88b1340370ccb6ad02cde590fc102094ddffbb1fc86d2085295a43f02f67b'
)
get_packages() {
local distro="$1"
shift
local branch="$1"
shift
local perl=
local r=
local sep=
case "$distro:$branch" in
alpine*:*)
r="r"
sep="."
;;
debian*:*)
sep="+"
;;
esac
case "$distro" in
*-perl)
perl="nginx-module-perl"
;;
esac
echo -n ' \\\n'
case "$distro" in
*-slim)
for p in nginx; do
echo -n ' '"$p"'=${NGINX_VERSION}-'"$r"'${PKG_RELEASE} \\'
done
;;
*)
for p in nginx nginx-module-xslt nginx-module-geoip nginx-module-image-filter $perl; do
echo -n ' '"$p"'=${NGINX_VERSION}-'"$r"'${PKG_RELEASE} \\\n'
done
for p in nginx-module-njs; do
echo -n ' '"$p"'=${NGINX_VERSION}'"$sep"'${NJS_VERSION}-'"$r"'${PKG_RELEASE} \\'
done
;;
esac
}
get_packagerepo() {
local distro="${1%-perl}"
distro="${distro%-slim}"
shift
local branch="$1"
shift
[ "$branch" = "mainline" ] && branch="$branch/" || branch=""
echo "https://nginx.org/packages/${branch}${distro}/"
}
get_packagever() {
local distro="${1%-perl}"
shift
local branch="$1"
shift
local suffix=
[ "${distro}" = "debian" ] && suffix="~${debianver}"
echo ${pkg[$branch]}${suffix}
}
get_buildtarget() {
local distro="$1"
case "$distro" in
alpine-slim)
echo base
;;
alpine-perl)
echo module-perl
;;
alpine)
echo module-geoip module-image-filter module-njs module-xslt
;;
debian)
echo "\$nginxPackages"
;;
debian-perl)
echo "nginx-module-perl=\${NGINX_VERSION}-\${PKG_RELEASE}"
;;
esac
}
generated_warning() {
cat <<__EOF__
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
__EOF__
}
for branch in "${branches[@]}"; do
for variant in \
alpine{,-perl,-slim} \
debian{,-perl}; do
echo "$branch: $variant dockerfiles"
dir="$branch/$variant"
variant="$(basename "$variant")"
[ -d "$dir" ] || continue
template="Dockerfile-${variant}.template"
{
generated_warning
cat "$template"
} >"$dir/Dockerfile"
debianver="${debian[$branch]}"
alpinever="${alpine[$branch]}"
nginxver="${nginx[$branch]}"
njsver="${njs[${branch}]}"
revver="${rev[${branch}]}"
pkgosschecksumver="${pkgosschecksum[${branch}]}"
packagerepo=$(get_packagerepo "$variant" "$branch")
packages=$(get_packages "$variant" "$branch")
packagever=$(get_packagever "$variant" "$branch")
buildtarget=$(get_buildtarget "$variant")
sed -i.bak \
-e 's,%%ALPINE_VERSION%%,'"$alpinever"',' \
-e 's,%%DEBIAN_VERSION%%,'"$debianver"',' \
-e 's,%%NGINX_VERSION%%,'"$nginxver"',' \
-e 's,%%NJS_VERSION%%,'"$njsver"',' \
-e 's,%%PKG_RELEASE%%,'"$packagever"',' \
-e 's,%%PACKAGES%%,'"$packages"',' \
-e 's,%%PACKAGEREPO%%,'"$packagerepo"',' \
-e 's,%%REVISION%%,'"$revver"',' \
-e 's,%%PKGOSSCHECKSUM%%,'"$pkgosschecksumver"',' \
-e 's,%%BUILDTARGET%%,'"$buildtarget"',' \
"$dir/Dockerfile"
done
for variant in \
alpine-slim \
debian; do \
echo "$branch: $variant entrypoint scripts"
dir="$branch/$variant"
cp -a entrypoint/*.sh "$dir/"
cp -a entrypoint/*.envsh "$dir/"
done
done