Skip to content

Deploy to a VM with GitHub Actions

Create a project on your laptop, push it to GitHub, run the stack on a VM with Docker Compose, and ship schema and frontend changes on every push to main.

Pre-1.0: APIs and config may change between releases.

What you will have

  • One repository with supatype.config.ts, shared by local development and the VM.
  • A VM running supatype self-host compose, with the gateway serving HTTPS for your domain on ports 80 and 443.
  • A GitHub Action that connects over SSH, pulls, migrates, rebuilds static files and restarts Compose.

Create the project locally

On your machine, with Node.js 20.19 or later, or 22.12 or later on Node 22: the CLI needs 18, and the Vite 8 app it sets up needs one of those.

1. Scaffold

Terminal window
$ npm install -g @supatype/cli
$ mkdir my-blog && cd my-blog
$ supatype init

init installs dependencies and writes generated secrets and API keys to .env for local development.

2. Add a static frontend

Terminal window
$ supatype app add --static ./public
$ npm install -D vite
# in package.json: "build": "vite build", with output in public/

Commit supatype.config.ts. You do not run app add again on the server.

Give the deployment its domain while you are here. The gateway gets a Let’s Encrypt certificate for it itself, so there is no reverse proxy to set up:

Terminal window
$ supatype add domain example.com --email you@example.com

This writes server.mode, server.domain and server.tls to supatype.config.ts. supatype dev ignores them, so local development stays on http://localhost. See Self-hosting for the details.

3. Develop, then push to GitHub

Terminal window
$ supatype dev

Optionally proxy to Vite from a gitignored supatype.local.config.ts while production stays static. See Deploy changes.

Terminal window
$ git init
$ git add .
$ git commit -m "Initial Supatype project"
$ git branch -M main
$ git remote add origin git@github.com:YOUR_USER/my-blog.git
$ git push -u origin main

Prepare the VM

A one-time setup on Ubuntu 22.04 or similar, with SSH access.

4. Install the tools and clone

vm
# Docker: https://docs.docker.com/engine/install/ubuntu/
# Node.js 20.19 or later, or 22.12 or later on Node 22, which Vite 8 needs to build the app (Ubuntu's own nodejs package is older): https://nodejs.org/en/download
$ sudo apt update && sudo apt install -y git
$ sudo npm install -g @supatype/cli
$ sudo mkdir -p /opt/my-blog
$ sudo chown "$USER":"$USER" /opt/my-blog
$ cd /opt/my-blog
$ git clone git@github.com:YOUR_USER/my-blog.git .

5. Write the production secrets

Create /opt/my-blog/.env on the server and never commit it. Generate each CHANGE_ME with openssl rand -base64 48 | tr -d '/+=', use a different value for each, and set your public URL. Compose refuses to start while any of the passwords or secrets is missing.

/opt/my-blog/.env
DATABASE_URL=postgresql://supatype_admin:CHANGE_ME@localhost:5432/my-blog
POSTGRES_USER=supatype_admin
POSTGRES_PASSWORD=CHANGE_ME # the same value as in DATABASE_URL
POSTGRES_DB=my-blog
AUTHENTICATOR_PASSWORD=CHANGE_ME
SUPATYPE_SQL_EDITOR_PASSWORD=CHANGE_ME
SUPATYPE_CONTROL_PLANE_SECRET=CHANGE_ME
SUPATYPE_KEYSPACE_PASSWORD=CHANGE_ME # the cache's password, from supatype/postgres 17.2.13
JWT_SECRET=CHANGE_ME # at least 32 characters
# Leave both keys blank. compose up mints them from JWT_SECRET.
ANON_KEY=
SERVICE_ROLE_KEY=
API_EXTERNAL_URL=https://example.com
SITE_URL=https://example.com

Then run supatype keys --write in /opt/my-blog. It signs ANON_KEY and SERVICE_ROLE_KEY from this JWT_SECRET and adds the VITE_SUPATYPE_URL (https://example.com, from API_EXTERNAL_URL) and VITE_SUPATYPE_ANON_KEY copies your frontend build reads to .env. With a localhost or 127.0.0.1 API_EXTERNAL_URL, as on a test machine, it treats the stack as a local one and writes those copies to .env.development.local instead, which a production build never reads. Keys from your laptop will not work here, because they were signed with a different secret.

6. First boot

vm
$ cd /opt/my-blog
$ npm install
$ supatype self-host compose up -d
$ supatype push
$ supatype build
$ supatype self-host compose up -d

compose up writes the compose file itself, so there is no separate render step.

Before this, point an A record for example.com at the VM and open ports 80 and 443 in its firewall. Then open https://example.com, with Studio at /studio/. Without a domain in supatype.config.ts, the gateway is on http://YOUR_VM_IP:18473 instead. Backups, logs and rollbacks are covered in Running in production.

Repository secrets

In your repository, open Settings → Secrets and variables → Actions and add:

SecretValue
VM_HOSTPublic IP or hostname of the VM
VM_USERSSH user, for example ubuntu
VM_SSH_KEYPrivate key (PEM) that can log in as VM_USER
DEPLOY_PATHProject directory on the VM, for example /opt/my-blog

The workflow

Add .github/workflows/deploy-self-host.yml to your repository:

.github/workflows/deploy-self-host.yml
name: Deploy self-host
on:
push:
branches: [main]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy over SSH
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USER }}
key: ${{ secrets.VM_SSH_KEY }}
script_stop: true
script: |
set -euo pipefail
cd "${{ secrets.DEPLOY_PATH }}"
git fetch origin main
git reset --hard origin/main
npm ci
supatype push
supatype build
supatype self-host compose up -d

On every push to main the VM pulls the latest code, applies schema migrations, rebuilds public/ and refreshes Compose.

Verify the pipeline

7. Push a change

Terminal window
$ git add .
$ git commit -m "Add posts and update the landing page"
$ git push origin main

Watch the run under Actions on GitHub. When it succeeds, load your gateway URL and check that the schema and static files changed.

If something fails

SymptomCheck
SSH failsThe firewall allows port 22, and VM_SSH_KEY matches the VM’s authorized_keys.
supatype push failsCompose is up, and DATABASE_URL points at localhost:5432. If it refused a change that needs your consent, see The workflow.
Site unchangedsupatype build writes to the directory in app.static_dir, then re-run supatype self-host compose up -d.
supatype build failsIt lists each source it tried for the API URL and anon key. On the VM both come from .env: API_EXTERNAL_URL must be the public address, not localhost, and ANON_KEY must be set. See Deploy your frontend.