From 6dba8a19f9f4ba0559327018edf0b8805fb17e72 Mon Sep 17 00:00:00 2001 From: xZero707 Date: Tue, 29 Oct 2024 20:24:06 +0100 Subject: [PATCH] Add init-wpcontent script to fix error if wp-content is empty --- Dockerfile | 5 ++++ .../dependencies.d/init-wpcontent | 0 .../etc/s6-overlay/s6-rc.d/init-wpcontent/run | 24 +++++++++++++++++++ .../s6-overlay/s6-rc.d/init-wpcontent/type | 1 + .../etc/s6-overlay/s6-rc.d/init-wpcontent/up | 1 + .../svc-unitd/dependencies.d/init-wpcontent | 0 .../s6-rc.d/user/contents.d/init-wpcontent | 0 7 files changed, 31 insertions(+) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/init-webuser-permissions/dependencies.d/init-wpcontent create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/run create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/up create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/svc-unitd/dependencies.d/init-wpcontent create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-wpcontent diff --git a/Dockerfile b/Dockerfile index 8dc7828..7214273 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 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 FROM ghcr.io/n0rthernl1ghts/wordpress-unit-base:2.1.0 @@ -38,6 +42,7 @@ RUN apk add --update --no-cache patch COPY --from=rootfs ["/", "/"] RUN set -eux \ + && apk add --update --no-cache rsync \ && chmod a+x /usr/local/bin/wp \ && 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" diff --git a/rootfs/etc/s6-overlay/s6-rc.d/init-webuser-permissions/dependencies.d/init-wpcontent b/rootfs/etc/s6-overlay/s6-rc.d/init-webuser-permissions/dependencies.d/init-wpcontent new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/run b/rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/run new file mode 100755 index 0000000..65e5958 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/run @@ -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 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/type b/rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/type new file mode 100644 index 0000000..3d92b15 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/type @@ -0,0 +1 @@ +oneshot \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/up b/rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/up new file mode 100644 index 0000000..8da8221 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-wpcontent/run \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/s6-rc.d/svc-unitd/dependencies.d/init-wpcontent b/rootfs/etc/s6-overlay/s6-rc.d/svc-unitd/dependencies.d/init-wpcontent new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-wpcontent b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-wpcontent new file mode 100644 index 0000000..e69de29