Commit ec41cef4 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add sandbox mode

parent 291e848a
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
<?php
/**
 * Copyright 2019-2021 Dominik Sekotill <dom.sekotill@kodo.org.uk>
 * Copyright 2019-2021, 2023 Dominik Sekotill <dom.sekotill@kodo.org.uk>
 *
 * Plugin Name: Docker Image Integration
 * Plugin URI: https://code.kodo.org.uk/singing-chimes.co.uk/wordpress/tree/master/plugins
@@ -31,6 +31,8 @@ add_action( 'plugins_loaded', function() {
});


if ( !defined( 'SANDBOX_MODE' ) ):

// Block File Modification

add_filter(
@@ -70,6 +72,8 @@ add_filter(
	10, 3
);

endif;


// S3-Uploads Integration

+23 −0
Original line number Diff line number Diff line
@@ -202,6 +202,28 @@ setup_media()
	chown -R ${WORKER_USER}:${WORKER_USER} "${MEDIA}"
}

setup_sandbox()
{
	[[ -v SANDBOX_MODE ]] || return 0
	wp config set SANDBOX_MODE true --raw
	wp config set FS_METHOD direct
	wp config set WP_CONTENT_DIR /app/static/wp-content
	wp config set WPMU_PLUGIN_DIR /app/wp-content/mu-plugins
	rsync \
		--archive \
		--delete-delay \
		--exclude=/wp-content/mu-plugins/ \
		wp-content static/
	mkdir -p \
		static/wp-content/plugins \
		static/wp-content/upgrade
	chown -R www-data:www-data \
		static/wp-content/languages \
		static/wp-content/plugins \
		static/wp-content/themes \
		static/wp-content/upgrade
}

collect_static()
{
	get_media_dir
@@ -310,6 +332,7 @@ case "$1" in
		setup_media
		collect_static
		generate_static
		setup_sandbox
		timestamp "Completed Wordpress preparation"
		run_background_cron
		exec "$@" "${extra_args[@]}"