Skip to content

Commit fe3078d

Browse files
committed
Add initial jq-based templating engine
1 parent c3460db commit fe3078d

39 files changed

+3010
-426
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*/**/Dockerfile linguist-generated
2+
/*/**/docker-entrypoint.sh linguist-generated
3+
/Dockerfile.template linguist-language=Dockerfile
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Verify Templating
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
defaults:
8+
run:
9+
shell: 'bash -Eeuo pipefail -x {0}'
10+
11+
jobs:
12+
apply-templates:
13+
name: Check For Uncomitted Changes
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Apply Templates
18+
run: ./apply-templates.sh
19+
- name: Check Git Status
20+
run: |
21+
status="$(git status --short)"
22+
[ -z "$status" ]

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.jq-template.awk

Dockerfile-cli.template

-101
This file was deleted.

Dockerfile.template

+224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
FROM php:{{ env.phpVersion }}-{{ env.variant }}
2+
3+
{{ if env.version != "cli" then ( -}}
4+
# persistent dependencies
5+
{{ if env.variant | index("alpine") then ( -}}
6+
RUN apk add --no-cache \
7+
# in theory, docker-entrypoint.sh is POSIX-compliant, but priority is a working, consistent image
8+
bash \
9+
# BusyBox sed is not sufficient for some of our sed expressions
10+
sed \
11+
# Ghostscript is required for rendering PDF previews
12+
ghostscript \
13+
# Alpine package for "imagemagick" contains ~120 .so files, see: https://github.com/docker-library/wordpress/pull/497
14+
imagemagick
15+
{{ ) else ( -}}
16+
RUN set -eux; \
17+
apt-get update; \
18+
apt-get install -y --no-install-recommends \
19+
# Ghostscript is required for rendering PDF previews
20+
ghostscript \
21+
; \
22+
rm -rf /var/lib/apt/lists/*
23+
{{ ) end -}}
24+
{{ ) else ( -}}
25+
# install wp-cli dependencies
26+
RUN apk add --no-cache \
27+
# bash is needed for 'wp shell': https://github.com/wp-cli/shell-command/blob/b8dafcc2a2eba5732fdee70be077675a302848e9/src/WP_CLI/REPL.php#L104
28+
bash \
29+
less \
30+
mysql-client
31+
32+
RUN set -ex; \
33+
mkdir -p /var/www/html; \
34+
chown -R www-data:www-data /var/www/html
35+
WORKDIR /var/www/html
36+
{{ ) end -}}
37+
38+
# install the PHP extensions we need (https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions)
39+
RUN set -ex; \
40+
\
41+
{{ if env.variant | index("alpine") then ( -}}
42+
apk add --no-cache --virtual .build-deps \
43+
$PHPIZE_DEPS \
44+
freetype-dev \
45+
imagemagick-dev \
46+
libjpeg-turbo-dev \
47+
libpng-dev \
48+
libzip-dev \
49+
; \
50+
{{ ) else ( -}}
51+
savedAptMark="$(apt-mark showmanual)"; \
52+
\
53+
apt-get update; \
54+
apt-get install -y --no-install-recommends \
55+
libfreetype6-dev \
56+
libjpeg-dev \
57+
libmagickwand-dev \
58+
libpng-dev \
59+
libzip-dev \
60+
; \
61+
{{ ) end -}}
62+
\
63+
docker-php-ext-configure gd \
64+
{{ if env.phpVersion == "7.3" then ( -}}
65+
--with-freetype-dir=/usr \
66+
--with-jpeg-dir=/usr \
67+
--with-png-dir=/usr \
68+
{{ ) else ( -}}
69+
--with-freetype \
70+
--with-jpeg \
71+
{{ ) end -}}
72+
; \
73+
docker-php-ext-install -j "$(nproc)" \
74+
bcmath \
75+
exif \
76+
gd \
77+
mysqli \
78+
zip \
79+
; \
80+
pecl install imagick-3.4.4; \
81+
docker-php-ext-enable imagick; \
82+
\
83+
{{ if env.variant | index("alpine") then ( -}}
84+
runDeps="$( \
85+
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
86+
| tr ',' '\n' \
87+
| sort -u \
88+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
89+
)"; \
90+
apk add --no-network --virtual .wordpress-phpexts-rundeps $runDeps; \
91+
apk del --no-network .build-deps
92+
{{ ) else ( -}}
93+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
94+
apt-mark auto '.*' > /dev/null; \
95+
apt-mark manual $savedAptMark; \
96+
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
97+
| awk '/=>/ { print $3 }' \
98+
| sort -u \
99+
| xargs -r dpkg-query -S \
100+
| cut -d: -f1 \
101+
| sort -u \
102+
| xargs -rt apt-mark manual; \
103+
\
104+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
105+
rm -rf /var/lib/apt/lists/*
106+
{{ ) end -}}
107+
108+
# set recommended PHP.ini settings
109+
{{ if env.version != "cli" then ( -}}
110+
# see https://secure.php.net/manual/en/opcache.installation.php
111+
RUN set -eux; \
112+
docker-php-ext-enable opcache; \
113+
{ \
114+
echo 'opcache.memory_consumption=128'; \
115+
echo 'opcache.interned_strings_buffer=8'; \
116+
echo 'opcache.max_accelerated_files=4000'; \
117+
echo 'opcache.revalidate_freq=2'; \
118+
echo 'opcache.fast_shutdown=1'; \
119+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
120+
{{ ) else ( -}}
121+
# excluding opcache due https://github.com/docker-library/wordpress/issues/407
122+
{{ ) end -}}
123+
# https://wordpress.org/support/article/editing-wp-config-php/#configure-error-logging
124+
RUN { \
125+
# https://www.php.net/manual/en/errorfunc.constants.php
126+
# https://github.com/docker-library/wordpress/issues/420#issuecomment-517839670
127+
echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \
128+
echo 'display_errors = Off'; \
129+
echo 'display_startup_errors = Off'; \
130+
echo 'log_errors = On'; \
131+
echo 'error_log = /dev/stderr'; \
132+
echo 'log_errors_max_len = 1024'; \
133+
echo 'ignore_repeated_errors = On'; \
134+
echo 'ignore_repeated_source = Off'; \
135+
echo 'html_errors = Off'; \
136+
} > /usr/local/etc/php/conf.d/error-logging.ini
137+
{{ if env.variant == "apache" then ( -}}
138+
139+
RUN set -eux; \
140+
a2enmod rewrite expires; \
141+
\
142+
# https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html
143+
a2enmod remoteip; \
144+
{ \
145+
echo 'RemoteIPHeader X-Forwarded-For'; \
146+
# these IP ranges are reserved for "private" use and should thus *usually* be safe inside Docker
147+
echo 'RemoteIPTrustedProxy 10.0.0.0/8'; \
148+
echo 'RemoteIPTrustedProxy 172.16.0.0/12'; \
149+
echo 'RemoteIPTrustedProxy 192.168.0.0/16'; \
150+
echo 'RemoteIPTrustedProxy 169.254.0.0/16'; \
151+
echo 'RemoteIPTrustedProxy 127.0.0.0/8'; \
152+
} > /etc/apache2/conf-available/remoteip.conf; \
153+
a2enconf remoteip; \
154+
# https://github.com/docker-library/wordpress/issues/383#issuecomment-507886512
155+
# (replace all instances of "%h" with "%a" in LogFormat)
156+
find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' +
157+
{{ ) else "" end -}}
158+
159+
{{ if env.version != "cli" then ( -}}
160+
RUN set -eux; \
161+
version={{ .upstream | @sh }}; \
162+
sha1={{ .sha1 | @sh }}; \
163+
\
164+
curl -o wordpress.tar.gz -fL "https://wordpress.org/wordpress-$version.tar.gz"; \
165+
echo "$sha1 *wordpress.tar.gz" | sha1sum -c -; \
166+
\
167+
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
168+
tar -xzf wordpress.tar.gz -C /usr/src/; \
169+
rm wordpress.tar.gz; \
170+
\
171+
chown -R www-data:www-data /usr/src/wordpress; \
172+
# pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
173+
# wp-content/cache: https://github.com/docker-library/wordpress/issues/534#issuecomment-705733507
174+
mkdir wp-content; \
175+
for dir in /usr/src/wordpress/wp-content/*/ cache; do \
176+
dir="$(basename "${dir%/}")"; \
177+
mkdir "wp-content/$dir"; \
178+
done; \
179+
chown -R www-data:www-data wp-content; \
180+
chmod -R 777 wp-content
181+
{{ ) else ( -}}
182+
# https://make.wordpress.org/cli/2018/05/31/gpg-signature-change/
183+
# pub rsa2048 2018-05-31 [SC]
184+
# 63AF 7AA1 5067 C056 16FD DD88 A3A2 E8F2 26F0 BC06
185+
# uid [ unknown] WP-CLI Releases <releases@wp-cli.org>
186+
# sub rsa2048 2018-05-31 [E]
187+
ENV WORDPRESS_CLI_GPG_KEY 63AF7AA15067C05616FDDD88A3A2E8F226F0BC06
188+
189+
ENV WORDPRESS_CLI_VERSION {{ .version }}
190+
ENV WORDPRESS_CLI_SHA512 {{ .sha512 }}
191+
192+
RUN set -ex; \
193+
\
194+
apk add --no-cache --virtual .fetch-deps \
195+
gnupg \
196+
; \
197+
\
198+
curl -o /usr/local/bin/wp.gpg -fL "https://github.com/wp-cli/wp-cli/releases/download/v${WORDPRESS_CLI_VERSION}/wp-cli-${WORDPRESS_CLI_VERSION}.phar.gpg"; \
199+
\
200+
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
201+
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$WORDPRESS_CLI_GPG_KEY"; \
202+
gpg --batch --decrypt --output /usr/local/bin/wp /usr/local/bin/wp.gpg; \
203+
gpgconf --kill all; \
204+
rm -rf "$GNUPGHOME" /usr/local/bin/wp.gpg; unset GNUPGHOME; \
205+
\
206+
echo "$WORDPRESS_CLI_SHA512 */usr/local/bin/wp" | sha512sum -c -; \
207+
chmod +x /usr/local/bin/wp; \
208+
\
209+
apk del --no-network .fetch-deps; \
210+
\
211+
wp --allow-root --version
212+
{{ ) end -}}
213+
214+
VOLUME /var/www/html
215+
216+
COPY docker-entrypoint.sh /usr/local/bin/
217+
218+
ENTRYPOINT ["docker-entrypoint.sh"]
219+
{{ if env.version != "cli" then ( -}}
220+
CMD {{ [ if env.variant == "apache" then "apache2-foreground" else "php-fpm" end ] | @json }}
221+
{{ ) else ( -}}
222+
USER www-data
223+
CMD ["wp", "shell"]
224+
{{ ) end -}}

apache-extras.template

-18
This file was deleted.

0 commit comments

Comments
 (0)