Skip to content

Commit

Permalink
Add init-wpcontent script to fix error if wp-content is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
xZero707 committed Oct 29, 2024
1 parent 108fd72 commit 6dba8a1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Empty file.
24 changes: 24 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/run
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-wpcontent/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-wpcontent/run
Empty file.
Empty file.

0 comments on commit 6dba8a1

Please sign in to comment.