Add GitHub Actions deployment workflow

- Add deployment workflow with test, build, and deploy jobs
- Add testing workflow for PRs
- Add deployment scripts (deploy, healthcheck, rollback)
- Add systemd service configuration
- Update Makefile with CI/CD targets
- Add comprehensive deployment documentation
This commit is contained in:
root
2025-10-30 12:19:57 +00:00
parent ee354d1d35
commit 5e38292d2e
9 changed files with 1849 additions and 10 deletions
+69
View File
@@ -0,0 +1,69 @@
#!/bin/bash
set -e
APP_NAME="${1:-cv-server}"
SERVICE_NAME="${2:-cv}"
DEPLOY_PATH="${DEPLOY_PATH:-/home/txeo/Git/yo/cv}"
echo "🚀 Starting deployment of $APP_NAME"
echo "📍 Deploy path: $DEPLOY_PATH"
echo "🔧 Service: $SERVICE_NAME"
# Create backup of current version
if [ -f "$DEPLOY_PATH/$APP_NAME" ]; then
echo "📦 Backing up current version..."
BACKUP_DIR="$DEPLOY_PATH/backups"
mkdir -p "$BACKUP_DIR"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
cp "$DEPLOY_PATH/$APP_NAME" "$BACKUP_DIR/$APP_NAME.$TIMESTAMP"
# Keep only last 5 backups
ls -t "$BACKUP_DIR" | tail -n +6 | xargs -I {} rm -f "$BACKUP_DIR/{}"
echo "✓ Backup created: $APP_NAME.$TIMESTAMP"
fi
# Move new binary into place
echo "📥 Installing new version..."
mv "$DEPLOY_PATH/$APP_NAME.new" "$DEPLOY_PATH/$APP_NAME"
chmod +x "$DEPLOY_PATH/$APP_NAME"
# Restart service
echo "🔄 Restarting service..."
sudo systemctl restart "$SERVICE_NAME"
# Wait for service to start
sleep 3
# Check service status
if sudo systemctl is-active --quiet "$SERVICE_NAME"; then
echo "✅ Service started successfully"
# Get service status
echo ""
echo "📊 Service Status:"
sudo systemctl status "$SERVICE_NAME" --no-pager -l | head -15
echo ""
echo "🎉 Deployment completed successfully"
exit 0
else
echo "❌ Service failed to start - rolling back"
# Rollback to backup
LATEST_BACKUP=$(ls -t "$BACKUP_DIR" 2>/dev/null | head -1)
if [ -n "$LATEST_BACKUP" ]; then
echo "⏪ Rolling back to: $LATEST_BACKUP"
cp "$BACKUP_DIR/$LATEST_BACKUP" "$DEPLOY_PATH/$APP_NAME"
sudo systemctl restart "$SERVICE_NAME"
if sudo systemctl is-active --quiet "$SERVICE_NAME"; then
echo "⚠️ Rolled back to previous version successfully"
else
echo "❌ Rollback failed - manual intervention required"
fi
else
echo "❌ No backup found - manual intervention required"
fi
exit 1
fi
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
set -e
HEALTH_URL="${HEALTH_URL:-http://localhost:1999/health}"
MAX_RETRIES=30
RETRY_DELAY=2
echo "🏥 Running health check on $HEALTH_URL"
for i in $(seq 1 $MAX_RETRIES); do
if curl -sf "$HEALTH_URL" > /dev/null 2>&1; then
echo "✅ Health check passed (attempt $i/$MAX_RETRIES)"
# Show health response
RESPONSE=$(curl -s "$HEALTH_URL")
echo ""
echo "📊 Health Status:"
echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE"
exit 0
fi
echo "⏳ Waiting for service... (attempt $i/$MAX_RETRIES)"
sleep $RETRY_DELAY
done
echo "❌ Health check failed after $MAX_RETRIES attempts"
exit 1
+93
View File
@@ -0,0 +1,93 @@
#!/bin/bash
set -e
APP_NAME="${1:-cv-server}"
SERVICE_NAME="${2:-cv}"
DEPLOY_PATH="${DEPLOY_PATH:-/home/txeo/Git/yo/cv}"
BACKUP_DIR="$DEPLOY_PATH/backups"
echo "⏪ Rollback Script for $APP_NAME"
echo "📍 Deploy path: $DEPLOY_PATH"
echo "🔧 Service: $SERVICE_NAME"
echo ""
# Check if backup directory exists
if [ ! -d "$BACKUP_DIR" ]; then
echo "❌ No backup directory found at $BACKUP_DIR"
exit 1
fi
# List available versions
echo "📦 Available backup versions:"
ls -lht "$BACKUP_DIR" | tail -n +2 | head -5 | awk '{print NR". "$9" ("$6" "$7" "$8")"}'
echo ""
# If no argument provided, show usage
if [ -z "$3" ]; then
echo "Usage: $0 <app_name> <service_name> <version_number>"
echo "Example: $0 cv-server cv 1"
echo ""
echo "Or to rollback to the most recent version:"
echo " $0 cv-server cv latest"
exit 0
fi
VERSION_ARG="$3"
# Determine which backup to use
if [ "$VERSION_ARG" = "latest" ]; then
BACKUP_FILE=$(ls -t "$BACKUP_DIR" | head -1)
echo "🔍 Selected: latest version ($BACKUP_FILE)"
else
BACKUP_FILE=$(ls -t "$BACKUP_DIR" | sed -n "${VERSION_ARG}p")
echo "🔍 Selected: version #$VERSION_ARG ($BACKUP_FILE)"
fi
if [ -z "$BACKUP_FILE" ]; then
echo "❌ Version not found"
exit 1
fi
# Confirm rollback
echo ""
echo "⚠️ About to rollback to: $BACKUP_FILE"
read -p "Continue? (yes/no): " CONFIRM
if [ "$CONFIRM" != "yes" ]; then
echo "❌ Rollback cancelled"
exit 0
fi
# Create backup of current version before rollback
if [ -f "$DEPLOY_PATH/$APP_NAME" ]; then
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
cp "$DEPLOY_PATH/$APP_NAME" "$BACKUP_DIR/$APP_NAME.pre-rollback.$TIMESTAMP"
echo "✓ Current version backed up as: $APP_NAME.pre-rollback.$TIMESTAMP"
fi
# Perform rollback
echo "⏪ Rolling back..."
cp "$BACKUP_DIR/$BACKUP_FILE" "$DEPLOY_PATH/$APP_NAME"
chmod +x "$DEPLOY_PATH/$APP_NAME"
# Restart service
echo "🔄 Restarting service..."
sudo systemctl restart "$SERVICE_NAME"
# Wait for service to start
sleep 3
# Check service status
if sudo systemctl is-active --quiet "$SERVICE_NAME"; then
echo "✅ Rollback successful - service is running"
echo ""
echo "📊 Service Status:"
sudo systemctl status "$SERVICE_NAME" --no-pager -l | head -15
exit 0
else
echo "❌ Service failed to start after rollback"
echo ""
echo "🔍 Service logs:"
sudo journalctl -u "$SERVICE_NAME" -n 20 --no-pager
exit 1
fi