-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate.sh
executable file
·181 lines (146 loc) · 5.05 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
#!/bin/bash
set -eo pipefail
# XXX No phar asset on 2.4.1
#cliVersion="$(
# git ls-remote --tags 'https://github.com/wp-cli/wp-cli.git' \
# | sed -r 's!^[^\t]+\trefs/tags/v([^^]+).*!\1!g' \
# | tail -1
#)"
cliVersion=2.4.0
cliSha512="$(curl -fsSL "https://github.com/wp-cli/wp-cli/releases/download/v${cliVersion}/wp-cli-${cliVersion}.phar.sha512")"
declare -A conf=(
[apache]=''
[fpm]='nginx'
[fpm-alpine]='nginx'
)
declare -A compose=(
[apache]='apache'
[fpm]='fpm'
[fpm-alpine]='fpm'
)
declare -A cmd=(
[apache]='apache2-foreground'
[fpm]='php-fpm'
[fpm-alpine]='php-fpm'
)
declare -A base=(
[apache]='debian'
[fpm]='debian'
[fpm-alpine]='alpine'
)
declare -A extras=(
[apache]='a2enmod headers remoteip ;\\\n {\\\n echo RemoteIPHeader X-Real-IP ;\\\n echo RemoteIPTrustedProxy 10.0.0.0/8 ;\\\n echo RemoteIPTrustedProxy 172.16.0.0/12 ;\\\n echo RemoteIPTrustedProxy 192.168.0.0/16 ;\\\n } > /etc/apache2/conf-available/remoteip.conf;\\\n a2enconf remoteip;'
[fpm]=''
[fpm-alpine]=''
)
# https://pecl.php.net/package/APCu
# https://pecl.php.net/package/memcached
declare -A pecl_versions=(
[APCu]='5.1.18'
[memcached]='3.1.5'
)
variants=(
apache
fpm
fpm-alpine
)
min_version='5.5'
dockerLatest='5.8'
dockerDefaultVariant='apache'
# version_greater_or_equal A B returns whether A >= B
function version_greater_or_equal() {
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" || "$1" == "$2" ]];
}
php_versions=( "7.4" )
dockerRepo="monogramm/docker-wordpress"
echo "retrieve automatically the latest versions..."
latests=( $( curl -fsSL 'https://api.github.com/repos/WordPress/WordPress/tags' |tac|tac| \
grep -oE '[[:digit:]]+\.[[:digit:]]+' | \
sort -urV ) )
# Remove existing images
echo "reset docker images"
rm -rf ./images/*
echo "update docker images"
readmeTags=
githubEnv=
travisEnv=
for latest in "${latests[@]}"; do
version=$(echo "$latest" | cut -d. -f1-2)
# Only add versions >= "$min_version"
if version_greater_or_equal "$version" "$min_version"; then
if [ ! -d "images/$version" ]; then
# Add GitHub Actions env var
githubEnv="'$version', $githubEnv"
fi
for php_version in "${php_versions[@]}"; do
for variant in "${variants[@]}"; do
echo "updating $latest [$version] php$php_version-$variant"
# Create the version+php_version+variant directory with a Dockerfile.
dir="images/$version/php$php_version-$variant"
if [ -d "$dir" ]; then
continue
fi
mkdir -p "$dir"
template="Dockerfile.${base[$variant]}.template"
cp "template/$template" "$dir/Dockerfile"
cp -r "template/hooks/" "$dir/"
cp -r "template/test/" "$dir/"
cp "template/.env" "$dir/.env"
cp "template/.dockerignore" "$dir/.dockerignore"
cp "template/docker-compose.${compose[$variant]}.test.yml" "$dir/docker-compose.test.yml"
if [ -n "${conf[$variant]}" ] && [ -d "template/${conf[$variant]}" ]; then
cp -r "template/${conf[$variant]}" "$dir/${conf[$variant]}"
fi
# Replace the variables.
sed -ri -e '
s/%%PHP_VERSION%%/'"$php_version"'/g;
s/%%VARIANT%%/'"$variant"'/g;
s/%%VERSION%%/'"$latest"'/g;
s/%%CMD%%/'"${cmd[$variant]}"'/g;
s|%%VARIANT_EXTRAS%%|'"${extras[$variant]}"'|g;
s/%%APCU_VERSION%%/'"${pecl_versions[APCu]}"'/g;
s/%%MEMCACHED_VERSION%%/'"${pecl_versions[memcached]}"'/g;
s/%%WORDPRESS_CLI_VERSION%%/'"${cliVersion}"'/g;
s/%%WORDPRESS_CLI_SHA512%%/'"${cliSha512}"'/g;
' "$dir/Dockerfile"
sed -ri -e '
s|DOCKER_TAG=.*|DOCKER_TAG='"$version"'|g;
s|DOCKER_REPO=.*|DOCKER_REPO='"$dockerRepo"'|g;
' "$dir/hooks/run"
# Create a list of "alias" tags for DockerHub post_push
if [ "$latest" = "$dockerLatest" ]; then
if [ "$variant" = "$dockerDefaultVariant" ]; then
export DOCKER_TAGS="$latest-$variant $variant $latest latest "
else
export DOCKER_TAGS="$latest-$variant $variant "
fi
else
if [ "$variant" = "$dockerDefaultVariant" ]; then
export DOCKER_TAGS="$latest-$variant $latest "
else
export DOCKER_TAGS="$latest-$variant "
fi
fi
echo "${DOCKER_TAGS}" > "$dir/.dockertags"
# Add README.md tags
readmeTags="$readmeTags\n- \`$dir/Dockerfile\`: $(cat $dir/.dockertags)<!--+tags-->"
# Add Travis-CI env var
travisEnv='\n - VERSION='"$version"' PHP_VERSION='"$php_version"' VARIANT='"$variant$travisEnv"
if [[ $1 == 'build' ]]; then
tag="$version-$php_version-$variant"
echo "Build Dockerfile for ${tag}"
docker build -t "${dockerRepo}:${tag}" "$dir"
fi
done
done
fi
done
# update README.md
sed -i -e '/^- .*<!--+tags-->/d' README.md
readme="$(awk -v 'RS=\n\n' '$1 == "Tags:" { $0 = "Tags:'"$readmeTags"'" } { printf "%s%s", $0, RS }' README.md)"
echo "$readme" > README.md
# update .github workflows
sed -i -e "s|version: \[.*\]|version: [${githubEnv}]|g" .github/workflows/hooks.yml
# update .travis.yml
travis="$(awk -v 'RS=\n\n' '$1 == "env:" && $2 == "#" && $3 == "Environments" { $0 = "env: # Environments'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
echo "$travis" > .travis.yml