initial commit

This commit is contained in:
2023-12-16 17:23:18 -06:00
commit 0df4f8540d
16 changed files with 254 additions and 0 deletions

14
.env.sample Normal file
View File

@@ -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=

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.sql
*.tgz
.env

41
README.md Normal file
View File

@@ -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
```

15
caddy/Caddyfile Normal file
View File

@@ -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
}

8
chihounds/.env.sample Normal file
View File

@@ -0,0 +1,8 @@
WORDPRESS_TITLE=
WORDPRESS_SITEURL=
WORDPRESS_HOME=
WORDPRESS_DB_NAME=
WP_THEMES=
WP_PLUGINS=

4
chihounds/docker-run.sh Executable file
View File

@@ -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 "$@"

2
chihounds/wp-cli.sh Executable file
View File

@@ -0,0 +1,2 @@
cd "$(dirname "$0")"
./docker-run.sh wordpress:cli "$@"

27
chihounds/wp-import.sh Executable file
View File

@@ -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
'

7
chihounds/wp-install.sh Executable file
View File

@@ -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
'

8
cmbabaseball/.env.sample Normal file
View File

@@ -0,0 +1,8 @@
WORDPRESS_TITLE=
WORDPRESS_SITEURL=
WORDPRESS_HOME=
WORDPRESS_DB_NAME=
WP_THEMES=
WP_PLUGINS=

4
cmbabaseball/docker-run.sh Executable file
View File

@@ -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 "$@"

2
cmbabaseball/wp-cli.sh Executable file
View File

@@ -0,0 +1,2 @@
cd "$(dirname "$0")"
./docker-run.sh wordpress:cli "$@"

27
cmbabaseball/wp-import.sh Executable file
View File

@@ -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
'

7
cmbabaseball/wp-install.sh Executable file
View File

@@ -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
'

77
compose.yml Normal file
View File

@@ -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:

8
shared/php.ini Normal file
View File

@@ -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