Skip to main content

Deployments

Normal Deploy (via git push)

All deploys are triggered automatically by CI/CD:

# Deploy to staging
git push origin develop

# Deploy to production (from develop after testing)
git checkout master
git merge develop
git push origin master

The GitHub Actions CI job runs (typecheck + lint + build). If it passes, the deploy job runs automatically.


Monitoring a Deploy

In GitHub Actions: Watch the workflow at github.com/ctsolutions/pcmr-gr/actions.

In Coolify: https://coolify.ctsolutions.gr → Application → Deployments tab.

Container logs during startup:

sudo docker logs <container_name> --follow

A successful API startup shows:

Running database migrations...
Migrations complete. Starting server...
[NestApplication] Nest application successfully started

Force Redeploy (Without Code Changes)

Option 1: Coolify UI → Application → click "Redeploy"

Option 2: Empty commit:

git commit --allow-empty -m "chore: force redeploy"
git push

Option 3: Trigger via Coolify API directly on the server:

curl -X GET \
-H "Authorization: Bearer <COOLIFY_API_TOKEN>" \
"http://localhost:8000/api/v1/deploy?uuid=<COOLIFY_UUID>&force=true"

Use force=true to rebuild from scratch (ignores build cache).


Rolling Back

Coolify does not have a one-click rollback. Options:

Option 1: Revert the git commit and redeploy

git revert HEAD
git push origin master # or develop for staging

This creates a new commit that undoes the changes and triggers a normal CI/CD deploy.

Option 2: Coolify — redeploy a previous deployment

  1. Coolify UI → Application → Deployments tab
  2. Find the last known-good deployment
  3. Click the deployment → "Redeploy this commit"

This redeploys the specific commit without reverting git history.

Option 3: Database rollback (if migration went wrong)

Prisma does not support automatic migration rollbacks. For a bad migration:

  1. Manually write the reverse SQL
  2. Run it against the database: psql -d pcmr_production -c "..."
  3. Mark the migration as "rolled back" in Prisma: prisma migrate resolve --rolled-back <migration_name>
  4. Deploy a code version that doesn't include the bad migration

This is why: Never deploy a migration without testing it on staging first.


Checking Deploy Health

After a deploy, verify:

# Check API is responding
curl https://api.pcmr.gr/health

# Check web is responding
curl -I https://pcmr.gr

# Check container is running
sudo docker ps | grep pcmr

Uptime Kuma at status.pcmr.gr monitors both API and web — check there for a visual indicator.


What To Do When a Deploy Fails

CI job fails (typecheck/lint/build)

Fix the code issue. The deploy won't trigger until CI passes.

Deploy job fails (Coolify webhook not reached)

The self-hosted runner may have lost connection to Coolify. Check:

# On the server
sudo docker ps | grep coolify
sudo systemctl status actions-runner # or similar

Container starts but crashes immediately

Check container logs:

sudo docker logs <container_name> --tail=100

Common causes:

  • Missing required env var — look for "Missing required environment variable" error
  • Database connection failed — check DATABASE_URL
  • Migration failed — look for Prisma migration errors before "Starting server..."
  • Fonts missing — won't crash, but booklets will silently fail (not a startup issue)

Container won't start after migration

If start.sh fails (migration error), the container exits immediately. Check:

  1. Can the API container reach the database? (DATABASE_URL correct, DB running)
  2. Is there a pending migration that conflicts with existing data?
  3. Is start.sh corrupted (CRLF line endings)? See Docker docs — start.sh line endings

Environment Variable Changes

Environment variable changes require a container restart (not just a redeploy):

  1. Update the env var in Coolify UI
  2. Coolify will offer to restart — confirm
  3. The container restarts with the new value

For NEXT_PUBLIC_* variables, a rebuild is required (not just restart) — these are baked into the Next.js bundle at build time.


Docs Deploy

The docs site deploys automatically on every push to master or develop. No special steps needed. The docs build is independent of the main CI job (needs: []).

To check docs deploy status: Coolify UI → Docs application → Deployments tab.