forked from docker-library/php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·217 lines (193 loc) · 5.87 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
209
210
211
212
213
214
215
216
217
#!/bin/bash
set -e
# https://secure.php.net/gpg-keys.php
declare -A gpgKeys=(
# https://wiki.php.net/todo/php72
# pollita & remi
# https://secure.php.net/downloads.php#gpg-7.2
# https://secure.php.net/gpg-keys.php#gpg-7.2
[7.2]='1729F83938DA44E27BA0F4D3DBDB397470D12172 B1B44D8F021E4E2D6021E995DC9FF8D3EE5AF27F'
# https://wiki.php.net/todo/php71
# davey & krakjoe
# https://secure.php.net/downloads.php#gpg-7.1
# https://secure.php.net/gpg-keys.php#gpg-7.1
[7.1]='A917B1ECDA84AEC2B568FED6F50ABC807BD5DCD0 528995BFEDFBA7191D46839EF9BA0ADA31CBD89E'
# https://wiki.php.net/todo/php70
# ab & tyrael
# https://secure.php.net/downloads.php#gpg-7.0
# https://secure.php.net/gpg-keys.php#gpg-7.0
[7.0]='1A4E8B7277C42E53DBA9C7B9BCAA30EA9C0D5763 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3'
# https://wiki.php.net/todo/php56
# jpauli & tyrael
# https://secure.php.net/downloads.php#gpg-5.6
# https://secure.php.net/gpg-keys.php#gpg-5.6
[5.6]='0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3'
)
# see https://secure.php.net/downloads.php
defaultDebianSuite='stretch-slim'
declare -A debianSuites=(
[5.6]='jessie'
[7.0]='jessie'
[7.1]='jessie'
)
defaultAlpineVersion='3.6'
declare -A alpineVersions=(
[5.6]='3.4'
[7.0]='3.4'
[7.1]='3.4'
)
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
generated_warning() {
cat <<-EOH
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
EOH
}
travisEnv=
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
# scrape the relevant API based on whether we're looking for pre-releases
apiUrl="https://secure.php.net/releases/index.php?json&max=100&version=${rcVersion%%.*}"
apiJqExpr='
(keys[] | select(startswith("'"$rcVersion"'."))) as $version
| [ $version, (
.[$version].source[]
| select(.filename | endswith(".xz"))
|
"https://secure.php.net/get/" + .filename + "/from/this/mirror",
"https://secure.php.net/get/" + .filename + ".asc/from/this/mirror",
.sha256 // "",
.md5 // ""
) ]
'
if [ "$rcVersion" != "$version" ]; then
apiUrl='https://qa.php.net/api.php?type=qa-releases&format=json'
apiJqExpr='
.releases[]
| select(.version | startswith("'"$rcVersion"'."))
| [
.version,
.files.xz.path // "",
"",
.files.xz.sha256 // "",
.files.xz.md5 // ""
]
'
fi
IFS=$'\n'
possibles=( $(
curl -fsSL "$apiUrl" \
| jq --raw-output "$apiJqExpr | @sh" \
| sort -rV
) )
unset IFS
if [ "${#possibles[@]}" -eq 0 ]; then
echo >&2
echo >&2 "error: unable to determine available releases of $version"
echo >&2
exit 1
fi
# format of "possibles" array entries is "VERSION URL.TAR.XZ URL.TAR.XZ.ASC SHA256 MD5" (each value shell quoted)
# see the "apiJqExpr" values above for more details
eval "possi=( ${possibles[0]} )"
fullVersion="${possi[0]}"
url="${possi[1]}"
ascUrl="${possi[2]}"
sha256="${possi[3]}"
md5="${possi[4]}"
gpgKey="${gpgKeys[$rcVersion]}"
if [ -z "$gpgKey" ]; then
echo >&2 "ERROR: missing GPG key fingerprint for $version"
echo >&2 " try looking on https://secure.php.net/downloads.php#gpg-$version"
exit 1
fi
# if we don't have a .asc URL, let's see if we can figure one out :)
if [ -z "$ascUrl" ] && wget -q --spider "$url.asc"; then
ascUrl="$url.asc"
fi
dockerfiles=()
{ generated_warning; cat Dockerfile-debian.template; } > "$version/Dockerfile"
cp -v \
docker-php-entrypoint \
docker-php-ext-* \
docker-php-source \
"$version/"
dockerfiles+=( "$version/Dockerfile" )
if [ -d "$version/alpine" ]; then
{ generated_warning; cat Dockerfile-alpine.template; } > "$version/alpine/Dockerfile"
cp -v \
docker-php-entrypoint \
docker-php-ext-* \
docker-php-source \
"$version/alpine/"
dockerfiles+=( "$version/alpine/Dockerfile" )
fi
for target in \
apache \
fpm fpm/alpine \
zts zts/alpine \
; do
[ -d "$version/$target" ] || continue
base="$version/Dockerfile"
variant="${target%%/*}"
if [ "$target" != "$variant" ]; then
variantVariant="${target#$variant/}"
[ -d "$version/$variantVariant" ] || continue
base="$version/$variantVariant/Dockerfile"
fi
echo "Generating $version/$target/Dockerfile from $base + $variant-Dockerfile-block-*"
awk '
$1 == "##</autogenerated>##" { ia = 0 }
!ia { print }
$1 == "##<autogenerated>##" { ia = 1; ab++; ac = 0 }
ia { ac++ }
ia && ac == 1 { system("cat '$variant'-Dockerfile-block-" ab) }
' "$base" > "$version/$target/Dockerfile"
cp -v \
docker-php-entrypoint \
docker-php-ext-* \
docker-php-source \
"$version/$target/"
dockerfiles+=( "$version/$target/Dockerfile" )
done
debianSuite="${debianSuites[$rcVersion]:-$defaultDebianSuite}"
alpineVersion="${alpineVersions[$rcVersion]:-$defaultAlpineVersion}"
(
set -x
sed -ri \
-e 's!%%PHP_VERSION%%!'"$fullVersion"'!' \
-e 's!%%GPG_KEYS%%!'"$gpgKey"'!' \
-e 's!%%PHP_URL%%!'"$url"'!' \
-e 's!%%PHP_ASC_URL%%!'"$ascUrl"'!' \
-e 's!%%PHP_SHA256%%!'"$sha256"'!' \
-e 's!%%PHP_MD5%%!'"$md5"'!' \
-e 's!%%DEBIAN_SUITE%%!'"$debianSuite"'!' \
-e 's!%%ALPINE_VERSION%%!'"$alpineVersion"'!' \
"${dockerfiles[@]}"
)
# update entrypoint commands
for dockerfile in "${dockerfiles[@]}"; do
cmd="$(awk '$1 == "CMD" { $1 = ""; print }' "$dockerfile" | tail -1 | jq --raw-output '.[0]')"
entrypoint="$(dirname "$dockerfile")/docker-php-entrypoint"
sed -i 's! php ! '"$cmd"' !g' "$entrypoint"
done
newTravisEnv=
for dockerfile in "${dockerfiles[@]}"; do
dir="${dockerfile%Dockerfile}"
dir="${dir%/}"
variant="${dir#$version}"
variant="${variant#/}"
newTravisEnv+='\n - VERSION='"$version VARIANT=$variant"
done
travisEnv="$newTravisEnv$travisEnv"
done
travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
echo "$travis" > .travis.yml