diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index c8e57138..364a1ae8 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -11,25 +11,25 @@ jobs: run: | set -e - # 1. Lockfile om dubbele, gelijktijdige deployments te voorkomen + # 1. Lockfile to prevent concurrent, duplicate 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 bij crashes + # Fallback routine on deployment crashes 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 + sudo systemctl restart atom-nexst.service || true exit 1 } trap 'error_handler $LINENO' ERR - # 2. Systeem opruimen + # 2. Clean up old system Docker images safely docker image prune -f - # 3. Git updates & Rechten + # 3. Git updates & Permissions configuration cd /var/www/atom-nexst/ git config --global --add safe.directory /var/www/atom-nexst git remote set-url origin /docker/gitea/gitea/git/repositories/remco/epicnext-cms.git/ @@ -37,37 +37,43 @@ jobs: git fetch origin --prune git reset --hard origin/main - # Schoonmaken met behoud van .env en de cruciale Next.js cache map (.next/cache) - # We sluiten expliciet de .next map uit van 'git clean' zodat de build cache overleeft + # Clean untracked files while preserving environment configurations and the Next.js cache (.next/cache) git clean -fd -e .env -e .env.local -e .env.production -e .env*.local -e .next - # Verwijder oude builds, maar BEHOUD de cache-map binnen .next + # Clear old build artifacts but KEEP the cache directory inside .next find .next -mindepth 1 -maxdepth 1 ! -name 'cache' -exec rm -rf {} + 2>/dev/null || true - # 4. Dependencies installeren met de nieuwste PNPM security flags + # 4. Install dependencies with modern PNPM security rules + # PRISMA_SKIP_POSTINSTALL_GENERATE avoids running duplicate prisma client builds export PNPM_CONFIG_ONLY_BUILT_DEPENDENCIES="@parcel/watcher,@swc/core,sharp" + export PRISMA_SKIP_POSTINSTALL_GENERATE=1 pnpm install --frozen-lockfile - # 5. Database & Prisma + # 5. Database migrations & Generate Prisma Client pnpm db:migrate pnpm prisma:generate - # 6. Next.js Build - # NEXT_DISABLE_SOURCEMAPS bespaart enorm veel RAM tijdens de build (fijn voor rustige server-resources) + # 6. Next.js Build (Standalone Mode for Next.js 16 + Turbopack) export NEXT_DISABLE_SOURCEMAPS=1 + export NEXT_TELEMETRY_DISABLED=1 + export UV_THREADPOOL_SIZE=2 pnpm build - # 7. Rechten corrigeren voor de webserver - # Zorgt dat www-data de nieuwe bestanden kan lezen, maar behoudt schrijfrechten voor de deployer + # 6b. Configure Standalone Bundle Paths + echo "Preparing standalone bundle paths..." + # Copy open assets, media, and static CSS/JS to the standalone bundle path + cp -r public .next/standalone/ + cp -r .next/static .next/standalone/.next/ + # Copy the core Prisma directory to the standalone node_modules to ensure database actions work + cp -r node_modules/@prisma .next/standalone/node_modules/ 2>/dev/null || true + + # 7. Correct file ownership and permissions for the www-data web server user sudo chown -R www-data:www-data /var/www/atom-nexst/ sudo chmod -R g+rw /var/www/atom-nexst/ - # 8. Service herstarten en controleren - echo "Hard resetting systemd service..." - sudo systemctl stop atom-nexst.service || true - pkill -f 'next-server' || true - - sudo systemctl start atom-nexst.service + # 8. Restart the Systemd service gracefully (Fast reloads with node server.js) + echo "Restarting systemd service gracefully..." + sudo systemctl restart atom-nexst.service sleep 2 if ! systemctl is-active --quiet atom-nexst.service; then