2 Commits

Author SHA1 Message Date
b30cc46739 add convenience script for wp scaffolding 2023-12-24 11:47:40 -06:00
3e9a020b20 add development stuff
rename submodule

add theme
2023-12-24 11:46:39 -06:00
37 changed files with 388 additions and 348724 deletions

View File

@@ -1,12 +0,0 @@
WORDPRESS_NETWORK_URL=cmbabaseball.localhost
WORDPRESS_CONFIG_EXTRA="
define('WP_ALLOW_MULTISITE', true );
define('MULTISITE', true );
define('SUBDOMAIN_INSTALL', false );
define('DOMAIN_CURRENT_SITE', '${WORDPRESS_NETWORK_URL}' );
define('PATH_CURRENT_SITE', '/' );
define('SITE_ID_CURRENT_SITE', 1 );
define('BLOG_ID_CURRENT_SITE', 1 );
define('FORCE_SSL_LOGIN', true );
"

9
.gitmodules vendored Normal file
View File

@@ -0,0 +1,9 @@
[submodule "cmbabaseball/data/plugins/tonys-sportspress-enhancements"]
path = cmbabaseball/data/plugins/tonys-sportspress-enhancements
url = https://gitea.ascorrea.com/asc/tonys-sportspress-enhancements.git
[submodule "cmbabaseball/data/plugins/cimba"]
path = cmbabaseball/data/plugins/cimba
url = https://gitea.ascorrea.com/asc/cimba.git
[submodule "cmbabaseball/data/themes/tonys-rookie-enhancements"]
path = cmbabaseball/data/themes/tonys-rookie-enhancements
url = https://gitea.ascorrea.com/asc/tonys-rookie-enhancements.git

51
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,51 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html/wp-content/plugins/": "${workspaceFolder}/src/plugins"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}

View File

@@ -1,3 +1,43 @@
# Selig # Selig
Selig is a Docker project to set-up two Wordpress servers, one for a league, one for a team using Wordpress multisite. It uses Caddy for the webserver and a single MariaDB instance for the server. Selig 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), [chihounds](./chihounds/wp-install)). 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 probably 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). It also preinstalls a list of plugins as defined in the site's .env.
Currently, the scripts are exactly the same, so they are symbolic links to the shared directory.
```sh
./cmbabaseball/init-wordpress
./chihounds/init-wordpress
```
OR
```sh
./*/init-wordpress
```
### 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
}

View File

@@ -1,18 +0,0 @@
cmbabaseball.localhost {
root * /var/www/html
@wp path_regexp wp ^/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)
handle @wp {
rewrite * {http.regexp.wp.2}
}
php_fastcgi wordpress:9000
file_server
}
chihounds.localhost {
root * /var/www/html
php_fastcgi wordpress:9000
file_server
}

View File

@@ -1,18 +0,0 @@
cmbabaseball.correa.co {
root * /var/www/html
@wp path_regexp wp ^/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)
handle @wp {
rewrite * {http.regexp.wp.2}
}
php_fastcgi wordpress:9000
file_server
}
chihounds.correa.co {
root * /var/www/html
php_fastcgi wordpress:9000
file_server
}

View File

@@ -1,2 +1,8 @@
WORDPRESS_SITE_2_SLUG= WORDPRESS_TITLE=
WORDPRESS_SITE_2_TITLE= WORDPRESS_SITEURL=
WORDPRESS_HOME=
WORDPRESS_DB_NAME=
WP_THEMES=
WP_PLUGINS=

File diff suppressed because one or more lines are too long

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

@@ -0,0 +1,4 @@
cd "$(dirname "$0")"
PROJECT_NAME=selig
CONTAINER_NAME=chihounds
docker run --rm --user 33:33 --volume ${PROJECT_NAME}_${CONTAINER_NAME}-wpdata:/var/www/html --volume ./data:/data --env-file ../.env --env-file .env --network ${PROJECT_NAME}_network "$@"

1
chihounds/wp-cli.sh Symbolic link
View File

@@ -0,0 +1 @@
../shared/wp-cli.sh

View File

@@ -1,18 +0,0 @@
if [ "$#" -lt 1 ]; then
echo "Error: COMPOSE_FILE argument is missing."
echo "Usage: $0 COMPOSE_FILE"
exit 1
fi
COMPOSE_FILE="$1"
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
ENV_FILE=$SCRIPTPATH/.env
# this env file is not being read and i don't know why.
# it's actually being loaded from compose.yml
docker compose -f $COMPOSE_FILE --env-file $ENV_FILE run --rm -it wp-cli sh -c '\
wp site create \
--title="$WORDPRESS_SITE_2_TITLE" \
--slug="$WORDPRESS_SITE_2_SLUG" \
--skip-email'

1
chihounds/wp-import.sh Symbolic link
View File

@@ -0,0 +1 @@
../shared/wp-import.sh

1
chihounds/wp-install.sh Symbolic link
View File

@@ -0,0 +1 @@
../shared/wp-install.sh

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=selig
CONTAINER_NAME=cmbabaseball
docker run --rm --user 33:33 --volume ${PROJECT_NAME}_${CONTAINER_NAME}-wpdata:/var/www/html --volume ./data:/data --env-file ../.env --env-file .env --network ${PROJECT_NAME}_network "$@"

29
cmbabaseball/scaffold.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/zsh
# Script Name: scaffold.sh
# Description: Convenience script to create things using WP-CLI scaffold command
#
# Usage: ./scaffold.sh COMMAND SLUG OPTIONS
# Example:
cd "$(dirname "$0")"
CONTAINER_NAME=cmbabaseball
# Check if the number of arguments is less than 1 (i.e., PLUGIN_NAME is not provided)
if [ "$#" -lt 2 ]; then
echo "Error: Not enough arguments."
echo "Usage: $0 COMMAND SLUG OPTIONS"
exit 1
fi
COMMAND=$1
SLUG=$2
OPTIONS=$3
WP_COMMAND="wp scaffold ${COMMAND} ${SLUG} ${OPTIONS}"
echo $WP_COMMAND
# WP_COMMAND="echo 'hello'"
# WP_COMMAND="wp scaffold child-theme"
echo $WP_COMMAND
NEW_PLUGIN_CONTAINER_LOCATION=$(./docker-run.sh --attach stdout --attach stderr -e WPCLI_COMMAND="$WP_COMMAND" wordpress:cli sh -c 'eval $WPCLI_COMMAND' | sed -rn "s/.*Success: Created '(.*)'.*/\1/gp")
echo $NEW_PLUGIN_CONTAINER_LOCATION
docker cp ${CONTAINER_NAME}:${NEW_PLUGIN_CONTAINER_LOCATION} ./data/themes/

1
cmbabaseball/wp-cli.sh Symbolic link
View File

@@ -0,0 +1 @@
../shared/wp-cli.sh

1
cmbabaseball/wp-import.sh Symbolic link
View File

@@ -0,0 +1 @@
../shared/wp-import.sh

1
cmbabaseball/wp-install.sh Symbolic link
View File

@@ -0,0 +1 @@
../shared/wp-install.sh

92
compose-development.yml Normal file
View File

@@ -0,0 +1,92 @@
name: ${PROJECT_NAME}
services:
wordpress-chihounds:
container_name: chihounds
depends_on:
- database
image: wordpress:fpm
env_file:
- .env
- chihounds/.env
environment:
XDEBUG_MODE: debug
XDEBUG_CONFIG: client_host=host.docker.internal client_port=9003
XDEBUG_SESSION: 1
WORDPRESS_DEBUG: 1
WORDPRESS_CONFIG_EXTRA: |
define( 'WP_DEBUG_DISPLAY', true );
define( 'WP_DEBUG_LOG', true );
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
build:
context: ./cmbabaseball
dockerfile: ../shared/Dockerfile-development
env_file:
- .env
- cmbabaseball/.env
environment:
XDEBUG_MODE: debug
XDEBUG_CONFIG: client_host=host.docker.internal client_port=9003
XDEBUG_SESSION: 1
WORDPRESS_DEBUG: 1
WORDPRESS_CONFIG_EXTRA: |
define( 'WP_DEBUG_DISPLAY', true );
define( 'WP_DEBUG_LOG', true );
volumes:
- cmbabaseball-wpdata:/var/www/html
- ./cmbabaseball/data/plugins/cimba:/var/www/html/wp-content/plugins/cimba
- ./cmbabaseball/data/plugins/debug-trace:/var/www/html/wp-content/plugins/debug-trace
- ./cmbabaseball/data/plugins/tonys-sportspress-enhancements:/var/www/html/wp-content/plugins/tonys-sportspress-enhancements
- ./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
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:

View File

@@ -1,77 +0,0 @@
services:
wp-cli:
image: wordpress:cli
user: 33:33
env_file:
- .env
- .env.local
- ./network/.env
- ./chihounds/.env
depends_on:
- database
volumes:
- wpdata:/var/www/html
profiles:
- cli
networks:
- network
wordpress:
depends_on:
- database
image: wordpress:fpm
env_file:
- .env
- .env.local
- ./network/.env
environment:
WORDPRESS_DEBUG: 1
volumes:
- wpdata:/var/www/html
- ./wordpress/php.ini:/usr/local/etc/php/conf.d/wordpress.ini
networks:
- network
database:
image: mariadb
env_file:
- .env
volumes:
- db-data:/var/lib/mysql
networks:
- network
phpmyadmin:
depends_on:
- database
image: phpmyadmin
env_file:
- .env
environment:
UPLOAD_LIMIT: 128M
PMA_HOST: database
PMA_PORT: 3306
ports:
- "8080:80"
networks:
- network
profiles:
- debug
caddy:
image: caddy:alpine
ports:
- 80:80
- 443:443
volumes:
- caddy-data:/data
- caddy-config:/config
- ./caddy/Caddyfile.localhost:/etc/caddy/Caddyfile
- wpdata:/var/www/html
networks:
- network
command: ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile", "--watch"]
volumes:
db-data:
wpdata:
caddy-data:
caddy-config:
networks:
network:

View File

@@ -1,76 +0,0 @@
services:
wp-cli:
image: wordpress:cli
user: 33:33
env_file:
- .env
- .env.local
- ./network/.env
- ./chihounds/.env
depends_on:
- database
volumes:
- wpdata:/var/www/html
profiles:
- cli
networks:
- network
wordpress:
depends_on:
- database
image: wordpress:fpm
env_file:
- .env
- .env.local
- ./network/.env
environment:
WORDPRESS_DEBUG: 1
volumes:
- wpdata:/var/www/html
- ./wordpress/php.ini:/usr/local/etc/php/conf.d/wordpress.ini
networks:
- network
database:
image: mariadb
env_file:
- .env
volumes:
- db-data:/var/lib/mysql
networks:
- network
phpmyadmin:
depends_on:
- database
image: phpmyadmin
env_file:
- .env
environment:
UPLOAD_LIMIT: 128M
PMA_HOST: database
PMA_PORT: 3306
ports:
- "8080:80"
networks:
- network
profiles:
- debug
caddy:
image: caddy:alpine
ports:
- 80:80
- 443:443
volumes:
- caddy-data:/data
- caddy-config:/config
- ./caddy/Caddyfile.production:/etc/caddy/Caddyfile
- wpdata:/var/www/html
networks:
- network
volumes:
db-data:
wpdata:
caddy-data:
caddy-config:
networks:
network:

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:

View File

@@ -1,4 +0,0 @@
WORDPRESS_NETWORK_TITLE=
WORDPRESS_ADMIN_USER=
WORDPRESS_ADMIN_EMAIL=
WORDPRESS_ADMIN_PASSWORD=

View File

@@ -1,21 +0,0 @@
if [ "$#" -lt 1 ]; then
echo "Error: COMPOSE_FILE argument is missing."
echo "Usage: $0 COMPOSE_FILE"
exit 1
fi
COMPOSE_FILE="$1"
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
ENV_FILE=$SCRIPTPATH/.env
# this env file is not being read and i don't know why.
# it's actually being loaded from compose.yml
docker compose -f $COMPOSE_FILE --env-file "${ENV_FILE}" run --rm -it wp-cli sh -c \
'wp core multisite-install \
--title="${WORDPRESS_NETWORK_TITLE}" \
--url="${WORDPRESS_NETWORK_URL}" \
--admin_user="$WORDPRESS_ADMIN_USER" \
--admin_email="$WORDPRESS_ADMIN_EMAIL" \
--admin_password="$WORDPRESS_ADMIN_PASSWORD" \
--skip-config --skip-email' \

View File

@@ -1,17 +0,0 @@
WP_PLUGINS="sportspress sportspress-for-baseball wordpress-importer"
WP_PLUGINS+=" akismet jetpack pretty-link printful-shipping-for-woocommerce seriously-simple-podcasting woocommerce woocommerce-services"
if [ "$#" -lt 1 ]; then
echo "Error: COMPOSE_FILE argument is missing."
echo "Usage: $0 COMPOSE_FILE"
exit 1
fi
COMPOSE_FILE="$1"
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
ENV_FILE=$SCRIPTPATH/.env
# this env file is not being read and i don't know why.
# it's actually being loaded from compose.yml
docker compose -f $COMPOSE_FILE run --env WP_PLUGINS="$WP_PLUGINS" --rm -it wp-cli sh -c \
'wp plugin install $WP_PLUGINS --activate --force'

View File

@@ -1,16 +0,0 @@
WP_THEMES="rookie"
if [ "$#" -lt 1 ]; then
echo "Error: COMPOSE_FILE argument is missing."
echo "Usage: $0 COMPOSE_FILE"
exit 1
fi
COMPOSE_FILE="$1"
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
ENV_FILE=$SCRIPTPATH/.env
# this env file is not being read and i don't know why.
# it's actually being loaded from compose.yml
docker compose -f $COMPOSE_FILE run --env WP_THEMES="$WP_THEMES" --rm -it wp-cli sh -c \
'wp theme install $WP_THEMES'

View File

@@ -0,0 +1,4 @@
FROM wordpress:fpm
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug

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

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

28
shared/wp-import.sh Executable file
View File

@@ -0,0 +1,28 @@
cd "$(dirname "$0")"
./wp-cli.sh sh -c '
if [ -f /data/import.sql ]; then
echo "Importing Database..."
wp db import /data/import.sql
echo "Replacing default site url ($(wp option get siteurl)->$WORDPRESS_SITEURL)"
wp search-replace "$(wp option get siteurl)" "$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 /data/import-uploads.tgz ]; then
echo "Importing Uploads..."
tar -xz --overwrite -f /data/import-uploads.tgz -C /var/www/html/wp-content/uploads .
echo "Done."
fi && \
if [ -n "$(ls -A /data/import-plugins 2>/dev/null)" ]; then
echo "Importing Plugins..."
for I in /data/import-plugins/*.zip; do
[ -f "$I" ] || continue
echo "$I"
wp plugin install "$I" --activate
done
echo "Done."
fi
'

7
shared/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 --force; \
wp plugin install $WP_PLUGINS --activate --force
'