Add init-wpcontent script to fix error if wp-content is empty

This commit is contained in:
Aleksandar Puharic 2024-10-29 20:24:06 +01:00
parent 108fd72c86
commit 6dba8a19f9
Signed by: xZero707
GPG Key ID: 3CC53DCAA9C237BB
7 changed files with 31 additions and 0 deletions

View File

@ -29,6 +29,10 @@ COPY --from=wp-src ["/usr/src/wordpress/", "/var/www/html/"]
COPY ["patches/${WP_PATCH_VERSION}/wp-admin-update-core.patch", "/etc/wp-mods/"] COPY ["patches/${WP_PATCH_VERSION}/wp-admin-update-core.patch", "/etc/wp-mods/"]
# Copy wp-content/themes to src - This is needed if wp-content is mounted as a volume and not initialized prior
COPY --from=wp-src ["/usr/src/wordpress/wp-content/themes/", "/usr/src/wordpress/wp-content/themes/"]
# Stage 3 - Final # Stage 3 - Final
FROM ghcr.io/n0rthernl1ghts/wordpress-unit-base:2.1.0 FROM ghcr.io/n0rthernl1ghts/wordpress-unit-base:2.1.0
@ -38,6 +42,7 @@ RUN apk add --update --no-cache patch
COPY --from=rootfs ["/", "/"] COPY --from=rootfs ["/", "/"]
RUN set -eux \ RUN set -eux \
&& apk add --update --no-cache rsync \
&& chmod a+x /usr/local/bin/wp \ && chmod a+x /usr/local/bin/wp \
&& mv "/var/www/html/wp-config-docker.php" "/var/www/html/wp-config.php" \ && mv "/var/www/html/wp-config-docker.php" "/var/www/html/wp-config.php" \
&& wp-apply-patch "/etc/wp-mods/wp-admin-update-core.patch" "/var/www/html/wp-admin/update-core.php" "true" && wp-apply-patch "/etc/wp-mods/wp-admin-update-core.patch" "/var/www/html/wp-admin/update-core.php" "true"

View File

@ -0,0 +1,24 @@
#!/command/with-contenv bash
# shellcheck shell=bash
# init-wpcontent main
main() {
# This will prepend service name to all output from here
exec > >(while read -r line; do echo "[init-wpcontent] ${line}"; done) 2>&1
local wpContentDir="/var/www/html/wp-content"
local wpThemesDir="${wpContentDir}/themes"
# If themes directory is empty
if [ ! -d "${wpThemesDir}" ] || [ -z "$(ls -A "${wpThemesDir}")" ]; then
if [ "${WORDPRESS_INIT_NO_SYNC_THEMES:-false}" = "true" ]; then
echo "Warning: Themes directory is empty, but sync is disabled"
return
fi
echo "Themes directory is empty, copying default themes"
rsync -a --ignore-existing --progress /usr/src/wordpress/wp-content/themes "${wpContentDir}/"
return
fi
}
main

View File

@ -0,0 +1 @@
oneshot

View File

@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-wpcontent/run