Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
137 lines (114 loc) · 5.32 KB
/
Copy pathDockerfile
File metadata and controls
137 lines (114 loc) · 5.32 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
FROM wordpress:cli-2.12.0-php8.5@sha256:d16fa67b450f61a8e16d738e502f29dd30daa08c5e7d2bc39a1e32ec29815aed AS wpcli-donor
FROM wordpress:7.1.4-php8.5-fpm-alpine@sha256:b7c701c23c9f3e45b0e15c6e318c80933bcc6d0d79f08c4d5b10631be814d9f2 AS wordpress-donor
FROM --platform=$BUILDPLATFORM golang:1.27.4-alpine3.24@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS wp-guard-builder
WORKDIR /src
COPY go.mod ./
RUN go mod download
COPY cmd/ cmd/
COPY internal/ internal/
COPY mu-plugins/ /mu-plugins-src/
COPY prepend/ /prepend-src/
COPY --from=wordpress-donor /usr/src/wordpress /usr/src/wordpress
ARG TARGETOS
ARG TARGETARCH
RUN set -eux; \
CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath -o /bin/wp-guard-host ./cmd/wp-guard; \
mkdir -p /usr/local/share/wordpress/mu-plugins /usr/local/share/wordpress/prepend; \
cp -a /mu-plugins-src/sbs-platform/. /usr/local/share/wordpress/mu-plugins/; \
cp /mu-plugins-src/sbs-loader.php /usr/local/share/wordpress/sbs-loader.php; \
cp /prepend-src/sbs-prepend.php /usr/local/share/wordpress/prepend/sbs-prepend.php; \
/bin/wp-guard-host manifest generate; \
find /usr/local/share/wordpress -type d -exec chmod 0555 {} +; \
find /usr/local/share/wordpress -type f -exec chmod 0444 {} +; \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} go build \
-ldflags="-s -w" \
-trimpath \
-o /bin/wp-guard \
./cmd/wp-guard
FROM debian:trixie-slim@sha256:62bd423aeee912639ca8ee681c2b762cb3e25137e0a92b20be455898a9f034ad AS base
ENV DEBIAN_FRONTEND=noninteractive \
LC_ALL=C.UTF-8 \
LANG=C.UTF-8
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# hadolint ignore=DL3008
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gnupg; \
install -m 0755 -d /etc/apt/keyrings; \
curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /etc/apt/keyrings/deb.sury.org-php.gpg; \
chmod 0644 /etc/apt/keyrings/deb.sury.org-php.gpg; \
echo "deb [signed-by=/etc/apt/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ trixie main" \
> /etc/apt/sources.list.d/php.list; \
apt-get update; \
apt-get install -y --no-install-recommends \
php8.5-fpm \
php8.5-cli \
php8.5-common \
php8.5-mysql \
php8.5-redis \
php8.5-igbinary \
php8.5-zstd \
php8.5-imagick \
php8.5-apcu \
php8.5-gmp \
php8.5-intl \
php8.5-zip \
php8.5-bcmath \
php8.5-curl \
php8.5-mbstring \
php8.5-xml \
php8.5-gd \
webp \
libavif-bin \
libfcgi-bin; \
apt-get purge -y --auto-remove gnupg; \
ln -sf /usr/sbin/php-fpm8.5 /usr/local/sbin/php-fpm; \
ln -sf /usr/sbin/php-fpm8.5 /usr/sbin/php-fpm; \
ln -sf /usr/bin/php8.5 /usr/local/bin/php; \
POLICIES=$(find /etc/ImageMagick-* /usr/local/etc/ImageMagick-* -name "policy.xml" 2>/dev/null || true); \
if [ -n "$POLICIES" ]; then \
for p in $POLICIES; do \
for coder in EPHEMERAL URL HTTPS FTP MVG MSVG TEXT SHOW WIN PLT PS EPS PDF XPS; do \
sed -i "/pattern=[\"']${coder}[\"']/d" "$p"; \
sed -i "/<\/policymap>/i \ <policy domain=\"coder\" rights=\"none\" pattern=\"${coder}\" />" "$p"; \
done; \
done; \
fi; \
find / -perm /6000 -type f -exec chmod a-s {} + 2>/dev/null || true; \
mkdir -p /var/run/sockets/mysql /var/run/sockets/valkey /var/run/sockets/php /var/run/sockets/notify /var/www/html /var/www/tmp /run/php; \
chmod 1777 /var/www/tmp /run/php; \
chmod 0755 /var/run/sockets; \
sed -i 's|^error_log = .*|error_log = /proc/self/fd/2|' /etc/php/*/fpm/php-fpm.conf 2>/dev/null || true; \
sed -i 's|^pid = .*|pid = /tmp/php-fpm.pid|' /etc/php/*/fpm/php-fpm.conf 2>/dev/null || true; \
find /etc/php -mindepth 1 -maxdepth 1 -type d -exec ln -s {} /etc/php/current \; 2>/dev/null || true; \
apt-get clean; \
rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/* \
/usr/share/man \
/usr/share/doc \
/usr/share/info
COPY --from=wp-guard-builder --chmod=0555 /bin/wp-guard /usr/local/bin/wp-guard
WORKDIR /var/www/html
FROM base AS cli
HEALTHCHECK NONE
# hadolint ignore=DL3008
RUN apt-get update && apt-get install -y --no-install-recommends git mariadb-client less && apt-get clean && rm -rf /var/lib/apt/lists/*
COPY --from=wpcli-donor --chmod=0555 /usr/local/bin/wp /usr/local/bin/wp
ENTRYPOINT ["wp"]
FROM base AS fpm
COPY --from=wordpress-donor /usr/src/wordpress /usr/src/wordpress
COPY --from=wp-guard-builder /usr/local/share/wordpress /usr/local/share/wordpress
RUN find /usr/local/share/wordpress -type d -exec chmod 0555 {} + && \
find /usr/local/share/wordpress -type f -exec chmod 0444 {} + && \
find /usr/src/wordpress -type d -exec chmod 0555 {} + && \
find /usr/src/wordpress -type f -exec chmod 0444 {} + && \
rm -f /bin/sh /bin/dash /bin/bash /usr/bin/sh /usr/bin/dash /usr/bin/bash
STOPSIGNAL SIGQUIT
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
CMD ["/usr/bin/env", "-i", "SCRIPT_NAME=/ping", "SCRIPT_FILENAME=/ping", "REQUEST_METHOD=GET", "cgi-fcgi", "-bind", "-connect", "/var/run/sockets/php/php-fpm.sock"]
ENTRYPOINT ["php-fpm", "-F"]