forked from docker-library/php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·202 lines (171 loc) · 5.3 KB
/
update.sh
File metadata and controls
executable file
·202 lines (171 loc) · 5.3 KB
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
#!/bin/bash
set -e
declare -A aliases=(
[5.6]='5'
[7.4]='7'
[8.0]='8 latest'
)
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=("$@")
if [ ${#versions[@]} -eq 0 ]; then
versions=(*/)
# exclude vendor directory
tmp=()
for value in "${versions[@]}"; do
if [ "$value" == "vendor/" ]; then continue; fi
tmp+=($value)
done
versions=("${tmp[@]}")
unset tmp
fi
versions=("${versions[@]%/}")
generated_warning() {
cat <<-EOH
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
EOH
}
# Make version number comparable
vc() { echo "$@" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'; }
# prints "$2$1$3$1...$N"
join() {
local sep="$1"
shift
local out
printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
}
# Parameters: version, targetDir, tags...
copyFiles() {
_version=$1
_dir=$2
cp -v \
docker-php-entrypoint \
docker-php-ext-* \
docker-php-source \
"$_dir/"
if [ "$_dir" == "$_version/apache" ]; then
cp -v apache2-foreground "$_dir/"
fi
# Patches
mkdir -p "$_dir/patches"
if [ $(vc $_version) -lt $(vc 5.3) ]; then
cp -v libxml29_compat.patch "$_dir/patches/"
else
touch "$_dir/patches/.gitkeep"
fi
# Hooks
shift 2
echo "$@ ($#)"
rm -rf "$_dir/hooks"
if [ $# -gt 1 ]; then
ALTERNATIVE_TAGS=$(join ',' "$@")
mkdir -p "$_dir/hooks"
cp -v post_push "$_dir/hooks/"
sed -ri \
-e 's!%%ALTERNATIVE_TAGS%%!'"$ALTERNATIVE_TAGS"'!' \
"$_dir/hooks/post_push"
fi
}
travisEnv=
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
fullVersion=$(vendor/bin/php-versions version "$rcVersion")
basename=$(vendor/bin/php-versions download-url "$rcVersion" --format xz)
url=$(vendor/bin/php-versions download-url "$rcVersion" --format xz --url)
ascUrl=$(vendor/bin/php-versions download-url "$rcVersion" --format xz --asc --url)
sha256=$(vendor/bin/php-versions hash "$rcVersion" --format xz --type sha256)
md5=$(vendor/bin/php-versions hash "$rcVersion" --format xz --type md5)
gpgKey=$(vendor/bin/php-versions gpg "$rcVersion")
if [ -z "$gpgKey" ]; then
gpgKey='""'
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
# Temporarily disable GPG check due to problems with keyserver response time
ascUrl=
dockerfiles=()
{
generated_warning
cat Dockerfile-debian.template
} >"$version/Dockerfile"
versionAliases=(
$version
${aliases[$version]:-}
)
variant='cli'
variantAliases=("${versionAliases[@]/%/-$variant}")
variantAliases=("${variantAliases[@]//latest-/}")
variantAliases+=("${versionAliases[@]}")
copyFiles "$version" "$version" "${variantAliases[@]}"
dockerfiles+=("$version/Dockerfile")
if [ -d "$version/alpine" ]; then
{
generated_warning
cat Dockerfile-alpine.template
} >"$version/alpine/Dockerfile"
slash='/'
variantAliases=("${versionAliases[@]/%/-alpine}")
variantAliases=("${variantAliases[@]//latest-/}")
copyFiles "$version" "$version/alpine" "${variantAliases[@]}"
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"
slash='/'
variantAliases=("${versionAliases[@]/%/-${target//$slash/-}}")
variantAliases=("${variantAliases[@]//latest-/}")
copyFiles "$version" "$version/$target" "${variantAliases[@]}"
dockerfiles+=("$version/$target/Dockerfile")
done
(
set -x
sed -ri -e 's!%%PHP_VERSION%%!'"$fullVersion"'!' "${dockerfiles[@]}"
sed -ri -e 's!%%GPG_KEYS%%!'"$gpgKey"'!' "${dockerfiles[@]}"
sed -ri -e 's!%%PHP_FILE%%!'"$basename"'!' "${dockerfiles[@]}"
sed -ri -e 's!%%PHP_URL%%!'"$url"'!' "${dockerfiles[@]}"
sed -ri -e 's!%%PHP_ASC_URL%%!'"$ascUrl"'!' "${dockerfiles[@]}"
sed -ri -e 's!%%PHP_SHA256%%!'"$sha256"'!' "${dockerfiles[@]}"
sed -ri -e 's!%%PHP_MD5%%!'"$md5"'!' "${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