Operate bay

Serve your machines from an origin

Put a bay host near your machines in front of a hosted remote, so bay's traffic stays local.

An origin is a host from bay host near your machines that keeps a hosted remote, such as GitHub, current. Clones send bay's refs, its notes and main to the origin, and read them there. bay's reads then make a round trip on the local network, not to the hosted remote. In through mode, each write waits while the origin sends it to the hosted remote, with its Git login. In tail mode, only a write of main waits. When the hosted remote refuses a push with no cause, the origin forwards it again.

It is plain Git, as any host from bay host is, and its main hook works the same way. Other branches and tags keep their remote. The remote's name and its tracking refs stay as they are.

When to use an origin

  • A far hosted remote: your machines share a network, and each round trip to the hosted remote is slow.
  • Main stays on the hosted remote: people and tools still read it there, so you keep it.

Set up an origin

  1. 01

    Create the origin

    On a machine near the others, run bay host with --upstream. The machine needs Git 2.54 or newer, as any host from bay host does. Its own Git login must be able to push to the hosted remote.

    sh
    bay host /srv/git/app.git --upstream git@github.com:example/app.git
  2. 02

    Keep it current

    Run bay host serve under a supervisor, such as a systemd user unit or a launchd agent. It brings in what other writers push to the hosted remote. Its first pass fetches the whole repository. --once makes one pass and prints what it took.

    sh
    bay host serve /srv/git/app.git          # until you stop it
    bay host serve /srv/git/app.git --once   # one pass, and what it took
  3. 03

    Update every machine

    Move every machine, and the origin, to the newest bay, and check each one's version. A bay older than 0.7.0 does not know [origin]. Once the key is on main, each of its commands that reads the config fails and names the key. It never sends anything through the origin.

  4. 04

    Name the origin on main

    Merge [origin] url into .bay/config.toml. bay then sends its refs, its notes and main through the origin. A clone on the origin's own machine can reach it by path: git config bay.origin /srv/git/app.git. That local setting wins over [origin] url for that clone.

    toml
    # .bay/config.toml
    [origin]
    url = "ssh://git.internal/srv/git/app.git"
  5. 05

    Check the origin

    Run bay doctor in the origin. It names the hosted remote, the mode the origin works in, and the mode its config names. It never shows a credential from the hosted remote's URL. It goes red when the origin's hook is missing. In mirror mode, it also shows how far the hosted main lags.

    sh
    cd /srv/git/app.git && bay doctor

How the modes work

A new origin works in through mode. When another writer moved a ref on the hosted remote first, the origin refuses the push as stale. The origin then holds the hosted remote's value, and bay reads it and tries again.

ModeWhat it does
throughThe origin takes a push only after the hosted remote took it, all refs or none. The hosted remote never falls behind.
tailThe origin holds the newest copy of bay's refs and notes. They reach the hosted remote in the next pass of bay host serve. Main still goes to the hosted remote first.
mirrorThe origin holds the newest main too. A merge moves main on the origin alone, and never waits for the hosted remote. The next pass of bay host serve sends main to the hosted remote as a fast-forward, with no force.

Move to tail mode

In tail mode, a push of bay's refs does not wait for the hosted remote. Switch only when no other writer still writes bay's refs to the hosted remote. Read the log of the supervised bay host serve, and wait a whole day with no pass whose mirrored.strays is above 0. --once reports one pass only, and the running serve takes most strays first. Each pass names where each stray sits in strays_by: the runner whose log or presence it is, else its namespace. Then set the mode in the origin.

sh
git -C /srv/git/app.git config bay.upstreamMode tail

  • Strays: the origin logs a ref that another writer moved on the hosted remote as STRAY, and writes over it.
  • What stays on the origin: what is live on one machine, such as leases, live rows and runner records.
  • No way back by config: an origin that tails stays in tail mode, even if its config says through again.
  • Why: the hosted remote can be behind the origin then, and its values would undo newer writes.

Move to mirror mode

In mirror mode, a merge never waits for the hosted remote or for its rules. Use it when the hosted remote must never be on the path of a merge. First, protect main on the hosted remote, so that only the origin can push it. Then set the mode in an origin that tails.

sh
git -C /srv/git/app.git config bay.upstreamMode mirror

  • Main goes out through the serve: each pass pushes main first, as a fast-forward only, then bay's refs.
  • Main comes in only through bay: the serve no longer takes main from the hosted remote.
  • Strays on main: the origin logs another writer's commit on the hosted main as STRAY, and never writes over it.
  • Retries: when the hosted remote refuses main, the serve sends it again after 30 seconds.
  • Doctor: it names the commit, says how to bring it in through bay, and stays red with UPSTREAM_BEHIND until then.
  • Lag: doctor's origin row turns degraded past bay.lagDegradedS seconds of lag, and red with UPSTREAM_BEHIND past bay.lagRedS.

See the lag from any machine

bay status and bay status --all show how far the hosted main lags, under detail.origin.main. Its fields are lag_s, checked_s, stray and refusal. bay host serve writes the lag to refs/bay/origin/lag when it changes, or every 300 seconds. When a status cannot read the lag, detail.origin.unread says why.

Go back to tail mode

Wait until doctor's origin row shows main.lag_s at 0, and no merge runs. Then set tail in the origin, and remove the file bay/mirror in it. Until you remove that file, the origin mirrors, whatever its config says.

sh
git -C /srv/git/app.git config bay.upstreamMode tail
rm /srv/git/app.git/bay/mirror

When the origin does not answer

A machine whose origin does not answer uses the hosted remote instead. An origin in through mode holds nothing that the hosted remote lacks. An origin that tails first writes refs/bay-origin/tails to the hosted remote. While that ref is there, machines do not use the hosted remote in place of the origin. The origin removes the ref when it works in through mode again.

What it cannot do

  • Judge pushes to the hosted remote: a push straight to the hosted remote passes only that remote's own rules.
  • Move older machines: once [origin] is on main, a bay older than 0.7.0 fails each command that reads the config.

Limits

  • Git on the origin: 2.54 or newer.
  • Branches: bay host serve brings them in every bay.pollS seconds, 5 by default.
  • bay's refs and notes: in through mode, it brings them in every bay.sweepS seconds, 60 by default.
  • Main's lag in `mirror` mode: degraded past bay.lagDegradedS seconds, 60 by default, and red past bay.lagRedS, 900 by default.