Skip to content

Commit 906399d

Browse files
author
lillian
committed
ok, wordpress actually works with --read-only now
1 parent 17d3c4b commit 906399d

File tree

2 files changed

+64
-9
lines changed

2 files changed

+64
-9
lines changed

wordpress/Dockerfile

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ FROM alpine:latest
22

33
RUN apk add unit-php82 php82-ldap php82-mysqli php82-curl php82-dom php82-exif php82-fileinfo \
44
php82-pecl-imagick php82-mbstring php82-zip php82-gd php82-iconv php82-intl \
5-
zip curl git
5+
zip curl git strace
66

77
WORKDIR /app
88

9-
# Unit entrypoint, but config is in /app/config instead of /docker-entrypoint.d
10-
RUN wget https://raw.githubusercontent.com/nginx/unit/d48180190752201865f41b2cf1e0a6740fa2ea59/pkg/docker/docker-entrypoint.sh
11-
RUN sed -i 's/docker-entrypoint\.d/app\/config/g' docker-entrypoint.sh
12-
RUN chmod +x docker-entrypoint.sh
13-
14-
# fix for `unlink("/run/unit.pid") failed (2: No such file or directory)`, should ask upstream about this at some point
15-
RUN sed -i 's#set -e#touch /run/unit.pid\n&#' docker-entrypoint.sh
9+
COPY docker-entrypoint.sh .
1610

1711
RUN wget -O - https://wordpress.org/wordpress-6.4.2.tar.gz | tar xz
1812

@@ -32,4 +26,4 @@ COPY config.json .
3226
# mount /app/wordpress/wp-config.php:ro
3327
# mount /app/wordpress/wp-content/uploads/:rw
3428

35-
CMD [ "/app/docker-entrypoint.sh", "unitd", "--log", "/dev/stdout", "--no-daemon", "--user", "nobody", "--group", "nobody" ]
29+
CMD [ "/app/docker-entrypoint.sh" ]

wordpress/docker-entrypoint.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
# adapted from https://raw.githubusercontent.com/nginx/unit/d48180190752201865f41b2cf1e0a6740fa2ea59/pkg/docker/docker-entrypoint.sh
3+
4+
set -e
5+
6+
WAITLOOPS=5
7+
SLEEPSEC=1
8+
9+
log() {
10+
echo "$(basename $0): $@"
11+
}
12+
13+
curl_put()
14+
{
15+
RET=$(/usr/bin/curl -s -w '%{http_code}' -X PUT --data-binary $1 --unix-socket /var/run/control.unit.sock http://localhost/$2)
16+
RET_BODY=$(echo $RET | /bin/sed '$ s/...$//')
17+
RET_STATUS=$(echo $RET | /usr/bin/tail -c 4)
18+
if [ "$RET_STATUS" -ne "200" ]; then
19+
log "Error: HTTP response status code is '$RET_STATUS'"
20+
echo "$RET_BODY"
21+
return 1
22+
else
23+
log "OK: HTTP response status code is '$RET_STATUS'"
24+
echo "$RET_BODY"
25+
fi
26+
return 0
27+
}
28+
29+
set_config() {
30+
for i in $(/usr/bin/seq $WAITLOOPS); do
31+
if [ ! -S /var/run/control.unit.sock ]; then
32+
log "Waiting for control socket to be created..."
33+
/bin/sleep $SLEEPSEC
34+
else
35+
break
36+
fi
37+
done
38+
# even when the control socket exists, it does not mean unit has finished initialisation
39+
# this curl call will get a reply once unit is fully launched
40+
/usr/bin/curl -s -X GET --unix-socket /var/run/control.unit.sock http://localhost/
41+
42+
log "Setting access logs to /dev/stdout"
43+
curl_put '"/dev/stdout"' "config/access_log"
44+
45+
config="/app/config/config.json"
46+
log "Applying configuration $config"
47+
curl_put @$config config
48+
49+
echo "$0: Unit configuration complete"
50+
}
51+
52+
if [ "$1" == "set-config" ]; then
53+
set_config
54+
exit 0
55+
fi
56+
57+
log "Starting config thread in background..."
58+
sh $0 set-config &
59+
60+
log "Starting unitd..."
61+
exec unitd --control unix:/var/run/control.unit.sock --log /dev/stdout --no-daemon --user nobody --group nobody

0 commit comments

Comments
 (0)