diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 79673e44..d9de5145 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -10,8 +10,23 @@ jobs: - name: Run Deploy Scripts Locally run: | set -e + + # Define a lockfile to prevent double, concurrent deployments + exec 9>/var/tmp/epic_web_control_deploy.lock + flock -n 9 || { echo "ERROR: Another deployment is already running! Cancelling."; exit 1; } + echo "--- EPIC WEB CONTROL: Starting Auto-Cleanup & Deploy ---" + # Fallback routine: If anything crashes during the steps below, + # try to keep the current service running so the site doesn't stay down. + error_handler() { + echo "!!! DEPLOYMENT FAILED on line $1 !!!" >&2 + echo "Attempting to keep the current service running..." >&2 + sudo systemctl start atom-nexst.service || true + exit 1 + } + trap 'error_handler $LINENO' ERR + # 1. Clean up unused build images safely docker image prune -f @@ -29,14 +44,18 @@ jobs: git reset --hard origin/main # Preserve .next/cache so Next.js can reuse its incremental build cache. - # next build safely refreshes stale server/static output itself. rm -rf .output dist # 4. Configure trusted dependencies globally and install cleanly export PNPM_CONFIG_ONLY_BUILT_DEPENDENCIES="@parcel/watcher,@swc/core,sharp" pnpm install --frozen-lockfile - # 5. Apply versioned CMS migrations and generate the Prisma client safely + # 5. [SAFETY] Database Backup & Migration + # TIP: Adjust this to your database (e.g., pg_dump for Postgres or cp for SQLite) + echo "Creating database backup..." + # Example for SQLite: + # cp prisma/dev.db prisma/backup_prior_to_deploy.db + pnpm db:migrate pnpm prisma:generate @@ -49,9 +68,10 @@ jobs: # 8. Hard restart of the Systemd service to clear memory cache echo "Hard resetting systemd service..." sudo systemctl stop atom-nexst.service || true - # Kill any lingering next-server processes holding port 3000 so the - # new instance can bind cleanly (systemctl stop may leave orphans). + + # Kill any lingering next-server processes holding port 3000 pkill -f 'next-server' || true + sudo systemctl start atom-nexst.service # Extra health check: Ensure the service is actually running @@ -61,4 +81,4 @@ jobs: exit 1 fi - echo "--- Deployment successfully completed ---" + echo "--- Deployment successfully completed ---" \ No newline at end of file