This commit is contained in:
Gilles Mouchet 2026-03-09 13:50:22 +01:00
parent 05f0cae110
commit bf62784b5c
5 changed files with 96 additions and 190 deletions

View File

@ -1,23 +1,32 @@
# environment # environment
ENVIRONMENT=gmolab ENVIRONMENT=gmolab
# site # site
SITE_TITLE="GMo Lab" SITE_TITLE="GMo Lab"
# container
WP_SITE=wp-site
WP_DB=wp-db
WP_PMA=wp-pma
# host # host
HOST_NAME=wp-dev.gmolab.net HOST_NAME=wp-dev.gmolab.net
HOST_IP=172.31.10.16 HOST_IP=172.31.10.16
HOST_PMA=pma-dev.gmolab.net HOST_PMA=pma-dev.gmolab.net
# phpadmin image # phpadmin image
PHPADMIN_IMAGE=arm64v8/phpmyadmin:latest PHPADMIN_IMAGE=arm64v8/phpmyadmin:latest
#PHPADMIN_IMAGE=amd64/phpmyadmin:latest #PHPADMIN_IMAGE=amd64/phpmyadmin:latest
# wp client URL # wp client URL
WP_CLI_URL=https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar WP_CLI_URL=https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
WP_CLI=wp-cli.phar WP_CLI=wp-cli.phar
# gantry theme # gantry theme
GANTRY_THEME_HYDROGEN_URL=https://github.com/gantry/gantry5/releases/download/5.6.0/wordpress-tpl_g5_hydrogen_v5.6.0.zip GANTRY_THEME_HYDROGEN_URL=https://github.com/gantry/gantry5/releases/download/5.6.0/wordpress-tpl_g5_hydrogen_v5.6.0.zip
GANTRY_THEME_HELIUM_URL=https://github.com/gantry/gantry5/releases/download/5.6.0/wordpress-tpl_g5_helium_v5.6.0.zip GANTRY_THEME_HELIUM_URL=https://github.com/gantry/gantry5/releases/download/5.6.0/wordpress-tpl_g5_helium_v5.6.0.zip
# container
WP_SITE=wp-site
WP_DB=wp-db
WP_PMA=wp-pma
# paths
WP_ROOT_FOLDER=/home/docker/wp
WP_SITE_FOLDER=$WP_ROOT_FOLDER/wp-site
WP_DB_FOLDER=$WP_ROOT_FOLDER/wp-db

View File

@ -21,16 +21,20 @@ git clone https://gitweb.dyndns.org/docker/wordpress-docker-compose.git
cd wordpress-docker-compose cd wordpress-docker-compose
``` ```
## Environment file ## Environment file
Copy `env-dist` to `env-<environment_name>` file and adapt as your needs Copy `.env-dist` to `.env` file and adapt as your needs
## Build ## Build
```bash ```bash
./manage.sh --env <env_name> --build ./manage.sh --build
``` ```
## Start ## Start
```bash ```bash
./manage.sh --env <env_name> --start ./manage.sh --start
``` ```
## Others actions
```bash
./manage.sh --help
``
## DB ## DB
The database is a dump of wp first install The database is a dump of wp first install
The script adapt the sql file with data from environment file The script adapt the sql file with data from environment file
@ -39,7 +43,7 @@ The script adapt the sql file with data from environment file
https://wp-dev.gmolab.net https://wp-dev.gmolab.net
https://pma-dev.gmolab.net https://pma-dev.gmolab.net
### [1.0.0] - 2026-03-08 ### [v1.0.0] - 2026-03-08
#### Added #### Added
- initial version by [GMo](mailto:gilles.mouchet@gmail.com) - initial version by [GMo](mailto:gilles.mouchet@gmail.com)

View File

@ -1,20 +0,0 @@
# environment
ENVIRONMENT=gmolab
# site
SITE_TITLE="GMo Lab"
# container
WP_SITE=wp-site
WP_DB=wp-db
WP_PMA=wp-pma
# host
HOST_NAME=wp-dev.gmolab.net
HOST_IP=172.31.10.16
HOST_PMA=pma-dev.gmolab.net
# phpadmin image
PHPADMIN_IMAGE=arm64v8/phpmyadmin:latest
# wp client URL
WP_CLI_URL=https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
WP_CLI=wp-cli.phar
# gantry theme
GANTRY_THEME_HYDROGEN_URL=https://github.com/gantry/gantry5/releases/download/5.6.0/wordpress-tpl_g5_hydrogen_v5.6.0.zip
GANTRY_THEME_HELIUM_URL=https://github.com/gantry/gantry5/releases/download/5.6.0/wordpress-tpl_g5_helium_v5.6.0.zip

View File

@ -1,20 +0,0 @@
# environment
ENVIRONMENT=vdglab
# site
SITE_TITLE="VdG Lab"
# container
WP_SITE=wp-site
WP_DB=wp-db
WP_PMA=wp-pma
# host
HOST_NAME=wp.vdglab.net
HOST_IP=10.10.8.104
HOST_PMA=pma.vdglab.net
# phpadmin image
PHPADMIN_IMAGE=amd64/phpmyadmin:latest
# wp client URL
WP_CLI_URL=https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
WP_CLI=wp-cli.phar
# gantry theme
GANTRY_THEME_HYDROGEN_URL=https://github.com/gantry/gantry5/releases/download/5.6.0/wordpress-tpl_g5_hydrogen_v5.6.0.zip
GANTRY_THEME_HELIUM_URL=https://github.com/gantry/gantry5/releases/download/5.6.0/wordpress-tpl_g5_helium_v5.6.0.zip

175
manage.sh
View File

@ -17,10 +17,6 @@ SCRIPT_NAME=$(basename "$0")
UPDATE_DATE=08.02.2026 UPDATE_DATE=08.02.2026
VERSION=1.0.0 VERSION=1.0.0
WP_ROOT_FOLDER=/home/docker/wp
WP_SITE_FOLDER=$WP_ROOT_FOLDER/wp-site
WP_DB_FOLDER=$WP_ROOT_FOLDER/wp-db
RED='\e[1;31m' RED='\e[1;31m'
GREEN='\e[0;32m' GREEN='\e[0;32m'
ORANGE='\e[0;33m' ORANGE='\e[0;33m'
@ -50,10 +46,10 @@ Usage: $SCRIPT_NAME <options>
Options: Options:
--bash open shell root in container wp --bash open shell root in container wp
--build create files for persistent datas and containers
--console start docker compose as console --console start docker compose as console
--delete stop and delete container and delete files in ${WP_ROOT_FOLDER} --delete stop and delete container and files in ${WP_ROOT_FOLDER}
--down stop docker compose and delete container --down stop docker compose and delete container
--env <env_name> environment name (MANDATORY)
--stop stop docker compose --stop stop docker compose
--start start docker compose as daemon --start start docker compose as daemon
--version version --version version
@ -103,10 +99,12 @@ check-container-up(){
# MAIN # MAIN
#----------------------------------------------------------- #-----------------------------------------------------------
# create destinations folders # read env file
if [ ! -d "$WP_ROOT_FOLDER" ]; then if [ -f ".env" ]; then
#echo "create $WP_ROOT_FOLDER" . .env
sudo mkdir -p $WP_ROOT_FOLDER else
echo -e "\n${RED}[ERROR]: file .env do not exist${NC}\n"
exit 1
fi fi
# check param exist # check param exist
@ -118,119 +116,52 @@ fi
# analysis of arguments # analysis of arguments
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
--help)
usage
;;
--version)
version
;;
--env)
if [[ -n "$2" && "$2" != -* ]]; then
ENV="$2"
shift 2
else
echo -e "\n${RED}Error: --env requires an argument.${NC}"
usage
fi
;;
--bash) --bash)
MODE="bash" check-container-exist
check-container-up
docker exec --user root -it ${WP_SITE} /bin/bash
shift shift
;; ;;
--build) --build)
MODE="build" # set var on DB
sed -e "s/_FQDN_/$HOST_NAME/g" \
-e "s/_SITE_TITLE_/$SITE_TITLE/g" < db-tmpl.sql > dump-db/wp-db.sql
# create destinations folders
if [ ! -d "$WP_ROOT_FOLDER" ]; then
sudo mkdir -p $WP_ROOT_FOLDER
fi
# start container
docker compose up -d
# install wp client line interface
inst-wpcli
# install gantry5 plugin
docker exec "$WP_SITE" ./wp-cli.phar plugin install gantry5 --activate --allow-root
# install helium theme
docker exec "$WP_SITE" ./wp-cli.phar theme install $GANTRY_THEME_HELIUM_URL --activate --allow-root
# set right
sudo chown 33:33 $WP_SITE_FOLDER -R
# stop containers
docker compose stop
shift shift
;; ;;
--console) --console)
MODE="console" check-container-exist
if [ "$(docker inspect -f '{{.State.Status}}' "$WP_SITE" 2>/dev/null)" = "running" ]; then
echo -e "\n${RED}$WP_SITE is started${NC}"
echo -e "Execute './${SCRIPT_NAME} --stop' to sto containers\n"
exit
fi
docker compose up
shift shift
;; ;;
--down) --down)
MODE="down" doicker compose down
shift shift
;; ;;
--delete) --delete)
MODE="delete"
shift
;;
--stop)
MODE="stop"
shift
;;
--start)
MODE="start"
shift
;;
*)
echo -e "\n${RED}Error: Unknown option !${NC}: $1"
usage
;;
esac
done
# if we have an ENV but no mode (--bash, --console, ...)
if [[ -n "$ENV" && -z "$MODE" ]]; then
echo -e "\n${RED}\nError: Missing options${NC}"
usage
fi
# if we have a mode but no ENV (since --env is mandatory outside of help/version)
if [[ -n "$MODE" && -z "$ENV" ]]; then
echo -e "\n${RED}Error: The --env option is required to use --$MODE.${NC}"
usage
fi
# if nothing is provided
if [[ -z "$ENV" && -z "$MODE" ]]; then
usage
fi
echo -e "${GREEN}------------------------"
echo "Environment: $ENV"
echo -e "------------------------${NC}"
# check if env file exist
# copy file env
if [ -f "env-$ENV" ]; then
cp env-$ENV .env
. .env
sed -e "s/_FQDN_/$HOST_NAME/g" \
-e "s/_SITE_TITLE_/$SITE_TITLE/g" < db-tmpl.sql > dump-db/wp-db.sql
else
echo -e "\n${RED}Error: file env-$ENV do not exist${NC}\n"
exit 1
fi
case "$MODE" in
bash)
check-container-exist
check-container-up
docker exec --user root -it wp-site /bin/bash
;;
build)
docker compose up -d
echo "Waiting for status 'healthy'... of container $WP_DB"
until [ "$(docker inspect -f '{{.State.Health.Status}}' $WP_DB)" == "healthy" ]; do
echo -n "."
sleep 2
done
echo " "
inst-wpcli
docker exec "$WP_SITE" ./wp-cli.phar plugin install gantry5 --activate --allow-root
docker exec "$WP_SITE" ./wp-cli.phar theme install $GANTRY_THEME_HELIUM_URL --activate --allow-root
sudo chown 33:33 $WP_SITE_FOLDER -R
docker compose stop
;;
console)
check-container-exist
docker compose up
#sudo chown 33:33 $WP_SITE_FOLDER -R
;;
delete)
echo -e "${RED}-----------------------------------------------------------------------------------------------------" echo -e "${RED}-----------------------------------------------------------------------------------------------------"
echo -e "Do you really want to delete the contents of the ${WP_ROOT_FOLDER} folder [y/N]?" echo -e "Do you really want to delete the contents of the ${WP_ROOT_FOLDER} folder [y/N]?"
echo -e "----------------------------------------------------------------------------------------------------- ${NC}" echo -e "----------------------------------------------------------------------------------------------------- ${NC}"
unset answer unset answer
read answer read answer
if [ "${answer}" != "y" ]; then if [ "${answer}" != "y" ]; then
@ -241,24 +172,26 @@ case "$MODE" in
#sleep 5 #sleep 5
sudo rm -rf $WP_ROOT_FOLDER sudo rm -rf $WP_ROOT_FOLDER
sudo rm -rf /root/.wp-cli sudo rm -rf /root/.wp-cli
exit shift
;; ;;
down) --stop)
docker compose down
exit
;;
stop)
docker compose stop docker compose stop
exit shift
;; ;;
start) --start)
check-container-exist check-container-exist
docker compose up -d docker compose up -d
echo "Waiting for status 'healthy'... of container $WP_DB" shift
until [ "$(docker inspect -f '{{.State.Health.Status}}' $WP_DB)" == "healthy" ]; do ;;
echo -n "." --help)
sleep 2 usage
done ;;
echo " " --version)
version
;;
*)
echo -e "\n${RED}Error: Unknown option !${NC}: $1"
usage
;; ;;
esac esac
done