diff --git a/env-dist b/.env-dist similarity index 85% rename from env-dist rename to .env-dist index 02722ec..7770789 100644 --- a/env-dist +++ b/.env-dist @@ -1,23 +1,32 @@ # 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 #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 +# 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 \ No newline at end of file diff --git a/README.md b/README.md index 113770c..c36f3f2 100644 --- a/README.md +++ b/README.md @@ -21,16 +21,20 @@ git clone https://gitweb.dyndns.org/docker/wordpress-docker-compose.git cd wordpress-docker-compose ``` ## Environment file -Copy `env-dist` to `env-` file and adapt as your needs +Copy `.env-dist` to `.env` file and adapt as your needs ## Build ```bash -./manage.sh --env --build +./manage.sh --build ``` ## Start ```bash -./manage.sh --env --start +./manage.sh --start ``` +## Others actions +```bash +./manage.sh --help +`` ## DB The database is a dump of wp first install 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://pma-dev.gmolab.net -### [1.0.0] - 2026-03-08 +### [v1.0.0] - 2026-03-08 #### Added - initial version by [GMo](mailto:gilles.mouchet@gmail.com) diff --git a/env-gmolab b/env-gmolab deleted file mode 100644 index 91f067b..0000000 --- a/env-gmolab +++ /dev/null @@ -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 \ No newline at end of file diff --git a/env-vdglab b/env-vdglab deleted file mode 100644 index d2c80b9..0000000 --- a/env-vdglab +++ /dev/null @@ -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 diff --git a/manage.sh b/manage.sh index c57a89a..7480526 100755 --- a/manage.sh +++ b/manage.sh @@ -17,10 +17,6 @@ SCRIPT_NAME=$(basename "$0") UPDATE_DATE=08.02.2026 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' GREEN='\e[0;32m' ORANGE='\e[0;33m' @@ -50,10 +46,10 @@ Usage: $SCRIPT_NAME Options: --bash open shell root in container wp + --build create files for persistent datas and containers --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 - --env environment name (MANDATORY) --stop stop docker compose --start start docker compose as daemon --version version @@ -103,10 +99,12 @@ check-container-up(){ # MAIN #----------------------------------------------------------- -# create destinations folders -if [ ! -d "$WP_ROOT_FOLDER" ]; then - #echo "create $WP_ROOT_FOLDER" - sudo mkdir -p $WP_ROOT_FOLDER +# read env file +if [ -f ".env" ]; then + . .env +else + echo -e "\n${RED}[ERROR]: file .env do not exist${NC}\n" + exit 1 fi # check param exist @@ -118,147 +116,82 @@ fi # analysis of arguments while [[ $# -gt 0 ]]; do case "$1" in + --bash) + check-container-exist + check-container-up + docker exec --user root -it ${WP_SITE} /bin/bash + shift + ;; + --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 + ;; + --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 + ;; + --down) + doicker compose down + shift + ;; + --delete) + echo -e "${RED}-----------------------------------------------------------------------------------------------------" + echo -e "Do you really want to delete the contents of the ${WP_ROOT_FOLDER} folder [y/N]?" + echo -e "----------------------------------------------------------------------------------------------------- ${NC}" + unset answer + read answer + if [ "${answer}" != "y" ]; then + echo -e "${ORANGE}Operation cancelled!${NC}" + exit 1 + fi + docker compose down + #sleep 5 + sudo rm -rf $WP_ROOT_FOLDER + sudo rm -rf /root/.wp-cli + shift + ;; + --stop) + docker compose stop + shift + ;; + --start) + check-container-exist + docker compose up -d + shift + ;; --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) - MODE="bash" - shift - ;; - --build) - MODE="build" - shift - ;; - --console) - MODE="console" - shift - ;; - --down) - MODE="down" - shift - ;; - --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 "Do you really want to delete the contents of the ${WP_ROOT_FOLDER} folder [y/N]?" - echo -e "----------------------------------------------------------------------------------------------------- ${NC}" - - unset answer - read answer - if [ "${answer}" != "y" ]; then - echo -e "${ORANGE}Operation cancelled!${NC}" - exit 1 - fi - docker compose down - #sleep 5 - sudo rm -rf $WP_ROOT_FOLDER - sudo rm -rf /root/.wp-cli - exit - ;; - down) - docker compose down - exit - ;; - stop) - docker compose stop - exit - ;; - start) - check-container-exist - 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 " " - ;; -esac