Documentation

Deployments

Getting a change onto the server predictably, and — more importantly — getting back off it when the change turns out to be wrong.

What this page is

The patterns below are general and apply to most hosting setups. The specific deploy target for your account — repository, branch, build command, and whether deploys are triggered by a push or run by you — is configured during onboarding and appears here as a placeholder. Confirm yours before adapting any command on this page.

Three properties worth having

Almost every deployment problem traces back to one of these being absent.

  • Identifiable. You can say exactly which commit is running in production right now, without guessing. A version endpoint, a build file, or a release directory named after the commit all achieve this.
  • Repeatable. The same input produces the same deployed result. This means pinned dependency versions, a lockfile committed to the repository, and a pinned runtime version — not "whatever the latest was on the day it built".
  • Reversible. There is a known, rehearsed way back to the previous state, and it does not depend on rebuilding anything. A rollback you have never performed is a plan, not a capability.

Git-based deploys

The repository is the source of truth: a designated branch reflects what should be running, and the server fetches, builds, and restarts. This is the recommended default because it gives you identifiability for free — every deployed state is a commit.

Branch strategy

  • One long-lived branch represents production. Deploys happen when it moves.
  • Work happens on short-lived branches merged in after review.
  • Nobody force-pushes the production branch. A force-push rewrites the history that rollback depends on.
  • Tag releases if you want a stable human-readable name: git tag -a v1.4.0 -m "…" && git push --tags.

The release-directory pattern

Deploying by pulling into the live directory means the site is half-old and half-new for the duration of the build. Building into a fresh directory and switching a symlink makes the change effectively atomic — the switch is a single filesystem operation.

/srv/app/
├── releases/
│   ├── 2026-09-21T14-02-11-a1b2c3d/
│   ├── 2026-09-27T09-40-55-e4f5a6b/
│   └── 2026-09-29T11-15-03-9c8d7e6/   ← just built
├── shared/                             ← persists across releases
│   ├── .env
│   ├── uploads/
│   └── logs/
└── current -> releases/2026-09-29T11-15-03-9c8d7e6

The switch itself, done so it is atomic rather than delete-then-create:

# ln -s then mv -T replaces the symlink in one operation —
# there is no moment where "current" does not exist
ln -sfn /srv/app/releases/$NEW_RELEASE /srv/app/current.tmp
mv -Tf /srv/app/current.tmp /srv/app/current

# then reload the application so it picks up the new path
sudo systemctl reload your-app.service

Anything that must survive a deploy — uploaded files, the environment file, logs — lives in shared/ and is symlinked into each release. Anything inside a release directory is disposable by definition.

Keeping old releases

Retain several previous releases so rollback is a symlink switch rather than a rebuild. Five is a common figure; prune beyond that so disk usage stays bounded. Releases retained on this platform: confirm during onboarding.

If deploys are triggered by a hook

A post-receive hook on a bare repository, or a CI job watching the branch, both work. Two things matter regardless of which:

  • The build must be able to fail the deploy. If the build step errors and the switch happens anyway, you have automated breaking production. Check exit codes and stop on the first failure.
  • The deploy must be logged. What was deployed, from which commit, by whom, and when. When something breaks at 02:00, this log is the first thing anyone asks for.

Manual uploads

Appropriate for static output, or a build produced on a machine the server cannot reach. Two rules keep it from becoming a mess:

  • Upload build output, never edit files in place on the server. An in-place edit exists nowhere else, will be silently destroyed by the next deploy, and cannot be reviewed.
  • Upload from a clean build, not from a working directory with uncommitted changes — otherwise the deployed state does not correspond to any commit.

rsync

Preferable to dragging files over SFTP: it transfers only what changed, preserves timestamps, and will tell you exactly what it intends to do first.

# 1. Always dry-run first and read the output
rsync -avz --delete --dry-run \
  ./dist/ user@your-server-hostname:/path/to/webroot/

# 2. If the list is what you expect, run it for real
rsync -avz --delete \
  ./dist/ user@your-server-hostname:/path/to/webroot/

Two details that bite people:

  • The trailing slash on the source matters. ./dist/ copies the contents of dist; ./dist copies the directory itself, creating webroot/dist/.
  • --delete removes server-side files absent locally. Correct for a pure build output directory. Destructive if user uploads, logs, or a config file live in the same tree — exclude them explicitly with --exclude, or keep them elsewhere.

Verifying an upload landed intact

# Compare a checksum of a known file on both sides
sha256sum ./dist/index.html
ssh user@your-server-hostname "sha256sum /path/to/webroot/index.html"

Database migrations

Migrations are the part of a deploy that rollback cannot undo by itself. A symlink switch reverses instantly; a dropped column does not.

  • Take a backup immediately before migrating. Not last night's — one from just before this change. See Backups & Restore.
  • Prefer additive migrations. Add a column, deploy code that writes both old and new, backfill, deploy code that reads the new one, and only then remove the old — across separate deploys. Each step is independently reversible.
  • Never combine a destructive migration with a risky code change. If you have to roll back, you want exactly one thing to reason about.
  • Write the down-migration and test it on a copy before you need it.
  • Watch for locks on large tables. A migration that is instant on a development database can hold a lock for minutes on a production one. Check the approach your database takes for that specific operation before running it live.

Pre-deploy checklist

  • Tests pass on the exact commit being deployed, not on a similar one.
  • The build succeeds from a clean checkout — no reliance on a file only present on your machine.
  • Any new environment variable is already set on the server. Code that reads a missing variable usually fails at the worst moment rather than at startup.
  • Migrations are reviewed, and a fresh backup exists if any are destructive.
  • You know which commit is currently live, so you know what rolling back means.
  • Someone is available to watch the deploy. Deploying immediately before going offline is how a five-minute problem becomes an overnight one.
  • The change has been through review. This catches more production incidents than any amount of tooling.

Post-deploy verification

A deploy command exiting zero means the deploy ran, not that the application works. Check the application.

# Does it respond, and with the status you expect?
curl -sS -o /dev/null -w "%{http_code} %{time_total}s\n" https://example.com/

# Is the version you expect actually running?
curl -sS https://example.com/your-version-or-health-endpoint

# Is the service healthy and not restart-looping?
ssh user@your-server-hostname "systemctl status your-app.service --no-pager"

# Anything new in the logs since the deploy?
ssh user@your-server-hostname "journalctl -u your-app.service --since '10 min ago' -p warning --no-pager"

Then check the things a health endpoint does not cover: a page that hits the database, a form submission, and a logged-in view if the application has one. Static assets are a common casualty of a build change and will not show up as a failed request in your own cached browser.

Rollback

Decide first, diagnose second

If production is broken, roll back and investigate afterwards on a copy. Debugging forward under pressure reliably takes longer than returning to a state that worked, and every minute spent on it is a minute of outage.

If you use release directories

This is the fastest and least risky form — no rebuild, no network fetch:

# What is live, and what is available to go back to?
ls -1t /srv/app/releases/ | head -5
readlink -f /srv/app/current

# Point at the previous release and reload
ln -sfn /srv/app/releases/PREVIOUS_RELEASE /srv/app/current.tmp
mv -Tf /srv/app/current.tmp /srv/app/current
sudo systemctl reload your-app.service

If you deploy from git

Revert the commit rather than force-pushing the branch backwards. A revert is itself a commit — it goes through the normal pipeline, leaves the history intact, and does not break anyone else's checkout.

# Find the offending commit
git log --oneline -10

# Create a commit that undoes it, then deploy normally
git revert COMMIT_SHA
git push origin main

# For a merge commit, name the mainline parent
git revert -m 1 MERGE_COMMIT_SHA

Note that a revert still goes through the build, so it is slower than a symlink switch and it can fail for the same reasons any deploy can. If the build itself is the problem, the release-directory route is the one that works.

If the release included a database migration

Reverting the code does not revert the schema. Work out which of these you are in before doing anything:

  • The migration was additive — old code ignores the new column. Roll the code back and leave the schema alone. This is why additive migrations are worth the extra deploy.
  • The migration was destructive and a tested down-migration exists — roll the code back, then run the down-migration.
  • The migration was destructive and no down-migration exists — restoring from backup is now involved, and any data written since the deploy is at risk. Stop, and contact support before taking further action. A hurried second decision here is what turns an outage into data loss.

Afterwards

Once the site is stable, write down what happened while it is fresh: what changed, how it was noticed, what fixed it, and what would have caught it earlier. Anything that affected data, availability, or access should also be reported — see Incident reporting.