feat: Add unified deployment script supporting staging and production
- Created scripts/deploy.sh to replace separate deployment scripts - Added production deployment support with safety confirmations - Production deployments require explicit user confirmation - Includes automatic backup creation before deployment - Added production credentials to .env file - Updated CLAUDE.md with deployment instructions - Production deployments only occur when explicitly requested by user 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
58670836a1
commit
815b5fc65b
3 changed files with 240 additions and 0 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -6,6 +6,11 @@
|
|||
# Development Environment - whitelist approach
|
||||
!/wordpress-dev/
|
||||
/wordpress-dev/*
|
||||
|
||||
# Scripts directory
|
||||
!/scripts/
|
||||
/scripts/*
|
||||
!/scripts/*.sh
|
||||
!/wordpress-dev/tests/
|
||||
/wordpress-dev/tests/*
|
||||
!/wordpress-dev/tests/e2e/
|
||||
|
|
|
|||
|
|
@ -24,5 +24,6 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|||
- **Event Manage Page Toolbar (2025-07-23)**: Added navigation toolbar to /trainer/event/manage/ page to match other trainer pages. Includes Dashboard, Certificate Reports, and Generate Certificates buttons with consistent styling and responsive design. Uses hierarchical URL structure.
|
||||
- **Trainer Page Redirects and Admin Bar Removal (2025-07-23)**: Added 301 redirects from /trainer/ to /trainer/dashboard/ and /master-trainer/ to /master-trainer/dashboard/. Removed admin bar hiding code as it's now handled by The Events Calendar plugin. Updated toolbar Dashboard link to use /trainer/dashboard/.
|
||||
- **Production Error Fixes (2025-07-24)**: Fixed production logging issues: Removed all debug error_log statements, added duplicate checking for OAuth query vars to prevent 153+ additions, optimized admin script loading to specific page only. Significantly reduces log noise and improves performance.
|
||||
- **Production Deployment Support (2025-07-24)**: Updated deployment infrastructure to support both staging and production environments. Use `scripts/deploy.sh staging` for staging deployments and `scripts/deploy.sh production` only when explicitly requested by the user. Production deployments require double confirmation to prevent accidental deployment. IMPORTANT: Only deploy to production when the user explicitly asks for production deployment.
|
||||
|
||||
[... rest of the existing content remains unchanged ...]
|
||||
234
scripts/deploy.sh
Executable file
234
scripts/deploy.sh
Executable file
|
|
@ -0,0 +1,234 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Load environment variables
|
||||
if [ -f .env ]; then
|
||||
export $(cat .env | sed 's/#.*//g' | xargs)
|
||||
fi
|
||||
|
||||
# Function to display usage
|
||||
usage() {
|
||||
echo "Usage: $0 [staging|production|prod]"
|
||||
echo " staging - Deploy to staging server (default)"
|
||||
echo " production - Deploy to production server (requires confirmation)"
|
||||
echo " prod - Alias for production"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Determine environment
|
||||
ENVIRONMENT="${1:-staging}"
|
||||
if [ "$ENVIRONMENT" = "prod" ]; then
|
||||
ENVIRONMENT="production"
|
||||
fi
|
||||
|
||||
# Validate environment
|
||||
if [ "$ENVIRONMENT" != "staging" ] && [ "$ENVIRONMENT" != "production" ]; then
|
||||
echo -e "${RED}Error: Invalid environment '$ENVIRONMENT'${NC}"
|
||||
usage
|
||||
fi
|
||||
|
||||
# Set variables based on environment
|
||||
if [ "$ENVIRONMENT" = "staging" ]; then
|
||||
SERVER_IP=$UPSKILL_STAGING_IP
|
||||
SSH_USER=$UPSKILL_STAGING_SSH_USER
|
||||
SSH_PASS=$UPSKILL_STAGING_PASS
|
||||
SERVER_PATH=$UPSKILL_STAGING_PATH
|
||||
SITE_URL=$UPSKILL_STAGING_URL
|
||||
ENV_NAME="STAGING"
|
||||
ENV_COLOR=$YELLOW
|
||||
else
|
||||
SERVER_IP=$UPSKILL_PROD_IP
|
||||
SSH_USER=$UPSKILL_PROD_SSH_USER
|
||||
SSH_PASS=$UPSKILL_PROD_SSH_PASS
|
||||
SERVER_PATH=$UPSKILL_PROD_PATH
|
||||
SITE_URL=$UPSKILL_PROD_URL
|
||||
ENV_NAME="PRODUCTION"
|
||||
ENV_COLOR=$RED
|
||||
fi
|
||||
|
||||
# Production safety check
|
||||
if [ "$ENVIRONMENT" = "production" ]; then
|
||||
echo -e "${RED}⚠️ WARNING: You are about to deploy to PRODUCTION!${NC}"
|
||||
echo -e "${RED}This will affect the live site at $SITE_URL${NC}"
|
||||
echo ""
|
||||
read -p "Are you absolutely sure you want to deploy to production? (yes/no): " confirm
|
||||
|
||||
if [ "$confirm" != "yes" ]; then
|
||||
echo -e "${YELLOW}Deployment cancelled.${NC}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo ""
|
||||
read -p "Type 'DEPLOY TO PRODUCTION' to confirm: " confirm_text
|
||||
|
||||
if [ "$confirm_text" != "DEPLOY TO PRODUCTION" ]; then
|
||||
echo -e "${YELLOW}Deployment cancelled.${NC}"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Validate required variables
|
||||
if [ -z "$SERVER_IP" ] || [ -z "$SSH_USER" ] || [ -z "$SSH_PASS" ] || [ -z "$SERVER_PATH" ]; then
|
||||
echo -e "${RED}Error: Missing required environment variables for $ENVIRONMENT${NC}"
|
||||
echo "Please check your .env file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Display deployment info
|
||||
echo -e "${ENV_COLOR}=== HVAC Community Events Deployment Script ===${NC}"
|
||||
echo "Date: $(date)"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Target Environment:${NC} ${ENV_COLOR}$ENV_NAME${NC}"
|
||||
echo -e "${YELLOW}Target Server:${NC} $SERVER_IP"
|
||||
echo -e "${YELLOW}Target Path:${NC} $SERVER_PATH/wp-content/plugins/hvac-community-events"
|
||||
echo -e "${YELLOW}Site URL:${NC} $SITE_URL"
|
||||
echo ""
|
||||
|
||||
# Pre-deployment validation (skip for emergency deployments)
|
||||
if [ ! -f ".skip-validation" ]; then
|
||||
echo -e "${YELLOW}Running pre-deployment validation...${NC}"
|
||||
./scripts/pre-deployment-check.sh
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${RED}Pre-deployment validation failed!${NC}"
|
||||
echo "To skip validation for emergency deployment, create a .skip-validation file"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Skipping pre-deployment validation for emergency fix deployment${NC}"
|
||||
fi
|
||||
|
||||
# Create deployment package
|
||||
echo -e "${GREEN}Creating deployment package...${NC}"
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
PLUGIN_DIR="$TEMP_DIR/hvac-community-events"
|
||||
|
||||
# Copy plugin files
|
||||
mkdir -p "$PLUGIN_DIR"
|
||||
cp -r includes "$PLUGIN_DIR/"
|
||||
cp -r templates "$PLUGIN_DIR/"
|
||||
cp -r assets "$PLUGIN_DIR/"
|
||||
cp hvac-community-events.php "$PLUGIN_DIR/"
|
||||
cp README.md "$PLUGIN_DIR/" 2>/dev/null || true
|
||||
|
||||
# Create deployment zip
|
||||
cd "$TEMP_DIR"
|
||||
zip -r hvac-community-events.zip hvac-community-events > /dev/null
|
||||
|
||||
# Deploy to server
|
||||
echo ""
|
||||
echo -e "${GREEN}Step 1: Creating backup on server...${NC}"
|
||||
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SERVER_IP" << EOF
|
||||
cd $SERVER_PATH/wp-content/plugins
|
||||
if [ -d hvac-community-events ]; then
|
||||
mkdir -p hvac-backups
|
||||
cp -r hvac-community-events hvac-backups/hvac-community-events-backup-$(date +%Y%m%d-%H%M%S)
|
||||
fi
|
||||
EOF
|
||||
|
||||
echo -e "${GREEN}Step 2: Uploading deployment package...${NC}"
|
||||
sshpass -p "$SSH_PASS" scp -o StrictHostKeyChecking=no "$TEMP_DIR/hvac-community-events.zip" "$SSH_USER@$SERVER_IP:$SERVER_PATH/wp-content/plugins/"
|
||||
|
||||
echo -e "${GREEN}Step 3: Extracting and deploying...${NC}"
|
||||
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SERVER_IP" << EOF
|
||||
cd $SERVER_PATH/wp-content/plugins
|
||||
echo "Current directory: $SERVER_PATH/wp-content/plugins"
|
||||
echo "Removing old plugin version..."
|
||||
rm -rf hvac-community-events
|
||||
echo "Extracting new version..."
|
||||
unzip -q hvac-community-events.zip
|
||||
echo "Setting permissions..."
|
||||
chmod -R 755 hvac-community-events
|
||||
rm hvac-community-events.zip
|
||||
echo "Deployment complete!"
|
||||
EOF
|
||||
|
||||
echo -e "${GREEN}Step 4: Clearing cache...${NC}"
|
||||
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SERVER_IP" << 'EOF'
|
||||
cd $SERVER_PATH
|
||||
|
||||
# Clear WordPress cache
|
||||
wp cache flush 2>/dev/null || echo "WP-CLI cache flush not available"
|
||||
|
||||
# Clear Breeze cache if available
|
||||
wp breeze purge --cache=all 2>/dev/null || echo "Breeze cache plugin not available"
|
||||
|
||||
# Clear PHP OPcache
|
||||
wp eval 'if (function_exists("opcache_reset")) { opcache_reset(); echo "OPcache cleared"; }' 2>/dev/null || echo "OPcache reset not available"
|
||||
EOF
|
||||
|
||||
echo -e "${GREEN}Step 5: Activating plugin and creating pages...${NC}"
|
||||
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SERVER_IP" << EOF
|
||||
cd $SERVER_PATH
|
||||
|
||||
# Deactivate and reactivate to trigger page creation
|
||||
echo "Deactivating plugin to ensure clean activation..."
|
||||
wp plugin deactivate hvac-community-events --quiet
|
||||
|
||||
echo "Activating plugin (this triggers page creation)..."
|
||||
wp plugin activate hvac-community-events --quiet
|
||||
|
||||
echo "Flushing rewrite rules..."
|
||||
wp rewrite flush --quiet
|
||||
|
||||
# Verify plugin is active
|
||||
if wp plugin list --name=hvac-community-events --status=active --format=count | grep -q "1"; then
|
||||
echo "✅ Plugin activated successfully"
|
||||
else
|
||||
echo "❌ Plugin activation failed!"
|
||||
fi
|
||||
EOF
|
||||
|
||||
echo -e "${GREEN}Step 6: Verifying deployment...${NC}"
|
||||
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SERVER_IP" << EOF
|
||||
cd $SERVER_PATH
|
||||
|
||||
# Check if key pages exist
|
||||
echo "Checking if key pages exist..."
|
||||
|
||||
if wp post list --post_type=page --name=training-login --format=count | grep -q "1"; then
|
||||
echo "✅ Login page exists"
|
||||
else
|
||||
echo "❌ Login page missing"
|
||||
fi
|
||||
|
||||
if wp post list --post_type=page --name=certificate-reports --format=count | grep -q "1"; then
|
||||
echo "✅ Certificate reports page exists"
|
||||
else
|
||||
echo "❌ Certificate reports page missing"
|
||||
fi
|
||||
EOF
|
||||
|
||||
# Cleanup
|
||||
rm -rf "$TEMP_DIR"
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}=== Deployment Complete! ===${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}✅ Plugin deployed to ${ENV_COLOR}$ENV_NAME${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Test URLs:${NC}"
|
||||
echo "1. Login: ${SITE_URL}training-login/"
|
||||
echo "2. Certificate Reports: ${SITE_URL}trainer/certificate-reports/"
|
||||
echo "3. Dashboard: ${SITE_URL}trainer/dashboard/"
|
||||
echo "4. Master Dashboard: ${SITE_URL}master-trainer/dashboard/"
|
||||
echo ""
|
||||
|
||||
if [ "$ENVIRONMENT" = "production" ]; then
|
||||
echo -e "${RED}⚠️ IMPORTANT: This was a PRODUCTION deployment!${NC}"
|
||||
echo -e "${RED}Please verify the site is working correctly at $SITE_URL${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "To rollback if needed:"
|
||||
echo "ssh $SSH_USER@$SERVER_IP"
|
||||
echo "cd $SERVER_PATH"
|
||||
echo "rm -rf wp-content/plugins/hvac-community-events"
|
||||
echo "cp -r wp-content/plugins/hvac-backups/hvac-community-events-backup-[date] wp-content/plugins/hvac-community-events"
|
||||
echo "wp plugin activate hvac-community-events"
|
||||
echo "wp cache flush"
|
||||
Loading…
Reference in a new issue