Add orbit self-update to replace the running binary
Rolling Release / build (push) Successful in 1m58s
Rolling Release / publish (push) Successful in 10s

- `orbit self-update [constraint]` replaces the running orbit with the newest `orbit` package in its channel, or one matching a constraint (which may downgrade).
- The new build must print its version before it is renamed over the old binary.
- An orbit installed as a global package is upgraded instead, keeping rollback.
- `orbit upgrade orbit` does the same when orbit isn't installed as a package.
- Read `/proc/self/exe` through a new C stub; document in README; mock-registry test.
This commit is contained in:
nandi committed 2026-12-02 13:32:29 -08:00
1 parent f14a1900af
commit d3b1dedeb5
7 files changed
+293 -2

No files matched your search

+27 -1
View File
@@ -15,6 +15,7 @@ A small package manager written in MoonBit that uses any OCI registry (Gitea, GH
- **Conflicts:** packages can declare that they can't be installed together, and a global install offers to replace the one in the way.
- **Upgrade and rollback:** global installs keep the previous two builds, and `orbit rollback <name>` switches back instantly with no network.
- **Remove:** `orbit remove` refuses to delete what other global packages need and autoremoves orphaned dependencies; in projects it updates `orbit.toml` and `orbit.lock`.
- **Self-update:** `orbit self-update` replaces the running Orbit with the newest `orbit` package in the registry, wherever it was installed.
- **gc** deletes store builds that are neither globally current nor kept for rollback.
## Package format
@@ -210,6 +211,9 @@ curl -fLO "$base/orbit-linux-x86_64" -fLO "$base/SHA256SUMS" &&
install -Dm755 orbit-linux-x86_64 ~/.local/bin/orbit
```
After that, `orbit self-update` keeps it current from the registry (see
[Updating Orbit](#updating-orbit)).
`just build-musl` makes the same binary locally in `dist/`. It needs `zig`,
`perl`, `make`, and `curl`. [scripts/build-musl.sh](scripts/build-musl.sh) compiles
MoonBit's C output and a pinned OpenSSL with `zig cc -target x86_64-linux-musl`.
@@ -217,6 +221,27 @@ MoonBit's C output and a pinned OpenSSL with `zig cc -target x86_64-linux-musl`.
can't do, so [openssl_static.c](scripts/musl/openssl_static.c) supplies the
linked-in functions instead.
## Updating Orbit
```sh
orbit self-update # newest orbit in its channel, if newer than this one
orbit self-update '~0.1' # newest build matching a constraint (can go back)
```
Orbit is the `orbit` package in `main`, built by orbit-packages whenever the
version in `moon.mod` changes.
- An Orbit installed some other way (`just install`, the rolling release) is
replaced where it runs, such as `~/.local/bin/orbit`. It downloads the
package, checks that the new binary runs and reports the version it should,
then swaps it in with one rename. Nothing is added to your installed
packages, and the download is deleted afterwards. `orbit upgrade orbit` does
the same when `orbit` isn't an installed package.
- An Orbit installed with `orbit install orbit` is upgraded like any other
package, so `orbit rollback orbit` still works.
- It uses the channel `orbit` is installed from, else the usual channel
priority. The directory holding the binary must be writable by you.
## Building
```sh
@@ -257,7 +282,7 @@ for future upgrades and rollbacks:
bootstrap=_build/native/release/build/main/main.exe
"$bootstrap" install orbit
eval "$("$bootstrap" env)"
orbit upgrade orbit
orbit self-update # same as `orbit upgrade orbit` here
# If needed: orbit rollback orbit
```
@@ -285,6 +310,7 @@ src/main/
project.mbt orbit.toml, orbit.lock, .orbit/ environments, project CLI (+ tests)
conflicts.mbt declared conflicts, replacing installed packages (+ tests)
channels.mbt config.toml, channel priority and lookup (+ tests)
self_update.mbt replacing the running orbit with a newer build
main.mbt CLI
registry_wbtest.mbt mock-OCI registry, SAT global, and project workflow tests
```