---
title: "How moin ships"
description: "From a change to your server. Pull requests. Signed releases. Updates you run yourself. How moin.run goes live."
group: "Reference"
order: 4
---

This page is the one place that says how a change gets from the code to your server. When that changes, this page changes in the same pull request.

```text
change → pull request → main → release → GitHub, signed → moin update, when you run it
                                                        → update.sh, when its owner runs it → moin.run
```

## A change

One branch, one small thing. Everyone, maintainers too:

1. A pull request. Nobody pushes to `main`.
2. CI turns green.
3. A maintainer reviews it.
4. A squash merge: one commit on `main`.

Merging ships nothing. The change only lands on `main`. [Contributing](https://github.com/axadrn/moin/blob/main/CONTRIBUTING.md)

## What ships what

| What changed | What ships it | Who gets it |
| --- | --- | --- |
| Only the repository: `AGENTS.md`, tests, workflows | nothing, the merge is enough | nobody |
| The site: docs, blog, landing | a **release**, then its owner rolls it out | moin.run |
| What `moin` does: a feature or a fix | a **release** | everyone who updates |

A release has a version, like `v1.0.0-beta.38`, and its notes in the [changelog](/changelog). The tag `v…` starts it. Only a release goes live, on moin.run too.

## A release

1. The notes go into the changelog, then the tag.
2. The Deploy workflow tests and builds the `moin` binaries and the image of the site.
3. It waits until a maintainer approves the run in GitHub.
4. `SHA256SUMS` lists the binaries and the image of the site, by its digest. The image holds the deploy files of moin.run, in `/deploy`.
5. It signs `SHA256SUMS` with `RELEASE_SIGNING_KEY`, a secret of the GitHub environment `release`, twice: `SHA256SUMS.sig` for `moin update`, `SHA256SUMS.sshsig` for `ssh-keygen` in `cli.sh` and `update.sh`. Only a `v*` tag reaches the key, and only after that approval.
6. It makes the GitHub release as a draft, adds every file, and only then publishes it.

So nobody sees a new version before its signed release is complete.

## Where moin.run runs

moin.run is one Go app. It has one SQLite database. Both live on one server.

Docker Compose starts it. `update.sh` runs Compose, not moin. So moin.run never needs moin to come back.

Its traffic comes in through a Cloudflare Tunnel. No port is open.

The server also runs moin's daemon, as [a server without apps](/docs/security#a-server-without-apps). The daemon keeps the firewall shut. It counts the knocks. It reports them. The knocks on the home page are those.

If moin.run is down, only that number is missing. Nothing else needs moin.run.

## How moin.run goes live

`cloud/deploy/update.sh` is moin.run's own script. If you run moin, you never need it: you update with `moin update <server>`, and a watcher of your own runs with `moin watcher run`.

### What GitHub does

GitHub only tests, builds, signs and publishes. A release carries only what people who run moin need: the binaries and `SHA256SUMS`, signed.

The files of the site's server live in the image of the site, in `/deploy`: `compose.yml`, `compose.tunnel.yml`, `litestream.yml`, `env.example`, `update.sh`, and `restore-check.sh` with its `restore-check.service` and `restore-check.timer`. `SHA256SUMS` names that image by its digest. So the release key signs these files too.

GitHub never touches the server. Nothing goes live when a release comes out.

### What its owner types

One command, from the owner's laptop:

```bash
tailscale ssh root@<server> /opt/moin/update.sh v1.0.0-beta.43
```

Without a version, it takes the newest release. Step by step, `update.sh`:

1. Downloads `SHA256SUMS` of that release, with its signature.
2. Checks the signature with the release keys written into the script. One wrong byte, and it stops. Nothing changed.
3. Pulls the image of the site by the digest `SHA256SUMS` names. Takes the files of the site out of its `/deploy`. So it runs exactly what the release signed.
4. Keeps the files of the running version in `previous/`.
5. On a server without a database, brings it back from its bucket.
6. Checks the env vars with the new version, while the old one keeps running.
7. Starts the new version, and waits until it runs healthy.
8. Asks the site at `/healthz` if it answers.
9. Sets up the daily [restore check](#the-daily-restore-check) of the database.

### Why nothing outside holds a key to the server

No outside service holds a key to the server. GitHub has no SSH key, no Tailscale key, and none of the env vars. It has no key to the bucket of the database either, not even one that only reads.

A stolen GitHub token can't change moin.run. At most it could publish a release. And the server only starts a release the release key signed, and only when its owner types the command.

### When a rollout fails

If a step before 4 fails, nothing changed. The old version keeps running.

If a step from 5 to 8 fails, `update.sh` puts the files of `previous/` back. It starts the previous version again. It says so, clearly, and ends with an error. The new version is not live.

Step 9 comes after the site is live. If it fails, the new version stays live, and `update.sh` ends with an error.

### Go back to an older version

Give `update.sh` the older version. It rolls it out the same way.

It goes back as far as v1.0.0-beta.47. An older image has no `/deploy`. `update.sh` stops there. Nothing changed.

### Change the .env

The env vars live in one plain file on the server: `/opt/moin/.env`. No service fills it. `/opt/moin/env.example` names every env var, with one line on what it is. Each update puts the one of its version there.

1. Edit `/opt/moin/.env` on the server.
2. Run `update.sh` again.

The preflight of step 6 stops a missing or wrong env var. Then the running site stays.

### The first install

A fresh server needs `update.sh` once, out of the image the release signed. As root on the server, with Docker installed. First check the signature:

```bash
mkdir -p /opt/moin && cd /opt/moin
version=v1.0.0-beta.47
url=https://github.com/axadrn/moin/releases/download/$version
curl -fsSLO "$url/SHA256SUMS"
curl -fsSLO "$url/SHA256SUMS.sshsig"
cat > allowed_signers << 'KEYS'
moin-release ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHZMF3btxHJfEbOLX18SK74qTn0WuUetbX1hHSiEsNyw
moin-release ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICtglRxa7QWCtSE+7Pvtv0fy2TcTuvoxj3OvBGYlAyoU
KEYS
ssh-keygen -Y verify -f allowed_signers -I moin-release -n moin-release -s SHA256SUMS.sshsig < SHA256SUMS
```

`ssh-keygen` must say `Good "moin-release" signature`. Else stop. The keys are the same as in `update.sh` and in `internal/build/release.go`.

Then take `update.sh` and `env.example` out of the image `SHA256SUMS` names:

```bash
image=ghcr.io/axadrn/moin@sha256:$(awk -v image="ghcr.io/axadrn/moin:$version" '$2 == image { print $1 }' SHA256SUMS)
docker pull "$image"
container=$(docker create "$image")
docker cp "$container:/deploy/update.sh" .
docker cp "$container:/deploy/env.example" .
docker rm "$container"
rm SHA256SUMS SHA256SUMS.sshsig allowed_signers
```

Then write the env vars into `/opt/moin/.env`, with `chmod 600`. `env.example` names them. Then `./update.sh $version`.

## moin.run's database

Litestream backs up the database. It runs on its own, next to the site. moin plays no part in it.

- Every change goes to its own bucket within seconds.
- A full snapshot goes there once a day.
- A restore can go back seven days.

A fresh server has no database. Before the site starts, `update.sh` asks Litestream to bring it back from the bucket. With a database there, it does nothing.

### The daily restore check

A backup only counts if it comes back. So every day, the server checks its own. moin does the same for your apps.

`restore-check.sh` does it, every morning. A systemd timer starts it. `update.sh` sets the timer up, so it needs no step by hand.

1. Litestream brings the newest copy back from the bucket, into a spare file. Same image, same env vars, same bucket.
2. SQLite checks the whole file.
3. The file must have workspaces.
4. The spare file is deleted.

Every check mails its result to the owner, at the address the site sends from: `moin.run backup check: OK` or `moin.run backup check: FAILED`, with a few plain lines. One mail a day. A day without one means something is broken.

The mail goes through Cloudflare Email Sending, with the env vars the site already has. No new env var.

The copies in the bucket are not encrypted. So only the server holds a key to the bucket. GitHub holds none, not even one that only reads.

To run the check by hand, from the owner's laptop:

```bash
tailscale ssh root@<server> /opt/moin/restore-check.sh
```

It says what it found. The daily runs are in `journalctl -u restore-check`.

## Updates

Nothing updates by itself. Not the CLI, not a server, not a watcher.

- `moin update` updates the CLI on your laptop, from the GitHub release, after it checked the signature.
- `moin update my-server` puts that same version on the server, over SSH. The server downloads it, checks its signature, and restarts the daemon. Your apps keep running.
- Once a day the CLI says when a new version is out.

What a release needs from you, if anything, is in its notes, under Upgrade. [Updates](/docs/security#updates)

## Your version

```bash
moin version
```
