forked from onefastsnail/phpfpm-nginx-supervisor-debian
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
216 lines (207 loc) · 6.88 KB
/
Dockerfile
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
# syntax=docker/dockerfile:1
FROM php:8.1.31-fpm-bullseye
LABEL maintainer="Evermade"
ENV WP_CLI_GPG_KEYS="63AF7AA15067C05616FDDD88A3A2E8F226F0BC06"
ENV WP_CLI_VERSION="2.11.0"
# Download WP-CLI binary and signature
ADD --checksum=sha256:35a53c2b59296c39a5251e0f3190f81a4ebcba2f02c069566c7a7367485419e0 --chmod=444 https://github.com/wp-cli/wp-cli/releases/download/v$WP_CLI_VERSION/wp-cli-$WP_CLI_VERSION.phar.asc /usr/local/bin/wp.asc
ADD --checksum=sha256:a39021ac809530ea607580dbf93afbc46ba02f86b6cffd03de4b126ca53079f6 --chmod=555 https://github.com/wp-cli/wp-cli/releases/download/v$WP_CLI_VERSION/wp-cli-$WP_CLI_VERSION.phar /usr/local/bin/wp
# Download WP-CLI bash tab completions
ADD --checksum=sha256:443ca0610ccae8d2d6aceba0ec4aa7929b87ed6cf54f666afed18d663a18a395 --chmod=444 https://raw.githubusercontent.com/wp-cli/wp-cli/v$WP_CLI_VERSION/utils/wp-completion.bash /etc/wp-completion.bash
# Download the deb.sury.org apt archive keyring
ADD --checksum=sha256:fc814e120cb28bbedf75b5e8df7a32e2b903c624d4f78bcd83dc6c4ae30a1dd5 --chmod=444 https://packages.sury.org/nginx/pool/main/d/debsuryorg-archive-keyring/debsuryorg-archive-keyring_2024.02.05%2B0~20240226.2%2Bdebian11~1.gbp343037_all.deb /tmp/debsuryorg-archive-keyring.deb
# This can be used to force rebuild below while allowing use of cache mounts
ARG BUILD_DATE="undefined"
# Builders aren't interactive
ARG DEBIAN_FRONTEND="noninteractive"
RUN --mount=type=cache,sharing=private,target=/var/cache/apt \
--mount=type=cache,sharing=private,target=/var/lib/apt \
--mount=type=cache,sharing=private,target=/tmp/pear \
--mount=type=cache,sharing=private,target=/tmp/pip \
--mount=type=bind,source=./certbot-requirements.txt,target=/opt/certbot/requirements.txt \
\
set -eux; \
\
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends gnupg; \
\
export GNUPGHOME="$(mktemp -d)"; \
GPG_KEYS="$WP_CLI_GPG_KEYS"; \
for key in $GPG_KEYS; do \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
done; \
\
# Verify signature of WP-CLI binary
gpg --batch --verify /usr/local/bin/wp.asc /usr/local/bin/wp; \
rm /usr/local/bin/wp.asc; \
\
gpgconf --kill all; \
rm -rf "$GNUPGHOME"; \
\
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark > /dev/null; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
\
# Nginx apt dependencies
apt-get install -y --no-install-recommends \
apt-transport-https \
lsb-release \
; \
\
# This adds a more frequently updated nginx apt repository
dpkg -i /tmp/debsuryorg-archive-keyring.deb; \
rm /tmp/debsuryorg-archive-keyring.deb; \
echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-nginx.gpg] https://packages.sury.org/nginx/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/nginx.list; \
printf "Package: debsuryorg* nginx* libnginx-mod-*\n\
Pin: origin packages.sury.org\n\
Pin-Priority: 1001\n" > /etc/apt/preferences.d/nginx; \
apt-get update; \
\
# Upgrade apt packages
apt-get upgrade -y; \
\
# Install persistent apt packages
apt-get install -y --no-install-recommends \
# PDF preview rendering for WordPress
ghostscript \
\
# Nginx
nginx \
libnginx-mod-http-brotli \
libnginx-mod-http-cache-purge \
libnginx-mod-http-geoip \
libnginx-mod-http-geoip2 \
libnginx-mod-http-headers-more-filter \
libnginx-mod-http-image-filter \
libnginx-mod-stream \
libnginx-mod-stream-geoip \
\
# Tools
brotli \
cron \
gnupg \
less \
mariadb-client \
nano \
sudo \
supervisor \
wget \
zip \
\
# Logging utils
expect \
logrotate \
moreutils \
rsyslog \
\
# Install certbot dependencies
python3 \
python3-venv \
; \
\
# Install certbot
python3 -m venv /opt/certbot/; \
/opt/certbot/bin/pip install --cache-dir /tmp/pip --isolated --require-virtualenv --only-binary :all: --upgrade pip; \
/opt/certbot/bin/pip install --cache-dir /tmp/pip --isolated --require-virtualenv --prefer-binary --require-hashes --requirement /opt/certbot/requirements.txt; \
ln -s /opt/certbot/bin/certbot /usr/bin/certbot; \
certbot --version; \
printf "PATH=\"/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\"\n\
0 0,12 * * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew -q\n" > /etc/cron.d/certbot; \
mkdir /etc/letsencrypt; \
\
# Install the PHP extensions we need (https://make.wordpress.org/hosting/handbook/server-environment/#php-extensions)
\
savedAptMark="$(apt-mark showmanual)"; \
\
# Install build dependencies to compile PHP extensions
apt-get install -y --no-install-recommends \
# gd
libfreetype6-dev \
libjpeg-dev \
libpng-dev \
libwebp-dev \
libzip-dev \
\
# intl
libicu-dev \
\
# imagick
libmagickwand-dev \
\
# redis
liblz4-dev \
; \
\
# Configure PHP GD extension
docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
; \
\
# Compile and install PHP extensions
docker-php-ext-install -j"$(nproc)" \
bcmath \
exif \
gd \
intl \
mysqli \
opcache \
zip \
; \
export MAKEFLAGS="-j$(nproc)"; \
pecl update-channels; \
pecl install \
--onlyreqdeps \
--configureoptions='enable-redis-igbinary="yes" enable-redis-lzf="no" enable-redis-zstd="no" enable-redis-msgpack="no" enable-redis-lz4="yes" with-liblz4="yes"' \
\
igbinary \
imagick-3.7.0 \
redis \
; \
docker-php-ext-enable \
igbinary \
imagick \
redis \
; \
\
# Some misbehaving extensions end up outputting to stdout 🙈 (https://github.com/docker-library/wordpress/issues/669#issuecomment-993945967)
out="$(php -r 'exit(0);')"; \
[ -z "$out" ]; \
err="$(php -r 'exit(0);' 3>&1 1>&2 2>&3)"; \
[ -z "$err" ]; \
\
extDir="$(php -r 'echo ini_get("extension_dir");')"; \
[ -d "$extDir" ]; \
\
# Reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
ldd "$extDir"/*.so \
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -rt apt-mark manual; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
\
! { ldd "$extDir"/*.so | grep 'not found'; }; \
\
# Check for output like "PHP Warning: PHP Startup: Unable to load dynamic library 'foo' (tried: ...)
err="$(php --version 3>&1 1>&2 2>&3)"; \
[ -z "$err" ]; \
\
# Print nginx version information
nginx -V; \
\
# Test nginx configuration for failures
nginx -t; \
\
# Create old brotli module config file for backwards compatibility
cat /etc/nginx/modules-enabled/50-mod-http-brotli-filter.conf /etc/nginx/modules-enabled/50-mod-http-brotli-static.conf > /etc/nginx/modules-enabled/50-mod-brotli.conf; \
\
# Install WP-CLI tab completions
echo 'source /etc/wp-completion.bash' >> /etc/bash.bashrc