Docs
Docs menu

Object storage

Mirror a node to an S3-compatible bucket as it runs, encrypted with your key, and restore it from there onto a new machine or another provider.

A node can copy itself to an S3-compatible bucket as it runs: Cloudflare R2, Tigris, Backblaze B2, Hetzner, MinIO or AWS S3. Every push, merge, comment and job reaches the bucket within seconds to a minute. If the node’s disk is lost, or you move to another machine or provider, moru-node restore --from rebuilds the node from the bucket.

The bucket is a copy. The node still keeps everything on its own disk and serves from there, and nothing leaves the disk because it’s in the bucket. It doesn’t replace backups either: a backup is a snapshot you keep, while the bucket follows the node, including its mistakes. Keep taking backups now and then.

What’s copied#

WhatWhen
Repositories, with every change, request, comment and review in themAbout 2 seconds after a push or merge, and within 10 seconds otherwise
Keys, accounts, organizations, access, runners, settings and the node’s other filesEvery 30 seconds, when one changed
The index: jobs, their logs, CI runs, events and webhook deliveries waitingA snapshot at most every 60 seconds while it changes; the last 10 kept
CI artifactsOnce each, after the run that made it stores it
Release filesOnce each, when the file is uploaded to the node

Repositories go up as git packs: each upload is a pack of what’s new, plus a small manifest of the repository’s refs. Many small packs are merged into one now and then. The other files are the same ones moru-node backup takes. When a repository is deleted, its copy in the bucket stays until the trash is purged, 7 days later. An artifact that expires is deleted from the bucket too. A release file goes under its repository’s prefix, named by its SHA-256, so a file several releases share is uploaded once.

Uploads that fail are tried again by themselves, and never fail the push or the request that caused them.

What’s encrypted#

Everything the node uploads is encrypted with a key you give it, except public repositories, their CI artifacts and their release files:

  • Encrypted: the index snapshots, the node’s files (keys, accounts, settings), and private repositories’ packs, manifests, CI artifacts and release files.
  • Not encrypted: public repositories’ packs and manifests, their CI artifacts and their release files. Anyone can read them through the node anyway.

What the storage provider can still see: the owner and name of every repository, private ones included; the names of the node’s files, which include people’s handles and organization names; CI run IDs and artifact file names; how big each object is and when it was uploaded. It knows that acme/secret-plans exists and roughly how large it is, not what’s in it.

When a public repository is made private, the node uploads it again, encrypted, before anything else, and deletes the plain copy. Its release files are encrypted again too, and each plain copy is deleted only once the encrypted one is in the bucket. When a private repository is made public, nothing is uploaded again: new packs go up plain, and the encrypted ones stay until packs are next merged.

The key#

The key is an age key. Make one with any of these, on your own machine:

moru-node store keygen
docker run --rm quay.io/moru/moru-node:latest store keygen
age-keygen

Each prints an AGE-SECRET-KEY-1… line (age-keygen prints a public key too; use the secret key line). That’s MORU_STORE_KEY.

Anything in the bucket can be read by hand with the standard age tool and the key: encrypted objects end in .age.

Choose a provider#

Cloudflare R2 is the one we test against. Any S3-compatible service should work.

  • Cloudflare R2 is the default. It’s free up to 10 GB, downloads are free, and MORU_STORE_REGION can stay auto.
  • Tigris should work, with a single-region or multi-region bucket. Its default global buckets aren’t consistent enough across regions.
  • Backblaze B2 and Hetzner Object Storage should work, and cost the least once you store a lot. Set MORU_STORE_REGION to the region in their endpoint, such as us-west-004 for B2 or fsn1 for Hetzner.
  • AWS S3 should work. Set MORU_STORE_REGION to the bucket’s region (us-east-1, …), and leave MORU_STORE_ENDPOINT out.
  • MinIO and other services you run yourself should work too, including on a plain http:// endpoint inside your network.

The default region, auto, is for R2.

To try it without a provider, a directory works as a bucket: MORU_STORE_URL=file:///srv/moru-bucket.

Set up the bucket#

  1. Create a bucket, and credentials for that one bucket with read and write access to its objects. On R2 that’s an API token scoped to the bucket. Don’t use an account-wide token.

  2. Add a lifecycle rule that aborts incomplete multipart uploads after one day. Large packs and artifacts go up in parts, and an upload cut short by a restart leaves its parts behind until a rule like this clears them.

  3. Make a key (see The key) and store it somewhere safe.

  4. Give the node the bucket, in .env with Compose or in your platform’s secrets:

    MORU_STORE_URL=s3://acme-moru/node
    MORU_STORE_ENDPOINT=https://<account>.r2.cloudflarestorage.com
    MORU_STORE_ACCESS_KEY_ID=…
    MORU_STORE_SECRET_ACCESS_KEY=…
    MORU_STORE_KEY=AGE-SECRET-KEY-1…

    MORU_STORE_URL is the bucket and a prefix in it, so one bucket can hold more than one node’s copy. Keep the credentials and the key out of the command line, where other users on the machine could see them.

  5. Restart the node: docker compose up -d with Compose (restart doesn’t read .env again), or redeploy on your platform. It starts uploading at once. The first pass uploads everything, which takes a while on a large node.

Each variable is described in Configuration. The node refuses to start with a bucket and no key, or with only one of the two credentials.

Check on it#

Site admins see the bucket in Settings → Network, in the node’s panel: how far behind it is, when it last uploaded the repositories, the index and the node’s files, what’s waiting, and the last error. Beside each of those, a countdown says when the node next looks for changes (see the table above). While something goes up (a repository’s new objects, an index snapshot, a CI artifact or a release file), the panel shows it with a progress bar and how much of it has gone up; the bar counts what the node has handed to the bucket, so on a slow link a large file’s bar runs up to about 40 MB ahead and then waits on Finishing…. The panel refreshes itself every few seconds. On a host with many nodes, select a node to see its bucket.

Open in Moru
  • Upload now uploads everything waiting, showing each step as it goes (the repositories, the node’s files, the index snapshot, then the CI artifacts), and says when it’s done. Asked during an upload pass, it starts once that pass ends.
  • Check key opens the newest index snapshot in the bucket with the node’s key, then the node’s files and each repository’s list of packs. If it can’t, a restore with this key would fail too: check MORU_STORE_KEY. After you change the key, the node encrypts everything again with the new one, and the check fails, saying how much is left, until that’s done.

The same on the command line. The store commands run where the node’s data directory is, so run them in the node’s container or machine:

docker compose exec moru moru-node store status
docker compose exec moru moru-node store flush
docker compose exec moru moru-node store check

On Fly.io, fly ssh console -C "moru-node store status", and the same for the others.

store status shows what’s uploaded and what’s still waiting, with the last error. store flush asks the running node to upload everything and waits until it has tried (10 minutes at most; --timeout changes that); it exits with 1 and lists what didn’t go up. store check opens what a restore would need with the key, like Check key; it needs the MORU_STORE_* variables, which the node’s own environment has.

/api/v0/health adds the bucket to its answer:

{ "ok": true, "store": { "lag_s": 3, "degraded": false } }

lag_s is how long, in seconds, the oldest change not yet uploaded has waited. degraded turns true once something has waited more than 5 minutes, or the node’s files or index snapshots have failed to upload for that long. The health check still answers 200 then, so a slow bucket never gets the node restarted. Watch degraded in your monitoring instead.

Shutting down#

When the node stops (SIGTERM or SIGINT), it finishes the requests and pushes in progress for up to 20 seconds, then uploads what’s left for up to 30 seconds (MORU_STORE_FLUSH_TIMEOUT), then closes. That’s up to about 55 seconds, so the platform must wait at least that long before it kills the node:

PlatformSetting
Fly.iokill_timeout = 60 in fly.toml
Docker Composestop_grace_period: 60s in compose.yaml
KubernetesterminationGracePeriodSeconds: 60
RendermaxShutdownDelaySeconds: 60 in render.yaml
Railwaythe variable RAILWAY_DEPLOYMENT_DRAINING_SECONDS=60

Under systemd, the default of 90 seconds is enough. If you raise MORU_STORE_FLUSH_TIMEOUT, raise the platform’s setting with it: keep it at least 25 seconds above. A node killed sooner loses nothing on its own disk; the bucket just catches up after the next start.

Restore from the bucket#

moru-node restore --from rebuilds a node’s data directory from the bucket: its files, its repositories, its newest index snapshot and its CI artifacts.

  1. Stop the old node, if it’s still running. Two nodes writing to the same place in the bucket would overwrite each other. If it can still upload, run store flush on it first (docker compose exec moru moru-node store flush with Compose).

  2. Set the same MORU_STORE_* variables (the endpoint, the credentials and the key) where you restore.

  3. Restore into an empty data directory:

    moru-node --data /var/lib/moru restore --from s3://acme-moru/node

    With Docker Compose, into an empty volume (the variables come from .env). If the old volume is still there, run docker compose exec moru moru-node store check first and take a backup of it, since the next commands delete it. On a new machine there’s no old volume, and docker volume rm fails harmlessly.

    docker compose down
    docker volume rm moru_moru-data
    docker compose run --rm moru restore --from s3://acme-moru/node
    docker compose up -d
  4. Start the node as usual (with Compose, the last command above), with the same variables. It rebuilds what the index derives from the repositories, and goes on uploading to the same place.

The restored node has the same identity, keys, accounts, runners, repositories, jobs and artifacts. People sign in with their passwords, and runners keep their tokens. What the restore says:

  • The index snapshot it used, and when it was taken. Jobs, log lines and events after that time weren’t in the bucket yet, so they’re lost. That’s about a minute while the bucket keeps up (see degraded under Check on it).
  • Repositories in the trash. They stay in the bucket but aren’t restored.
  • Release files come back with their repositories.
  • CI artifacts newer than the snapshot. No restored run names them, so the node deletes them from the bucket when it starts.
  • CI artifacts that weren’t in the bucket yet (“N CI artifacts weren’t in the bucket yet and were dropped”). Their runs no longer list them.

If the bucket has no index snapshot yet, the restore refuses unless you add --without-index: the node then rebuilds the index from the repositories, and jobs, their logs, events and every CI artifact are lost.

Everything that can be refused (the key, the node, the free disk space) is checked before the restore writes anything. If it stops halfway, the data directory is marked as unfinished and the node refuses to start on it, since a node started on half its data would delete the rest from the bucket. Empty the directory and run the restore again.

Move to another provider#

The bucket holds nothing specific to its provider, so moving is a copy:

  1. On the old machine, upload everything and stop the node:

    docker compose exec moru moru-node store flush

    (on Fly.io, fly ssh console -C "moru-node store flush"), then stop it the way your platform does.

  2. Copy the bucket to the new provider with any S3 tool, for example rclone:

    rclone sync r2:acme-moru hetzner:acme-moru

    Skip this step if only the machine changes and the bucket stays.

  3. On the new machine, set the MORU_STORE_* variables for the new bucket (the same key), restore into an empty data directory, and start the node.

  4. Point your domain’s DNS at the new machine. Keep MORU_PUBLIC_URL as it was.

Don’t start the old node again: it would go on writing to the old bucket, or to the same one.

A node whose MORU_STORE_URL or endpoint changes without a restore notices at its next start and uploads to the new bucket whatever isn’t there yet.

A host with many nodes#

Every node of a host uses the same bucket, the same MORU_STORE_URL and the same key. Each node uploads the repositories it holds and its own files, so the control node’s copy has the host-wide state (accounts, organizations, runners) and each repo node’s has its repositories. Settings → Network shows each node’s bucket in its panel.

  • Moves. Before a repository moves, its node uploads it to the bucket. If that upload fails, the move waits and tries again later.

  • Restoring. When the bucket holds more than one node’s copy, name the one to restore with --node and its DID, as moru-node nodes lists them, or as the restore lists them when you leave --node out:

    moru-node --data /var/lib/moru restore --from s3://acme-moru/host --node did:key:z6Mk…

    A restored control node comes back as itself. A restored repo node joins the host as a new node, with a new key, and takes over the old node’s repositories, as a restored backup does: start it with --role repo and a node code or enrollment token. See Restore a repo node.

Command menu
Search for a page, repository, change or request, or run a command