Space Works Machines · Install and run

Deploying on a server (VPS)

The bundled deployment runs the whole platform on one Linux server with Docker Compose: the curl installer, setup.sh, scripts/update.sh and scripts/spaceworks-compose.sh bundled, the same tooling as the other Space Works apps. Assume a dedicated server: the installer's Caddy takes ports 80 and 443.

Install

curl -fsSL https://raw.githubusercontent.com/SpaceWorks-Labs/SpaceWorks-Machines/main/install.sh | bash

The installer checks the host (architecture, distribution, Docker, disk space, an existing install), asks which GitHub repository to follow, downloads the newest published main release into temporary storage and asks the deployment questions: whether this server also serves the website, the HTTPS mode, the domain, bundled or external file storage, the super admin's email and password, and the SMTP relay. Nothing changes until you confirm the summary. Then it installs missing packages (Docker Engine, the Compose plugin, curl, tar), copies the release to /opt/spaceworks-machines and runs setup.sh, which:

  1. writes the owner-only .env with every generated secret (scripts/setup-write-environment.sh);
  2. pulls the release images (or builds them with bash setup.sh --build);
  3. creates a private CA and service certificates for PostgreSQL, Redis and Silo in tls/ (deploy/certificates.sh, run inside the backend image so the host needs no openssl);
  4. starts the stack with up --wait and runs the operator checks (--role ops);
  5. installs the optional GitHub Actions runner.

Options: --repo owner/name (or SWM_REPOSITORY), SWM_DIR=/path for another install directory, --help.

What runs

scripts/spaceworks-compose.sh bundled always uses docker-compose.prod.yml, the install's .env, the project name swmach, and the overlays the settings select:

Setting in .env Overlay Effect
SWM_LAYER='none' none Caddy serves http://<host> on port 80 (plain HTTP, LAN or trial).
SWM_LAYER='tls' docker/compose.tls.yml Caddy obtains Let's Encrypt certificates and also serves 443 (TCP and QUIC).
SWM_LAYER='proxy' docker/compose.proxy.yml No Caddy; the app listens on 127.0.0.1:8080 for your proxy.
SWM_STORAGE='external' docker/compose.external-storage.yml No Silo; files go to the S3_* bucket.
SWM_COMPOSE_BUILD_LAYER=1 (shell) docker/compose.build.yml Builds the backend image from the checkout.
Service Image Role
db postgres:16-alpine TLS only (hostnossl … reject), owner role swmach, runtime role swmach_app with data rights only
redis redis:7-alpine TLS only, password, append-only file
minio pgsty/silo TLS only, private bucket spaceworks-machines, versioning on
createbuckets pgsty/mc Creates the bucket and the swmach-app identity limited to it, then exits
migrate backend, --role migrate prisma migrate deploy as the owner role, then exits
backend backend, --role backend The app and API (Next.js) as swmach_app
worker backend, --role worker BullMQ worker (dist/worker.js): email and chat delivery, retention and every job in lib/queue/registry.ts; health on :3460/health
beat backend, --role beat BullMQ beat (dist/beat.js): keeps the repeatable schedules in Redis (outbox every minute, retention hourly); health on :3460/health
backup, backup-storage postgres:16-alpine, pgsty/mc Scheduled database dumps and bucket mirror into backups/
caddy locally built spaceworks-caddy:2.11.7-security-20261029 Standard Caddy with patched Go/dependencies and Alpine packages; blocks /api/internal/*; overwrites X-Real-IP
ops (profile tools) backend, --role ops Operator checks, run on demand

The data services sit on an internal network with no route to the internet. The backend, worker and beat also join the edge network, so they can reach SMTP relays, payment gateways and chat services. Only Caddy publishes ports.

Silo and its separate mc utility use digest-pinned October 26 releases. Setup and upgrades build the patched edge locally, including when the app images are pulled from a published release. Its small independent build context is docker/caddy/; the standard-module graph, security changes and remaining upstream v3 advisory are documented in its build notes. Allow at least 4 GiB RAM with swap and headroom for app/data services during upgrades. The measured edge build peaked at 2.21 GiB for the whole BuildKit cgroup with two CPUs; published-app installations still compile this independent edge image.

scripts/spaceworks-compose.sh bundled ps
scripts/spaceworks-compose.sh bundled logs -f backend worker beat
scripts/spaceworks-compose.sh bundled run --rm ops      # TLS, roles, migrations, Redis, bucket, readiness

Files on the server

Path Contents
/opt/spaceworks-machines/ The installed release (compose files, deploy/, scripts/)
.env Every setting and secret (mode 600). Back it up encrypted, off the server.
tls/ The private CA (ca.key never leaves this folder) and the service certificates
backups/ Database dumps, the bucket mirror, settings archives, replaced host files
.spaceworks-version, .spaceworks-previous-version The running release and the one before it

Backups and restore

  • Scheduled: the backup service dumps the database every BACKUP_INTERVAL_HOURS (24) to backups/scheduled-<time>.sql.gz and keeps BACKUP_RETENTION_DAYS (14); backup-storage mirrors the bucket to backups/storage.
  • On demand: bash scripts/backup.sh (also the installer's menu option 2) writes a dump, refreshes the bucket mirror and archives .env and tls/ to backups/config-<time>.tar.gz.
  • Before every update: backups/pre-update-<time>.sql.gz.

Backups contain every secret. Copy them off the server, encrypted, for example tar -czf - backups | gpg --symmetric > swmach-backups.tar.gz.gpg.

bash scripts/restore.sh backups/scheduled-20261020T020000Z.sql.gz                 # database only
bash scripts/restore.sh backups/manual-20261020T090000Z.sql.gz --with-storage     # and the files

Restore asks you to type RESTORE, stops the app, worker, beat, edge and backup schedulers, takes a fresh pre-restore dump and replaces the schema in one transaction. It optionally copies the files back, runs migrations explicitly, starts serving processes and checks readiness before resuming either scheduler. Failure before database commit restarts the original serving processes with schedulers kept stopped. Failure after commit leaves serving processes and schedulers offline; fix the cause and retry. Preserve the complete recovery archive until the restored installation has been checked.

New server: obtain the same release sources/images and recover the old .env, tls/, database dump and backups/storage from the encrypted archive. Start only the data services and schema migration:

scripts/spaceworks-compose.sh bundled up -d --wait db redis minio
scripts/spaceworks-compose.sh bundled run --rm --no-deps -T createbuckets
scripts/spaceworks-compose.sh bundled run --rm --no-deps -T migrate
bash scripts/restore.sh backups/manual-20261020T090000Z.sql.gz --with-storage

For external storage omit minio and the createbuckets command and restore files through the provider. Bucket initialization and migrations are one-shot jobs; run them explicitly after persistent services are healthy instead of selecting them with up --wait. Keep backup schedulers stopped until the restore finishes: starting backup-storage against an empty bucket can mirror that emptiness over backups/storage and erase the recovery source. The restore command starts serving processes and resumes backup schedules only after successful recovery and readiness checks.

Super admins

Super admins sign in with their email and password only. Their accounts and passwords are managed on the server, never by email and never in the app:

bash scripts/admin.sh create --email you@example.org          # make (or promote) a super admin; asks for a password
bash scripts/admin.sh set-password --email you@example.org    # change a super admin's password; signs them out everywhere
bash scripts/admin.sh reset-mfa --email you@example.org       # remove an authenticator from a super-admin account
bash scripts/admin.sh revoke --email you@example.org          # take super-admin access away
bash scripts/admin.sh list

The installer creates the first one from the email and password you give. Without Docker (npm run admin -- …) the same commands run against DATABASE_URL.

Updates and rollback

bash scripts/update.sh --force                                   # newest main release
bash scripts/update.sh --force --version 0.1.0-main.42.a1b2c3d4e5f6
bash scripts/update.sh --rollback                                # the release before the last update

The updater takes a lock (flock, or a PID lock on Git Bash; --override-lock clears a verified stale one), resolves a published, non-prerelease main release, downloads its source and hands over to that release's own updater. It dumps the database, checks the new image can be pulled, installs the release's host files (keeping the old ones in backups/host-config-*), pulls the images, runs migrations and waits for every service to be healthy, then runs the operator checks.

  • Automatic rollback: if the new release does not become healthy, the previous host files and images come back with --no-deps, so older migrations never run against the newer schema.
  • Manual rollback: --rollback returns to the release recorded in .spaceworks-previous-version, again without running migrations. Database changes stay; to return the data too, restore the pre-update dump the command prints.

The installer menu offers both (options 1 and 3), and the release workflow's deploy job runs update.sh --force --version <release> on a server with the runner (scripts/install-runner.sh).

Certificates

The service certificates last 825 days. Renew them from the same CA, then recreate the data services:

docker run --rm --user "$(id -u):$(id -g)" --entrypoint sh -v "$PWD/tls:/tls" -v "$PWD/deploy/certificates.sh:/c.sh:ro" \
  "$(grep ^SWM_BACKEND_IMAGE= .env | cut -d"'" -f2):$(cat .spaceworks-version)" /c.sh --renew
scripts/spaceworks-compose.sh bundled up -d --force-recreate db redis minio backend worker beat

Caddy renews the public certificates by itself.

Moving between modes

  • Plain HTTP to automatic HTTPS: point DNS at the server, then in .env set SWM_LAYER='tls', SITE_ADDRESS='<domain>', TLS_EMAIL='<you>', PUBLIC_APP_BASE_URL='https://<domain>' and remove ALLOW_PLAIN_HTTP, then scripts/spaceworks-compose.sh bundled up -d.
  • Website on Netlify: set DEPLOYMENT_MODE='backend', a 64-hex FRONTEND_GATEWAY_SECRET and PUBLIC_APP_BASE_URL to the website's origin; see DEPLOYMENT_NETLIFY.md.

Troubleshooting

  • scripts/spaceworks-compose.sh bundled logs migrate shows a failed migration; the app never starts on a half-migrated database.
  • The worker and beat are healthy only while their Redis heartbeat is fresh; logs worker beat shows a Redis or database connection problem. A worker that is up but sends nothing usually means beat is down: check ps for both.
  • Email that never arrives: Super admin → Email counts failed messages by kind (never recipients or contents), and Super admin → Operations holds the delivery controls.
  • run --rm ops names the failing check without printing any connection detail.

From SpaceWorks-Machines/docs/DEPLOYMENT_VPS.md at b60fee1, updated 2026-10-29. Suggest a change