Automates Build & Deploy

This commit is contained in:
Jonathan Rosenbaum 2025-06-09 16:34:25 +00:00
parent d58cd6e879
commit e66297136e
3 changed files with 49 additions and 1 deletions

View File

@ -103,8 +103,12 @@ docker compose -f docker-compose.first.yml down
# Start production environment # Start production environment
docker compose up -d docker compose up -d
# Or just run
./wp-rocket-launch.sh #also copies new content to production.
``` ```
### **4⃣ Migrate Content (Themes, Plugins)** ### **4⃣ Migrate Content (Themes, Plugins)**
```bash ```bash
# Copy new content to production # Copy new content to production

View File

@ -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) # 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 if grep -qE "\bwordpress_\w+(?::\d+)?\b" default.conf; then
# Update in-place only the portion that matches the database host pattern. # 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 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}'." echo "default.conf updated with COMPOSE_PROJECT_NAME='${COMPOSE_PROJECT_NAME}'."
fi fi

45
wp-rocket-launch.sh Executable file
View File

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