diff --git a/README.md b/README.md index fdf0877..50a08a2 100644 --- a/README.md +++ b/README.md @@ -103,8 +103,12 @@ docker compose -f docker-compose.first.yml down # Start production environment docker compose up -d + +# Or just run +./wp-rocket-launch.sh #also copies new content to production. ``` + ### **4๏ธโƒฃ Migrate Content (Themes, Plugins)** ```bash # Copy new content to production diff --git a/generate-compose-nginx.sh b/generate-compose-nginx.sh index 1a270d8..be69307 100755 --- a/generate-compose-nginx.sh +++ b/generate-compose-nginx.sh @@ -29,7 +29,6 @@ fi # Check if the existing default.conf contains a database hostname matching the pattern (it may or may not contain the env variable placeholder) if grep -qE "\bwordpress_\w+(?::\d+)?\b" default.conf; then # Update in-place only the portion that matches the database host pattern. - # sed -i "s/\bwordpress_\w+(?::\d+)?\b/${new_wp}/g" default.conf perl -pi -e 's/\bwordpress_\w+(?::(\d+))?\b/$ENV{"new_wp"} . (defined($1) ? ":$1" : "")/eg' default.conf echo "default.conf updated with COMPOSE_PROJECT_NAME='${COMPOSE_PROJECT_NAME}'." fi diff --git a/wp-rocket-launch.sh b/wp-rocket-launch.sh new file mode 100755 index 0000000..f817a38 --- /dev/null +++ b/wp-rocket-launch.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Define environment variables +COMPOSE_FILE="docker-compose.first.yml" + +echo "๐Ÿš€ Starting WordPress Deployment Process..." + +# Step 0: **Reset Environment** - Stop and remove volumes +echo "๐Ÿงน Cleaning up existing containers and volumes..." +docker compose down -v + +# Step 1: Build custom WordPress image +echo "๐Ÿ”ง Building custom WordPress image..." +docker compose -f "$COMPOSE_FILE" build + +# Step 2: Install or upgrade WordPress volume +echo "๐Ÿ“ฆ Installing or upgrading WordPress volume..." +docker compose -f "$COMPOSE_FILE" up -d + +# Step 3: Stop WordPress container (keep HTML volume) +echo "โน๏ธ Stopping WordPress container (keeping data)..." +docker compose -f "$COMPOSE_FILE" down + +# Step 4: Start production environment +echo "๐Ÿš€ Launching production environment..." +docker compose up -d + +# Step 5: Source .env and extract the first VIRTUAL_HOST address +if [ -f .env ]; then + set -o allexport + source .env + set +o allexport + + # Extract only the first address from VIRTUAL_HOST + FIRST_VIRTUAL_HOST=$(echo "$VIRTUAL_HOST" | cut -d',' -f1) + + echo "โœ… WordPress deployment complete! Site is live at: https://${FIRST_VIRTUAL_HOST}" +else + echo "โš ๏ธ .env file not found, VIRTUAL_HOST could not be displayed." +fi + +# Step 6: Copy new WordPress content after deployment +echo "๐Ÿ“‚ Copying new WordPress content to wp-content..." +docker compose exec wordpress_${COMPOSE_PROJECT_NAME} bash -c "cp -a /var/www/html/wp-content-new/* /var/www/html/wp-content/" +echo "โœ… WordPress content successfully copied!"