Verified Commit 96f59e22 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add a writable cache location in wp-content

parent 6150ae5f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -120,4 +120,9 @@ server {
		include safe.types;
		default_type application/octet-stream;
	}

	# Disable serving directly from any page cache in /wp-content/cache
	location /wp-content/cache/ {
		return =404;
	}
}
+14 −11
Original line number Diff line number Diff line
@@ -167,24 +167,26 @@ setup_components() {
	return 0
}

get_media_dir()
get_writable_dirs()
{
	[[ -v MEDIA ]] && return
	MEDIA=$(
	[[ -v MEDIA && -v CACHE ]] && return
	local content=$(
		wp config get WP_CONTENT_DIR --type=constant || echo wp-content
	)
	local media=$(
		wp config get UPLOADS --type=constant ||
		wp option get upload_path
	)
	[[ -n "${MEDIA}" ]] && return
	local _wp_content=$(wp config get WP_CONTENT_DIR --type=constant)
	MEDIA=${_wp_content:-wp-content}/uploads
	MEDIA=${media:-${content}/uploads}
	CACHE=${content}/cache
}

setup_media()
setup_writable()
{
	# UID values change on every run, ensure the owner and group are set
	# correctly on the media directory/volume.
	get_media_dir
	chown -R ${WORKER_USER}:${WORKER_USER} "${MEDIA}"
	get_writable_dirs
	chown -R ${WORKER_USER}:${WORKER_USER} "${MEDIA}" "${CACHE}"
}

setup_sandbox()
@@ -233,7 +235,7 @@ setup_debug()

collect_static()
{
	get_media_dir
	get_writable_dirs
	local IFS=,
	declare -a flags=(flist stats remove del)
	test -t 1 && flags+=(progress2)
@@ -244,6 +246,7 @@ collect_static()
		--exclude-from=- \
		--exclude='*.php' \
		--exclude="${MEDIA}" \
		--exclude="${CACHE}" \
		--exclude=/static/ \
		--exclude=/vendor/ \
		--force \
@@ -337,7 +340,7 @@ case "$1" in
		create_config
		setup_components
		setup_debug
		setup_media
		setup_writable
		collect_static
		generate_static
		setup_sandbox