Files
EpicNext-Cms/.gitea/workflows/deploy.yaml
T
remco 087a015f6e
Local Build and Deploy / deploy (push) Successful in 46s
Update .gitea/workflows/deploy.yaml
2026-07-18 14:53:29 +02:00

84 lines
3.5 KiB
YAML

name: Local Build and Deploy
on:
push:
branches:
- main
jobs:
deploy:
runs-on: shell
steps:
- name: Run Deploy Scripts Locally
run: |
set -e
# 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 on deployment crashes
error_handler() {
echo "!!! DEPLOYMENT FAILED on line $1 !!!" >&2
echo "Attempting to keep the current service running..." >&2
sudo systemctl restart atom-nexst.service || true
exit 1
}
trap 'error_handler $LINENO' ERR
# 2. Clean up old system Docker images safely
docker image prune -f
# 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/
git fetch origin --prune
git reset --hard origin/main
# 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
# 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. 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 migrations & Generate Prisma Client
pnpm db:migrate
pnpm prisma:generate
# 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
# 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. 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
echo "ERROR: atom-nexst.service failed to start!" >&2
exit 1
fi
echo "--- Deployment successfully completed ---"