Skip to content

Commit 10acdfa

Browse files
committed
Tweak
1 parent d652ab7 commit 10acdfa

File tree

5 files changed

+246
-0
lines changed

5 files changed

+246
-0
lines changed

8.3-prod/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM wordpress:cli-php8.3 as wordpress-cli
2+
FROM wordpress:php8.3-fpm-alpine as wordpress
3+
FROM kooldev/php:8.3-prod
4+
5+
6+
COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp
7+
COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress
8+
COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content
9+
COPY entrypoint /kool/wordpress-entrypoint
10+
11+
RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint
12+
13+
ENTRYPOINT [ "/kool/wordpress-entrypoint" ]
14+
CMD [ "supervisord", "-c", "/kool/supervisor.conf" ]

8.3-prod/entrypoint

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
5+
# Run as current user
6+
CURRENT_USER=${ASUSER:-${UID:-0}}
7+
8+
if [ ! -z "$CURRENT_USER" ] && [ "$CURRENT_USER" != "0" ]; then
9+
usermod -u $CURRENT_USER kool
10+
fi
11+
12+
# user/group for Wordpress
13+
user=kool
14+
group=kool
15+
uid=$(id -u)
16+
17+
if [ "$1" = 'php-fpm' ] || [ "$1" = 'supervisord' ]; then
18+
# Original Wordpress Entrypoint - fresh install if none exists
19+
if [ ! -e index.php ] && [ ! -e wp-includes/version.php ]; then
20+
# if the directory exists and WordPress doesn't appear to be installed AND the permissions of it are root:root, let's chown it (likely a Docker-created directory)
21+
if [ "$uid" = '0' ] && [ "$(stat -c '%u:%g' .)" = '0:0' ]; then
22+
chown "$user:$group" .
23+
fi
24+
25+
echo >&2 "WordPress not found in $PWD - copying now..."
26+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
27+
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
28+
fi
29+
sourceTarArgs=(
30+
--create
31+
--file -
32+
--directory /kool/wordpress
33+
--owner "$user" --group "$group"
34+
)
35+
targetTarArgs=(
36+
--extract
37+
--file -
38+
)
39+
if [ "$uid" != '0' ]; then
40+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
41+
targetTarArgs+=( --no-overwrite-dir )
42+
fi
43+
# loop over "pluggable" content in the source, and if it already exists in the destination, skip it
44+
# https://github.com/docker-library/wordpress/issues/506 ("wp-content" persisted, "akismet" updated, WordPress container restarted/recreated, "akismet" downgraded)
45+
for contentPath in \
46+
/kool/wordpress/.htaccess \
47+
/kool/wordpress/wp-content/*/*/ \
48+
; do
49+
contentPath="${contentPath%/}"
50+
[ -e "$contentPath" ] || continue
51+
contentPath="${contentPath#/kool/wordpress/}" # "wp-content/plugins/akismet", etc.
52+
if [ -e "$PWD/$contentPath" ]; then
53+
echo >&2 "WARNING: '$PWD/$contentPath' exists! (not copying the WordPress version)"
54+
sourceTarArgs+=( --exclude "./$contentPath" )
55+
fi
56+
done
57+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
58+
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
59+
fi
60+
61+
wpEnvs=( "${!WORDPRESS_@}" )
62+
if [ ! -s wp-config.php ] && [ "${#wpEnvs[@]}" -gt 0 ]; then
63+
for wpConfigDocker in \
64+
wp-config-docker.php \
65+
/kool/wordpress/wp-config-docker.php \
66+
; do
67+
if [ -s "$wpConfigDocker" ]; then
68+
echo >&2 "No 'wp-config.php' found in $PWD, but 'WORDPRESS_...' variables supplied; copying '$wpConfigDocker' (${wpEnvs[*]})"
69+
# using "awk" to replace all instances of "put your unique phrase here" with a properly unique string (for AUTH_KEY and friends to have safe defaults if they aren't specified with environment variables)
70+
awk '
71+
/put your unique phrase here/ {
72+
cmd = "head -c1m /dev/urandom | sha1sum | cut -d\\ -f1"
73+
cmd | getline str
74+
close(cmd)
75+
gsub("put your unique phrase here", str)
76+
}
77+
{ print }
78+
' "$wpConfigDocker" > wp-config.php
79+
if [ "$uid" = '0' ]; then
80+
# attempt to ensure that wp-config.php is owned by the run user
81+
# could be on a filesystem that doesn't allow chown (like some NFS setups)
82+
chown "$user:$group" wp-config.php || true
83+
fi
84+
break
85+
fi
86+
done
87+
fi
88+
fi
89+
90+
exec /kool/entrypoint "$@"

8.3/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM wordpress:cli-php8.3 as wordpress-cli
2+
FROM wordpress:php8.3-fpm-alpine as wordpress
3+
FROM kooldev/php:8.3
4+
5+
6+
COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp
7+
COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress
8+
COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content
9+
COPY entrypoint /kool/wordpress-entrypoint
10+
11+
RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint
12+
13+
ENTRYPOINT [ "/kool/wordpress-entrypoint" ]
14+
CMD [ "supervisord", "-c", "/kool/supervisor.conf" ]

8.3/entrypoint

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
5+
# Run as current user
6+
CURRENT_USER=${ASUSER:-${UID:-0}}
7+
8+
if [ ! -z "$CURRENT_USER" ] && [ "$CURRENT_USER" != "0" ]; then
9+
usermod -u $CURRENT_USER kool
10+
fi
11+
12+
# user/group for Wordpress
13+
user=kool
14+
group=kool
15+
uid=$(id -u)
16+
17+
if [ "$1" = 'php-fpm' ] || [ "$1" = 'supervisord' ]; then
18+
# Original Wordpress Entrypoint - fresh install if none exists
19+
if [ ! -e index.php ] && [ ! -e wp-includes/version.php ]; then
20+
# if the directory exists and WordPress doesn't appear to be installed AND the permissions of it are root:root, let's chown it (likely a Docker-created directory)
21+
if [ "$uid" = '0' ] && [ "$(stat -c '%u:%g' .)" = '0:0' ]; then
22+
chown "$user:$group" .
23+
fi
24+
25+
echo >&2 "WordPress not found in $PWD - copying now..."
26+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
27+
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
28+
fi
29+
sourceTarArgs=(
30+
--create
31+
--file -
32+
--directory /kool/wordpress
33+
--owner "$user" --group "$group"
34+
)
35+
targetTarArgs=(
36+
--extract
37+
--file -
38+
)
39+
if [ "$uid" != '0' ]; then
40+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
41+
targetTarArgs+=( --no-overwrite-dir )
42+
fi
43+
# loop over "pluggable" content in the source, and if it already exists in the destination, skip it
44+
# https://github.com/docker-library/wordpress/issues/506 ("wp-content" persisted, "akismet" updated, WordPress container restarted/recreated, "akismet" downgraded)
45+
for contentPath in \
46+
/kool/wordpress/.htaccess \
47+
/kool/wordpress/wp-content/*/*/ \
48+
; do
49+
contentPath="${contentPath%/}"
50+
[ -e "$contentPath" ] || continue
51+
contentPath="${contentPath#/kool/wordpress/}" # "wp-content/plugins/akismet", etc.
52+
if [ -e "$PWD/$contentPath" ]; then
53+
echo >&2 "WARNING: '$PWD/$contentPath' exists! (not copying the WordPress version)"
54+
sourceTarArgs+=( --exclude "./$contentPath" )
55+
fi
56+
done
57+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
58+
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
59+
fi
60+
61+
wpEnvs=( "${!WORDPRESS_@}" )
62+
if [ ! -s wp-config.php ] && [ "${#wpEnvs[@]}" -gt 0 ]; then
63+
for wpConfigDocker in \
64+
wp-config-docker.php \
65+
/kool/wordpress/wp-config-docker.php \
66+
; do
67+
if [ -s "$wpConfigDocker" ]; then
68+
echo >&2 "No 'wp-config.php' found in $PWD, but 'WORDPRESS_...' variables supplied; copying '$wpConfigDocker' (${wpEnvs[*]})"
69+
# using "awk" to replace all instances of "put your unique phrase here" with a properly unique string (for AUTH_KEY and friends to have safe defaults if they aren't specified with environment variables)
70+
awk '
71+
/put your unique phrase here/ {
72+
cmd = "head -c1m /dev/urandom | sha1sum | cut -d\\ -f1"
73+
cmd | getline str
74+
close(cmd)
75+
gsub("put your unique phrase here", str)
76+
}
77+
{ print }
78+
' "$wpConfigDocker" > wp-config.php
79+
if [ "$uid" = '0' ]; then
80+
# attempt to ensure that wp-config.php is owned by the run user
81+
# could be on a filesystem that doesn't allow chown (like some NFS setups)
82+
chown "$user:$group" wp-config.php || true
83+
fi
84+
break
85+
fi
86+
done
87+
fi
88+
fi
89+
90+
exec /kool/entrypoint "$@"

fwd-template.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,44 @@
305305
}
306306
]
307307
},
308+
{
309+
"name": "8.3",
310+
"data": {
311+
"from": "kooldev/php:8.3",
312+
"nginx": false,
313+
"prod": false,
314+
"version": "8.3"
315+
},
316+
"files": [
317+
{
318+
"name": "Dockerfile",
319+
"path": "template/Dockerfile"
320+
},
321+
{
322+
"name": "entrypoint",
323+
"path": "template/entrypoint"
324+
}
325+
]
326+
},
327+
{
328+
"name": "8.3-prod",
329+
"data": {
330+
"from": "kooldev/php:8.3-prod",
331+
"nginx": false,
332+
"prod": true,
333+
"version": "8.3"
334+
},
335+
"files": [
336+
{
337+
"name": "Dockerfile",
338+
"path": "template/Dockerfile"
339+
},
340+
{
341+
"name": "entrypoint",
342+
"path": "template/entrypoint"
343+
}
344+
]
345+
},
308346
{
309347
"name": "8.3-nginx",
310348
"data": {

0 commit comments

Comments
 (0)