From 0df4f8540d740a40f350b46e704a1f901f60e0f1 Mon Sep 17 00:00:00 2001 From: Anthony Correa Date: Sat, 16 Dec 2023 17:23:18 -0600 Subject: [PATCH] initial commit --- .env.sample | 14 +++++++ .gitignore | 3 ++ README.md | 41 ++++++++++++++++++++ caddy/Caddyfile | 15 ++++++++ chihounds/.env.sample | 8 ++++ chihounds/docker-run.sh | 4 ++ chihounds/wp-cli.sh | 2 + chihounds/wp-import.sh | 27 +++++++++++++ chihounds/wp-install.sh | 7 ++++ cmbabaseball/.env.sample | 8 ++++ cmbabaseball/docker-run.sh | 4 ++ cmbabaseball/wp-cli.sh | 2 + cmbabaseball/wp-import.sh | 27 +++++++++++++ cmbabaseball/wp-install.sh | 7 ++++ compose.yml | 77 ++++++++++++++++++++++++++++++++++++++ shared/php.ini | 8 ++++ 16 files changed, 254 insertions(+) create mode 100644 .env.sample create mode 100644 .gitignore create mode 100644 README.md create mode 100644 caddy/Caddyfile create mode 100644 chihounds/.env.sample create mode 100755 chihounds/docker-run.sh create mode 100755 chihounds/wp-cli.sh create mode 100755 chihounds/wp-import.sh create mode 100755 chihounds/wp-install.sh create mode 100644 cmbabaseball/.env.sample create mode 100755 cmbabaseball/docker-run.sh create mode 100755 cmbabaseball/wp-cli.sh create mode 100755 cmbabaseball/wp-import.sh create mode 100755 cmbabaseball/wp-install.sh create mode 100644 compose.yml create mode 100644 shared/php.ini diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..56eaee7 --- /dev/null +++ b/.env.sample @@ -0,0 +1,14 @@ +PROJECT_NAME=kenesaw + +WORDPRESS_ADMIN_USER= +WORDPRESS_ADMIN_EMAIL= +WORDPRESS_ADMIN_PASSWORD= + +WORDPRESS_DB_PASSWORD= +WORDPRESS_DB_USER= +WORDPRESS_DB_HOST= + +MYSQL_USER= +MYSQL_PASSWORD= +MYSQL_ROOT_PASSWORD= +MYSQL_DATABASE= \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4a375e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.sql +*.tgz +.env \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1034d75 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# Kenesaw + +Kenesaw is a Docker project to set-up two Wordpress servers, one for a league, one for a team. It uses Caddy for the webserver and a single MariaDB instance for the server. + +Each Wordpress instance setups their own database within the MariaDB instance. + +## Setup +### Environment Files +There are two environment files, one at the project root and one under each WordPress folder ([cmbabaseball](./cmbabaseball/.env), [chihounds](./chihounds/.env)). + +### Init +Each WordPress site has an `wp-install.sh` script ([cmbabaseball](./cmbabaseball/wp-install.sh), [chihounds](./chihounds/wp-install.sh)). It creates the database and install Wordpress using the common `wp-admin` user info provided in the project root via a ephemeral wp-cli container. (Theoretically, this can be changed by overwriting the environment variables in the website-specific env file, but I didn't test that and I don't know what the order would have to be). + +```sh +./cmbabaseball/init-wordpress.sh +./chihounds/init-wordpress.sh +``` + +OR + +```sh +./*/init-wordpress.sh +``` + +### Import +Since I was starting from a couple of existing sites, each WordPress site has an `import-wordpress.sh` ([cmbabaseball](./cmbabaseball/import-wordpress.sh), [chihounds](./chihounds/import-wordpress.sh)). These have been packaged as a `import.sql` DB export and a `import-uploads.tgz` archive of the uploads folder. + +```sh +./cmbabaseball/wp-import.sh +./chihounds/wp-import.sh +``` +OR +```sh +./*cmbabaseball*/wp-import.sh +``` + +### Tying it together +To put it together succintly, you can run the following to do all the init scripts, then the import scripts. +```sh +/*/wp-install.sh && ./*/wp-import.sh +``` \ No newline at end of file diff --git a/caddy/Caddyfile b/caddy/Caddyfile new file mode 100644 index 0000000..8e3deb8 --- /dev/null +++ b/caddy/Caddyfile @@ -0,0 +1,15 @@ +cmbabaseball.localhost { + root * /var/www/cmbabaseball + php_fastcgi cmbabaseball:9000 { + root /var/www/html + } + file_server +} + +chihounds.localhost { + root * /var/www/chihounds + php_fastcgi chihounds:9000 { + root /var/www/html + } + file_server +} diff --git a/chihounds/.env.sample b/chihounds/.env.sample new file mode 100644 index 0000000..5b29d40 --- /dev/null +++ b/chihounds/.env.sample @@ -0,0 +1,8 @@ +WORDPRESS_TITLE= +WORDPRESS_SITEURL= +WORDPRESS_HOME= + +WORDPRESS_DB_NAME= + +WP_THEMES= +WP_PLUGINS= diff --git a/chihounds/docker-run.sh b/chihounds/docker-run.sh new file mode 100755 index 0000000..36b7234 --- /dev/null +++ b/chihounds/docker-run.sh @@ -0,0 +1,4 @@ +cd "$(dirname "$0")" +PROJECT_NAME=kenesaw +CONTAINER_NAME=chihounds +docker run --rm --user 33:33 --volume ${PROJECT_NAME}_${CONTAINER_NAME}-wpdata:/var/www/html --env-file ../.env --env-file .env --network ${PROJECT_NAME}_network "$@" \ No newline at end of file diff --git a/chihounds/wp-cli.sh b/chihounds/wp-cli.sh new file mode 100755 index 0000000..59558d5 --- /dev/null +++ b/chihounds/wp-cli.sh @@ -0,0 +1,2 @@ +cd "$(dirname "$0")" +./docker-run.sh wordpress:cli "$@" \ No newline at end of file diff --git a/chihounds/wp-import.sh b/chihounds/wp-import.sh new file mode 100755 index 0000000..17464aa --- /dev/null +++ b/chihounds/wp-import.sh @@ -0,0 +1,27 @@ +cd "$(dirname "$0")" + +./docker-run.sh \ +-v ./data/import.sql:/import.sql \ +-v ./data/import-uploads.tgz:/import-uploads.tgz \ +wordpress:cli sh -c ' + +if [ -f /import.sql ]; then + echo "Importing Database..." + wp db query < /import.sql + echo "Replacing default site url (https://localhost->$WORDPRESS_SITEURL)" + wp search-replace "https://localhost" "$WORDPRESS_SITEURL" --format=count + echo "Re-adding the admin user" + wp user create $WORDPRESS_ADMIN_USER $WORDPRESS_ADMIN_EMAIL --user_pass=$WORDPRESS_ADMIN_PASSWORD --role=administrator --porcelain + echo "Done." +fi && \ +if [ -f /import-uploads.tgz ]; then + echo "Importing Uploads..." + tar -xz --overwrite -f /import-uploads.tgz -C /var/www/html/wp-content/uploads . + echo "Done." +fi && \ +if [ -f /import-plugins.tgz ]; then + echo "Importing Plugins..." + tar -xzk--overwrite -f /import-plugins.tgz -C /var/www/html/wp-content/plugins . + echo "Done." +fi +' \ No newline at end of file diff --git a/chihounds/wp-install.sh b/chihounds/wp-install.sh new file mode 100755 index 0000000..17db762 --- /dev/null +++ b/chihounds/wp-install.sh @@ -0,0 +1,7 @@ +cd "$(dirname "$0")" +./wp-cli.sh sh -c ' +wp db create || true && \ +wp core install --title="$WORDPRESS_TITLE" --url="$WORDPRESS_SITEURL" --admin_user=$WORDPRESS_ADMIN_USER --admin_email=$WORDPRESS_ADMIN_EMAIL --admin_password=$WORDPRESS_ADMIN_PASSWORD && \ +wp theme install $WP_THEMES --activate; \ +wp plugin install $WP_PLUGINS --activate +' \ No newline at end of file diff --git a/cmbabaseball/.env.sample b/cmbabaseball/.env.sample new file mode 100644 index 0000000..5b29d40 --- /dev/null +++ b/cmbabaseball/.env.sample @@ -0,0 +1,8 @@ +WORDPRESS_TITLE= +WORDPRESS_SITEURL= +WORDPRESS_HOME= + +WORDPRESS_DB_NAME= + +WP_THEMES= +WP_PLUGINS= diff --git a/cmbabaseball/docker-run.sh b/cmbabaseball/docker-run.sh new file mode 100755 index 0000000..68ebf41 --- /dev/null +++ b/cmbabaseball/docker-run.sh @@ -0,0 +1,4 @@ +cd "$(dirname "$0")" +PROJECT_NAME=kenesaw +CONTAINER_NAME=cmbabaseball +docker run --rm --user 33:33 --volume ${PROJECT_NAME}_${CONTAINER_NAME}-wpdata:/var/www/html --env-file ../.env --env-file .env --network ${PROJECT_NAME}_network "$@" \ No newline at end of file diff --git a/cmbabaseball/wp-cli.sh b/cmbabaseball/wp-cli.sh new file mode 100755 index 0000000..59558d5 --- /dev/null +++ b/cmbabaseball/wp-cli.sh @@ -0,0 +1,2 @@ +cd "$(dirname "$0")" +./docker-run.sh wordpress:cli "$@" \ No newline at end of file diff --git a/cmbabaseball/wp-import.sh b/cmbabaseball/wp-import.sh new file mode 100755 index 0000000..17464aa --- /dev/null +++ b/cmbabaseball/wp-import.sh @@ -0,0 +1,27 @@ +cd "$(dirname "$0")" + +./docker-run.sh \ +-v ./data/import.sql:/import.sql \ +-v ./data/import-uploads.tgz:/import-uploads.tgz \ +wordpress:cli sh -c ' + +if [ -f /import.sql ]; then + echo "Importing Database..." + wp db query < /import.sql + echo "Replacing default site url (https://localhost->$WORDPRESS_SITEURL)" + wp search-replace "https://localhost" "$WORDPRESS_SITEURL" --format=count + echo "Re-adding the admin user" + wp user create $WORDPRESS_ADMIN_USER $WORDPRESS_ADMIN_EMAIL --user_pass=$WORDPRESS_ADMIN_PASSWORD --role=administrator --porcelain + echo "Done." +fi && \ +if [ -f /import-uploads.tgz ]; then + echo "Importing Uploads..." + tar -xz --overwrite -f /import-uploads.tgz -C /var/www/html/wp-content/uploads . + echo "Done." +fi && \ +if [ -f /import-plugins.tgz ]; then + echo "Importing Plugins..." + tar -xzk--overwrite -f /import-plugins.tgz -C /var/www/html/wp-content/plugins . + echo "Done." +fi +' \ No newline at end of file diff --git a/cmbabaseball/wp-install.sh b/cmbabaseball/wp-install.sh new file mode 100755 index 0000000..17db762 --- /dev/null +++ b/cmbabaseball/wp-install.sh @@ -0,0 +1,7 @@ +cd "$(dirname "$0")" +./wp-cli.sh sh -c ' +wp db create || true && \ +wp core install --title="$WORDPRESS_TITLE" --url="$WORDPRESS_SITEURL" --admin_user=$WORDPRESS_ADMIN_USER --admin_email=$WORDPRESS_ADMIN_EMAIL --admin_password=$WORDPRESS_ADMIN_PASSWORD && \ +wp theme install $WP_THEMES --activate; \ +wp plugin install $WP_PLUGINS --activate +' \ No newline at end of file diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..f1ec2ab --- /dev/null +++ b/compose.yml @@ -0,0 +1,77 @@ +name: ${PROJECT_NAME} +services: + wordpress-chihounds: + container_name: chihounds + depends_on: + - database + image: wordpress:fpm + env_file: + - .env + - chihounds/.env + environment: + WORDPRESS_DEBUG: 0 + volumes: + - chihounds-wpdata:/var/www/html + - ./shared/php.ini:/usr/local/etc/php/conf.d/wordpress.ini + networks: + - network + wordpress-cmbabaseball: + container_name: cmbabaseball + depends_on: + - database + image: wordpress:fpm + env_file: + - .env + - cmbabaseball/.env + environment: + WORDPRESS_DEBUG: 0 + volumes: + - cmbabaseball-wpdata:/var/www/html + - ./shared/php.ini:/usr/local/etc/php/conf.d/wordpress.ini + networks: + - network + database: + container_name: database + hostname: ${WORDPRESS_DB_HOST} + image: mariadb + env_file: + - .env + volumes: + - db-data:/var/lib/mysql + networks: + - network + phpmyadmin: + container_name: phpmyadmin + image: phpmyadmin + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + UPLOAD_LIMIT: 128M + ports: + - "8080:80" + networks: + - network + profiles: + - DEV + caddy: + image: caddy:alpine + container_name: webserver + ports: + - 80:80 + - 443:443 + volumes: + - caddy-data:/data + - caddy-config:/config + - ./caddy/Caddyfile:/etc/caddy/Caddyfile + - chihounds-wpdata:/var/www/chihounds + - cmbabaseball-wpdata:/var/www/cmbabaseball + networks: + - network + +volumes: + db-data: + chihounds-wpdata: + cmbabaseball-wpdata: + caddy-data: + caddy-config: +networks: + network: \ No newline at end of file diff --git a/shared/php.ini b/shared/php.ini new file mode 100644 index 0000000..2d05b5d --- /dev/null +++ b/shared/php.ini @@ -0,0 +1,8 @@ +file_uploads = On +memory_limit = 256M +upload_max_filesize = 64M +post_max_size = 64M +max_execution_time = 300 +max_input_time = 1000 +max_input_vars = 10000 +max_multipart_body_parts = 10000 \ No newline at end of file