Self-hosting without Coolify
Two commands run SHADE on a Linux server of your own: shade install sets it up once, and shade update moves it to a
new version. They run SHADE's containers (admin, public and worker, or one all container with --small), its
Postgres and Redis, and Caddy in front for HTTPS. Self-hosting by hand explains every
part, for a proxy of your own or a server without Docker.
On NixOS, the flake runs SHADE without Docker (experimental).
What you need
- A Linux server with Docker and its Compose plugin (2.23.1 or newer), and root.
- A domain for SHADE's API (
api.example.com), and optionally one for the admin (admin.example.com) and one for the site (www.example.com). Point their DNS (A and AAAA records) at the server. - Ports 80 and 443 free, and open to the internet: Let's Encrypt checks each domain on port 80. Open 443 over UDP too, for HTTP/3: a firewall at your provider (Hetzner's cloud firewall, for example) usually blocks UDP until you allow it. Without it browsers still connect over HTTP/2.
Installing
SHADE has pre-releases only; 0.1.0 isn't out. The commands here use 0.1.0-next.2: take the newest version in the
changelog. Get the shade script from SHADE's image, then run it:
docker run --rm ghcr.io/shadehq-dev/shade:0.1.0-next.2 cat deploy/shade | sudo install -m 755 /dev/stdin /usr/local/bin/shade
sudo shade install --version 0.1.0-next.2 --api-domain api.example.com --email ops@example.com \
--admin-domain admin.example.com --site-domain www.example.com
To run code that isn't released, build the image from a checkout of the SHADE
workspace (for SHADE's maintainers for now; a
tested route for everyone else comes later) and pass it with --image:
docker build -f shade/apps/api/Dockerfile -t shade:local shade
sudo install -m 755 shade/deploy/server/shade /usr/local/bin/shade
sudo shade install --image shade:local --api-domain api.example.com --email ops@example.com
shade install:
- Checks the server: Docker and Compose, ports 80 and 443 (and 443 over UDP), Docker starting at boot, a
firewall, and with
--programsgVisor and the networks client programs need. - Writes
/etc/shade, with new passwords and a newAPP_SECRET. It never writes over a file that is there: run it again with--forceto write the compose file and the Caddyfile again; even then it keeps every secret. - Starts everything and waits until each container is healthy, Caddy last, so the first request after your DNS points here never meets an admin that is still starting.
- Makes the first admin: it asks for your email, name and password.
Its other options: --small runs the small profile, one container for everything (what that gives
up); --staging takes certificates from Let's Encrypt's staging, for a trial run;
--no-admin skips the first admin: you then create the owner's account in the browser, with the one-time code in the
admin container's log (docker compose logs | grep create-owner in /etc/shade), as on
Coolify.
What it sets up
In /etc/shade | What it is | Readable by |
|---|---|---|
shade.env | SHADE's env file: the running role's address (DATABASE_URL, as shade_app) and Redis's, with their passwords, APP_SECRET, the domains | SHADE's containers (uid 1000), mode 600 |
shade-owner.env | One line, DATABASE_OWNER_URL, the owner's address | The admin container only (uid 1000), mode 600 |
shade-backup.env | One line, DATABASE_BACKUP_URL, the backup role's address | The worker container only (uid 1000), mode 600 |
postgres-password, shade-db-password, shade-db-owner-password, shade-db-backup-password, rehearsal-password | Postgres's passwords: its own, the running role's (shade_app), the owner's, the backup role's and the restore rehearsal's | Postgres (uid 70), mode 600 |
redis.conf | Redis's settings and password | Redis (uid 999), mode 600 |
compose.yml | The containers, copied from SHADE's image | root |
compose.override.yml | Your own containers, such as the site: never written again | root |
.env | The settings Docker Compose reads: the image, the domains, the profile. No secret | root |
caddy/Caddyfile | Caddy's settings and SHADE's routes (the folder is Caddy's /etc/caddy) | root, read by Caddy |
caddy/Caddyfile.local | Your own additions to the proxy: never written again | root, read by Caddy |
caddy/lb-cookie | One line that sets the admin's stickiness cookie, with the secret it is keyed with (the Caddyfile imports it): kept by --force and shade update | Caddy (uid 1001), mode 600 |
caddy-data/ | The certificates and the Let's Encrypt account key | Caddy (uid 1001), mode 700 |
SHADE_ENV_FILE lists the files a container reads, separated by commas: the admin reads shade.env and
shade-owner.env, the worker shade.env and shade-backup.env, the public container shade.env only, and the small
profile's shade container all three.
No secret is in a container's configuration: SHADE reads its env file, Postgres and Redis read their files, so
docker inspect shows none. Only Caddy publishes ports, 80 and 443 (443 over UDP as well, for HTTP/3); SHADE's containers are reached only through it.
Caddy gets no Docker socket and reads its routes from the Caddyfile. Its admin API listens on a socket inside its
own container, never on a port, so nothing else on the server or the network can change its routes. Every container
keeps at most 30 MB of logs.
SHADE's routes are defined once, in SHADE, and the Caddyfile is written from them. With the three domains above it
reads:
# Written by SHADE (`shade install`, `shade update`) from its routes (apps/api/src/deploy/routes.ts). Do not edit:
# the next update writes it again. Your own additions go in Caddyfile.local, which is never written.
{
email ops@example.com
acme_ca https://acme-v02.api.letsencrypt.org/directory
storage file_system /data
admin unix//run/caddy/admin.sock
http_port 8080
https_port 8443
servers {
timeouts {
read_header 30s
read_body 600s
idle 5m
}
}
log {
level WARN
}
}
api.example.com {
encode zstd gzip
header Alt-Svc `h3=":443"; ma=2592000`
handle_errors {
@starting0 expression `{err.status_code} in [502, 503] && {http.request.method} in ["GET", "HEAD", "OPTIONS"]`
handle @starting0 {
header Retry-After 5
header Content-Type "application/json"
respond `{"error":{"code":"UNAVAILABLE","message":"SHADE is starting up. Try again in a moment.","key":"api.errors.starting"}}` 503
}
@unanswered0 expression `{err.status_code} in [502, 503]`
handle @unanswered0 {
header Content-Type "application/json"
respond `{"error":{"code":"BAD_GATEWAY","message":"The server didn't answer. Check before trying again."}}` 502
}
}
handle /api/v1/account/* {
reverse_proxy {
dynamic a public 4000 {
refresh 1s
}
lb_try_duration 15s
lb_try_interval 50ms
lb_retry_match {
method GET HEAD OPTIONS
}
fail_duration 1s
stream_close_delay 5m
}
}
handle {
reverse_proxy {
dynamic a admin 4000 {
refresh 1s
}
lb_try_duration 15s
lb_try_interval 50ms
lb_retry_match {
method GET HEAD OPTIONS
}
fail_duration 1s
stream_close_delay 5m
}
}
}
admin.example.com {
encode zstd gzip
header Alt-Svc `h3=":443"; ma=2592000`
handle_errors {
@starting0 expression `{err.status_code} in [502, 503] && path('/api/*') && {http.request.method} in ["GET", "HEAD", "OPTIONS"]`
handle @starting0 {
header Retry-After 5
header Content-Type "application/json"
respond `{"error":{"code":"UNAVAILABLE","message":"SHADE is starting up. Try again in a moment.","key":"api.errors.starting"}}` 503
}
@unanswered0 expression `{err.status_code} in [502, 503] && path('/api/*')`
handle @unanswered0 {
header Content-Type "application/json"
respond `{"error":{"code":"BAD_GATEWAY","message":"The server didn't answer. Check before trying again."}}` 502
}
@starting1 expression `{err.status_code} in [502, 503] && {http.request.method} in ["GET", "HEAD", "OPTIONS"]`
handle @starting1 {
header Retry-After 5
header Content-Type "text/plain; charset=utf-8"
respond "Starting, back in a moment." 503
}
@unanswered1 expression `{err.status_code} in [502, 503]`
handle @unanswered1 {
header Content-Type "text/plain; charset=utf-8"
respond "The server didn't answer. Check before trying again." 502
}
}
handle {
reverse_proxy {
dynamic a admin 4000 {
refresh 1s
}
import /etc/caddy/lb-cookie
lb_try_duration 15s
lb_try_interval 50ms
lb_retry_match {
method GET HEAD OPTIONS
}
fail_duration 1s
stream_close_delay 5m
}
}
}
www.example.com {
encode zstd gzip
header Alt-Svc `h3=":443"; ma=2592000`
handle_errors {
@starting0 expression `{err.status_code} in [502, 503] && (path('/api/v1/account/*')) && {http.request.method} in ["GET", "HEAD", "OPTIONS"]`
handle @starting0 {
header Retry-After 5
header Content-Type "application/json"
respond `{"error":{"code":"UNAVAILABLE","message":"SHADE is starting up. Try again in a moment.","key":"api.errors.starting"}}` 503
}
@unanswered0 expression `{err.status_code} in [502, 503] && (path('/api/v1/account/*'))`
handle @unanswered0 {
header Content-Type "application/json"
respond `{"error":{"code":"BAD_GATEWAY","message":"The server didn't answer. Check before trying again."}}` 502
}
}
handle /api/v1/account/* {
reverse_proxy {
dynamic a public 4000 {
refresh 1s
}
lb_try_duration 15s
lb_try_interval 50ms
lb_retry_match {
method GET HEAD OPTIONS
}
fail_duration 1s
stream_close_delay 5m
}
}
handle {
reverse_proxy http://site:8080
}
}
import /etc/caddy/Caddyfile.local
Each SHADE reverse_proxy finds every container of a role by its name, once a second (dynamic a), so a second
public or admin container started beside the first is used, and none once it is gone.
Caddy runs no health check of its own for those. A container takes requests once it is ready, because it opens the port
Caddy uses (4000) only then, and it closes that port when it has drained. A refused connection therefore always means
nothing was sent, and Caddy leaves that container out for a second and sends the request to another, or holds it up to
15 seconds until one answers, for every method. A reset on a connection Caddy reused is sent again for GET, HEAD and
OPTIONS only.
The admin's own domain keeps a browser on one admin while two run, with a cookie called shade_admin, so a page never
asks the other version for a file. The cookie is keyed with a secret of the server's own, kept in caddy/lb-cookie (made by
shade install, readable by Caddy alone), so its value says nothing about the container. The API domain's uploads, content API and MCP get no
cookie, which keeps them cacheable; an admin without a domain of its own has no such stickiness. stream_close_delay 5m keeps sockets and live streams open for up to five minutes when Caddy reloads this file.
When no SHADE container answers, a visitor gets a short answer in place of Caddy's bare 502. A GET, HEAD or
OPTIONS request is told "Starting, back in a moment." with Retry-After (in the API's error shape on the API paths,
as text on the admin's screens; where the admin has no domain of its own, the API's domain answers in the API's error shape while the admin starts). Any other method gets a 502, "The server didn't answer. Check before trying again.",
without Retry-After: the request may have reached the container before it went, so the client should check before it
sends it again. Your own site's container, behind Caddy, answers for itself.
Caddy starts HTTPS for each domain by itself and redirects HTTP to it. It sets X-Forwarded-For, -Proto and -Host
from the connection it saw and never takes them from a client, and it compresses text answers with zstd or gzip. The
last line imports caddy/Caddyfile.local, the file for your own additions (another site, a header, a redirect). shade install creates it with one comment line and shade update never writes it, as with compose.override.yml. After a change there, run
shade update or reload Caddy on its own:
cd /etc/shade && docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile --address unix//run/caddy/admin.sock
The site is yours to add: put its container in compose.override.yml under the name site, listening on 8080
(Self-hosting by hand shows one). Its domain's account API goes to SHADE's
public container, so visitors' sign-in stays on the site's own domain.
The firewall. Docker opens the ports it publishes past ufw and firewalld. That is why SHADE publishes only 80
and 443; allow SSH in the firewall and nothing else. A firewall at your provider sits in front of Docker, so it has to
allow 80 and 443 over TCP and 443 over UDP itself.
HTTP/3. Caddy answers over HTTP/2 and HTTP/3 on 443 and tells browsers about HTTP/3 in the Alt-Svc header. A
browser that can't reach UDP 443 stays on HTTP/2, so a blocked port costs speed on slow mobile networks, nothing else.
Hetzner's cloud firewall, like most cloud firewalls, lets nothing in until a rule says so: add a rule for UDP 443 beside
the ones for TCP 80 and 443, or every browser stays on HTTP/2 without an error to tell you.
Behind Caddy, SHADE's containers speak HTTP/1.1, which is all that hop on the same server needs.
The database's roles
SHADE connects to Postgres as three roles instead of one, so that a leaked address of the running instance reaches its rows and nothing else. None is a superuser, and none may create databases or roles or replicate.
| Role | Address | What it does |
|---|---|---|
shade_app, the running role | DATABASE_URL, every container | Runs every request, job and process. It owns nothing and has no BYPASSRLS, so row-level security applies to it. It reads and writes the rows of every table, including the tables of later migrations and of modules, and cannot create, alter or truncate a table |
shade, the owner | DATABASE_OWNER_URL, the admin container and the console | Owns the database and every table, and alone changes the schema: core's and the modules' migrations, the backup taken before them, and the console's migrate and restore (run in the admin container) |
shade_backup, the backup role | DATABASE_BACKUP_URL, the worker only | Reads every row (BYPASSRLS), and every one of its transactions is read-only. It runs the worker's pg_dump and the backup's snapshot |
The public container never holds the owner's address, and the worker and the public container drop it whatever their
host gives them; the public and admin containers likewise drop the backup role's. With backups on (SHADE_BACKUP_URL),
the worker needs DATABASE_BACKUP_URL; MIGRATE_ON_START on the admin needs DATABASE_OWNER_URL. Both addresses must
name the same host, port and database as DATABASE_URL. The image's bootstrap superuser, postgres, is used only by
the script that makes the roles, once, on an empty volume.
SHADE refuses to start when the role in DATABASE_URL is a superuser, has BYPASSRLS or owns a table, and says so:
DATABASE_URL connects as a role that may not run SHADE. The doctor's database-role check reports the
same problems. Put the owner's address in DATABASE_OWNER_URL and the backup role's in DATABASE_BACKUP_URL.
Row-level security
Every table belongs to one part of SHADE, or to one module, and Postgres lets the running role touch its rows only when SHADE runs the statement as that owner. A part that needs another's rows asks that part, so a bug in one part can't read or change another's data, and a statement SHADE didn't scope at all sees no rows and writes none.
The owner switches row-level security on and writes the policies after every migration run: the admin container with
MIGRATE_ON_START, the console's migrate, and installing or updating a module. They are written again from SHADE's
own declarations and the installed modules' each time, never kept in the migration history, so there is nothing to
maintain by hand: the console's migrate writes the modules' policies and views exactly as the admin's start does. A
run that would write what the last one wrote changes nothing and locks no table, and one that must wait more than ten
seconds for a table's lock (a long report reading it, say) stops, and the start with it, rather than hold every
request behind it; start again once the table is free. If a table
has it off (a table made by hand, or a database restored without the policies), every container refuses to start
and names the tables: run node console/migrate.mjs in the admin container. The doctor's
row-security check says the same.
Modules read a few columns of core's tables inside their own statements, such as an account's id and address for "the signed-in customer's orders". They get those through three views the owner makes in the same step (two of accounts and organisation members, one of the trash), each showing only those columns and only to the modules that need them. They never get the accounts table itself, so no module can read a password hash or a session.
The backup role bypasses row-level security on purpose, since pg_dump must read every row. One table is left open
to every part for reading: the search index, whose policy made search several times slower; the search service is its
only way in and checks the owner itself, and only search writes it.
A database made before the three roles cannot be converted: set the instance up again with a fresh database (nothing is
live before 0.1.0). shade install, the deployment template, the NixOS module and Self-hosting by
hand make the roles themselves on a new database.
From staging to real certificates
A server installed with --staging serves certificates from Let's Encrypt's staging, which browsers don't trust. To
switch to real ones, run the installer again without --staging, with the same domains and email:
sudo shade install --api-domain api.example.com --email you@example.com --image <the image it runs> --force
--force writes the Caddyfile again and keeps every secret. Because the certificate authority changed, shade restarts
Caddy instead of reloading it (a reload would keep serving the staging certificates it already holds), and Caddy then
asks Let's Encrypt for real ones. Give it a minute, then run shade doctor. The staging certificates stay in
/etc/shade/caddy-data, unused. The same restart happens in shade update when a new release changes the directory.
Updating
sudo shade update --version 0.2.0
Read the changelog first. shade update pulls the new image, writes the compose file
and the Caddyfile again from it, and pulls the Caddy, Postgres and Redis versions that release pins. It checks that
Caddy can read the new Caddyfile and replaces the live one only then (one that fails leaves the live one as it
was), then reloads it without dropping a connection (when the release restarts Caddy anyway, the recreated Caddy reads the new file instead, at the end). Then it updates SHADE's containers one at a time, the
admin first (it migrates), and for each one starts a second container on the new image beside the old one. Once the new
one is healthy (/health) the old one is stopped, after the requests it was serving have finished, and Caddy sends
everything to the new one. On the small profile the one shade container is updated the same way. When a new container
is not healthy within 15 minutes (--timeout) it is removed, the old one keeps serving and the update stops there with
what the container said. The containers after it keep running the previous image.
Two containers of one role need memory for about a minute: up to the container's limit again (512 MB for the admin,
public and worker, 768 MB on the small profile). Before it starts a second container, shade update reads the memory
the server has free. With less than that, or when it cannot read it, it warns and recreates that container in place
instead, which leaves a gap of a few seconds to a minute for that role. When an earlier update that stopped halfway left
two containers of a role, it keeps the one that is current once it is healthy and stops the other; it recreates in place
only when none of them is current.
Postgres, Redis and Caddy cannot be updated without a gap on one server. shade update says before it starts which of
them the release restarts, and what that costs (a few seconds of errors for Postgres, the loss of what Redis holds,
dropped connections for Caddy), and does it last, after SHADE's containers, with Caddy at the very end. Most releases
change none of them. Because they restart after the new admin has migrated the database, a release whose migrations need a
newer Postgres says so in its notes.
Without --version it pulls the image it runs again. The shade script updates itself from the new image.
When an update stops halfway
After a stop the admin may already run the new image, and it may have migrated the database, while .env still names the
previous image: .env only changes once every container runs the new one. The new settings wait in /etc/shade/.env.new.
Fix what the container's log says, then roll forward with the command shade printed:
sudo shade update --image <the new image>
Plain shade update does the same while .env.new is there: it goes on with the image the stopped update was moving to,
never back to the one .env names. docker compose up -d is not a recovery: it starts the admin on the image .env
names, under a database the new image already changed.
To go back, run shade update --image <the previous image>. If the new admin already migrated the database, the old image
doesn't undo that: restore the backup taken before migrating first. A
successful update, or a successful run of the previous image, removes .env.new.
Requests while it runs
While a role has two containers, Caddy sends each request to whichever is ready, and a request that reaches the one being stopped goes to the other. Requests already running on the container being stopped finish first, within its stop grace (two minutes for the admin, whose uploads can be long); a longer upload fails and is tried again. Where there was no memory for a second container, the role is recreated in place: Caddy holds a request that arrives meanwhile for up to 15 seconds and sends it on once a container answers, so a restart of seconds shows up as a slow request, not an error, and one that takes longer ends in the "Starting, back in a moment." answer for the requests that waited that long. A restart of Postgres or Redis gives a few seconds of errors, and while Caddy itself restarts nothing answers at all, so connections drop and new ones are refused until it is back. Schedule an update for a quiet hour all the same.
What is without a gap, and what is not
A normal update has no gap for the requests of visitors and the team: the admin, public and worker each get a second
container, and the old one stops only once the new one is healthy. Four things are not covered by that.
- The restart of Postgres, Redis or Caddy, when a release pins a new version of one of them.
shade updatenames these before it starts. - A role recreated in place because the server lacks the memory for a second container.
- Uploads that run longer than the admin's two minutes of stop grace, and streams or sockets that were open on the container being stopped. Both are cut and come back on their own once the page reconnects.
- A release that needs maintenance, below.
Migrations only add
While the new admin migrates the database, the old public and worker containers still run, on the new tables. So a
release's migrations only add: new tables, new columns that are empty or have a default, new indexes. Dropping or renaming
a table or column, changing a column's type, adding NOT NULL without a default, and adding a constraint that the old
version's writes would break all wait for a later release, which does it once no running version still reads the old
shape. The same holds for the shape of queued jobs and of what SHADE keeps in Redis: the new version reads the old, and
the old version tolerates the new.
SHADE checks this on every pull request (pnpm migrations:add-only, over the migrations added since the last release
tag). Core's migrations are checked in SHADE's repository, and a module's where the workspace holds the module next to
it; a module's own repository does not run the check yet. A migration that was already released and is edited, deleted or
renamed fails too. Dropping a constraint or a unique index is flagged, since old writes may rely on it. A step that drops
something on purpose says in a comment which release stopped using it. Releases up to 0.1.0 are not checked: nothing runs
on them yet.
A release that needs maintenance
Now and then a change cannot wait a release: a conversion of stored data in place, a rename the old version cannot do
without. Such a release is marked "needs maintenance" in its release file, and the changelog
says why. shade update refuses it. With a made-up release 0.3.0 as the example:
This update needs maintenance: the release notes mark 0.3.0 as breaking (its migrations cannot run while the old version serves). No running container was changed.
Run it again with --maintenance: shade update --image ghcr.io/shadehq-dev/shade:0.3.0 --maintenance
Take a backup first, then run the same update with the flag:
sudo shade update --version 0.3.0 --maintenance
With the flag, shade switches maintenance mode on before the admin starts (visitors get SHADE's
"back soon" answer, static pages stay up, admins keep working), recreates each container in place, so the old version never
runs beside the new (the worker is stopped first, public keeps serving), and switches maintenance mode off once every
container is healthy. Maintenance mode is always off at the end, even if it was on before you started. The flag also works
on a release that is not marked, when you want the quiet anyway. If an update under maintenance stops halfway, maintenance mode stays on while you
fix the cause. The command it prints to roll forward includes --maintenance, and the run that succeeds switches it off. If
it cannot, it says so, still finishes the update and gives the command: docker compose exec admin node console/maintenance.mjs off
in /etc/shade (docker compose exec shade … with --small).
Checking
sudo shade doctor
The doctor, run in the admin container, with the server's checks: each domain's certificate (trusted,
and valid for 14 days more), each domain and /health answering through Caddy, Caddy's admin API out of reach, and the
server's clock synchronised.
Backing up
Back up /etc/shade whole, encrypted and away from the server: shade.env holds APP_SECRET, without which the
secrets stored in the database cannot be read, and caddy-data/ holds the certificates and the Let's Encrypt account. caddy/Caddyfile.local holds your own proxy
settings. The
database and the media are SHADE's built-in backups: set
SHADE_BACKUP_URL and SHADE_BACKUP_KEY in shade.env, then cd /etc/shade && docker compose up -d.
Later: public domains for client services
Not built yet. Client programs may get public domains of their own. The way in is a route added to Caddy while it runs. The admin socket is Caddy's own today; sharing it with the admin container is the later work:
- A route goes in only for a domain an admin approved, and only after SHADE checked that the domain's DNS points at this server. A domain that doesn't point here fails its check again and again, until Let's Encrypt's limit on failed checks (5 an hour per domain) stops every new certificate for it.
- Caddy asks SHADE before it requests a certificate for a name (
on_demand_tls), so a domain nobody approved gets none, even when its DNS points at the server.