Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e6eee0b9c | ||
|
|
da206a5237 | ||
|
|
3881c623cf | ||
|
|
83343f7a18 |
@@ -292,7 +292,7 @@ Package upgrades (see above)
|
||||
1. **Done (0.13.2):** one "Updates" page with the parts "Router software" and "Packages", one overlay and one confirmation banner, both logs. Still to do for it: one check, one preview and one apply for both (needs step 3).
|
||||
2. **Done (0.13.3, fixed in 0.13.4):** the repository is hardcoded: the module option `routerUpdate.repository` (beside `routerUpdate.publicKeys`; not a `router.*` setting, so it is not in the settings, the options listing or the web UI) defaults to `https://git.stinnesbeck.com/nils/nixos-router`, is baked into `router-update` and written to `/etc/router-update-repository` for the web UI, and the page only names it (no field: a fork or a test sets the option in a module; a moved repository needs a bundle update). `router-update check` (daily timer `router-update-check`, and the page's button) lists the repository's tags with `git ls-remote`, takes the newest `vX.Y.Z` (other tags are ignored) and writes `update/check.json` (repository, time, installed, newest tag/version/revision, newer). The Overview and the Updates page show it while it is about this repository and the installed version.
|
||||
3. **Done (0.13.3), without a preview:** `router-update --git TAG|latest` (the web UI's "Install"): `nix flake prefetch` of `git+<repo>?ref=refs/tags/<tag>&rev=<commit>`, then the steps of a bundle update from the serial guard on (snapshot, flake, nixpkgs pin, migration, `router-apply` with commit-confirm, rollback). The flake is the source's `config-flake.nix` with `@SOURCE@` replaced by that address, so `flake.lock` and `flake.nix` agree and nothing moves by itself (this file is a contract with every updater already installed: change it only compatibly). The release data (version, serial = the commit's time, schema = the number of `migrations/*.jq`) is read from the fetched source. No signature is checked. Still to do: preview (package changes, download and builds of both inputs), and the nixpkgs-pin interplay for a pin chosen later.
|
||||
4. Still to do: a release is a tag `vX.Y.Z` on the release commit (`router-release` tags it, still writes a bundle for the installer and offline routers) and refuses a `flake.lock` whose nixpkgs is not a channel revision (`git-revision`), so cache.nixos.org has its packages.
|
||||
4. **Tag: done (0.13.5).** A release is a tag `vX.Y.Z` on the release commit: `nix run .#release` (which still writes the bundle for the installer and offline routers) ends by creating the annotated tag, locally (push it with the branch; `--no-tag` skips it). It refuses when HEAD's `VERSION` is another version or the tag is on another commit, does nothing outside a git checkout (the VM tests), and tags last so a failed release leaves no tag. Still to do: refuse a `flake.lock` whose nixpkgs is not a channel revision (`git-revision`), so cache.nixos.org has its packages.
|
||||
5. **Done:** the `update` VM test serves a repository from the builder (`common.gitServer`: `git http-backend` over HTTP) and covers the check, tags that are no releases, refused tags, install through the web UI with migration, confirm, the rebuild without the server, and "not newer".
|
||||
Bundles and `--url` stay (offline, installer, gitea down).
|
||||
|
||||
|
||||
@@ -222,6 +222,7 @@
|
||||
name = "router-release";
|
||||
runtimeInputs = with pkgs; [
|
||||
nix
|
||||
git
|
||||
gnutar
|
||||
coreutils
|
||||
jq
|
||||
|
||||
@@ -319,6 +319,8 @@ type dashboard struct {
|
||||
Events []Event
|
||||
Charts []Chart
|
||||
Prefs Prefs
|
||||
Version string // the installed release of nixos-router
|
||||
NixOS string // the NixOS it runs on
|
||||
}
|
||||
|
||||
func (a *app) dashboardData(rangeName string) dashboard {
|
||||
@@ -326,7 +328,8 @@ func (a *app) dashboardData(rangeName string) dashboard {
|
||||
now := time.Now()
|
||||
s, _ := loadSettings(a.sys.settingsPath())
|
||||
f := s.form()
|
||||
d := dashboard{Range: rg.Name, Interval: 5, Snap: a.metrics.Snapshot(), Prefs: a.sys.loadPrefs()}
|
||||
d := dashboard{Range: rg.Name, Interval: 5, Snap: a.metrics.Snapshot(), Prefs: a.sys.loadPrefs(),
|
||||
Version: a.sys.installedRelease().Version, NixOS: a.sys.runningVersion()}
|
||||
// Newest first, the last few.
|
||||
ev := d.Snap.Uplink.Events
|
||||
d.Events = make([]Event, 0, 10)
|
||||
|
||||
@@ -155,6 +155,25 @@ func TestDashboardRenders(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDashboardNamesTheVersion(t *testing.T) {
|
||||
a, sys := newTestApp(t)
|
||||
dir := t.TempDir()
|
||||
sys.ReleaseFile = filepath.Join(dir, "router-release")
|
||||
sys.VersionFile = filepath.Join(dir, "nixos-version")
|
||||
os.WriteFile(sys.ReleaseFile, []byte(`{"version":"4.5.6"}`), 0o600)
|
||||
os.WriteFile(sys.VersionFile, []byte("26.11.20261113.d5cc683\n"), 0o600)
|
||||
a.sys = sys
|
||||
h := a.routes()
|
||||
cookie := login(t, h)
|
||||
// The page and the fragment that refreshes it say what runs.
|
||||
for _, path := range []string{"/", "/dashboard?range=24h"} {
|
||||
body := do(h, "GET", path, nil, cookie).Body.String()
|
||||
if !strings.Contains(body, "nixos-router 4.5.6") || !strings.Contains(body, "NixOS 26.11.20261113.d5cc683") {
|
||||
t.Errorf("%s does not name the version:\n%s", path, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackup(t *testing.T) {
|
||||
a, sys := newTestApp(t)
|
||||
h := a.routes()
|
||||
|
||||
@@ -11,6 +11,43 @@ import (
|
||||
|
||||
const testRepository = "https://git.example.org/me/nixos-router"
|
||||
|
||||
// While the look at the repository runs, the page is covered by the same kind
|
||||
// of box as an update, and keeps asking for itself until it is done.
|
||||
func TestLookingAtTheRepositoryShowsABox(t *testing.T) {
|
||||
a, sys := newTestApp(t)
|
||||
sys.RepositoryFile = filepath.Join(t.TempDir(), "router-update-repository")
|
||||
os.WriteFile(sys.RepositoryFile, []byte(testRepository), 0o644)
|
||||
a.sys = sys
|
||||
orig := unitProperty
|
||||
state := "inactive"
|
||||
unitProperty = func(unit, prop string) string {
|
||||
if unit == gitCheckUnit && prop == "ActiveState" {
|
||||
return state
|
||||
}
|
||||
return ""
|
||||
}
|
||||
defer func() { unitProperty = orig }()
|
||||
h := a.routes()
|
||||
cookie := login(t, h)
|
||||
|
||||
body := do(h, "GET", "/update", nil, cookie).Body.String()
|
||||
if strings.Contains(body, "Looking at the repository…") || strings.Contains(body, "data-live") {
|
||||
t.Fatalf("a box with nothing running:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, "Look for a newer release") {
|
||||
t.Fatalf("no button:\n%s", body)
|
||||
}
|
||||
|
||||
state = "activating"
|
||||
body = do(h, "GET", "/update", nil, cookie).Body.String()
|
||||
if !strings.Contains(body, "Looking at the repository…") || !strings.Contains(body, `class="upload-overlay"`) || !strings.Contains(body, "data-live") {
|
||||
t.Fatalf("no box while looking:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, testRepository) {
|
||||
t.Fatalf("the box does not say where it looks:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdatesFromGit(t *testing.T) {
|
||||
a, sys := newTestApp(t)
|
||||
dir := t.TempDir()
|
||||
|
||||
@@ -49,7 +49,8 @@ func command(name string, args ...string) (string, error) {
|
||||
return strings.TrimSpace(string(out)), err
|
||||
}
|
||||
|
||||
func unitProperty(unit, prop string) string {
|
||||
// unitProperty is a property of a systemd unit (replaced in tests).
|
||||
var unitProperty = func(unit, prop string) string {
|
||||
out, _ := command("systemctl", "show", "--value", "-p", prop, unit)
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
<section class="card">
|
||||
<h2>System</h2>
|
||||
<dl>
|
||||
{{if $d.Version}}<dt>Version</dt><dd>nixos-router {{$d.Version}}{{if $d.NixOS}} <span class="muted">on NixOS {{$d.NixOS}}</span>{{end}}</dd>{{end}}
|
||||
<dt>Uptime</dt><dd>{{age $sys.Uptime}}</dd>
|
||||
{{if $sys.Kernel}}<dt>Kernel</dt><dd>{{$sys.Kernel}}{{if $sys.KernelNext}} <span class="bad">reboot to run {{$sys.KernelNext}}</span> <button type="button" class="link" data-dialog="Reboot the router now? Routing stops for a minute or two." data-dialog-ok="Reboot" data-post="/reboot">Reboot</button>{{end}}</dd>{{end}}
|
||||
{{if $sys.BootPending}}<dt>Reboot</dt><dd><span class="bad">a new configuration starts at the next reboot</span> <button type="button" class="link" data-dialog="Reboot the router now? Routing stops for a minute or two." data-dialog-ok="Reboot" data-post="/reboot">Reboot</button></dd>{{end}}
|
||||
|
||||
@@ -22,6 +22,16 @@
|
||||
<p class="muted">The page reloads when it is done. The web UI restarts when an upgrade is switched on, and you log in again.</p>
|
||||
</div>
|
||||
</div>
|
||||
{{else if $u.GitRun.Running}}
|
||||
<div class="upload-overlay" role="dialog" aria-modal="true">
|
||||
<div class="upload-card wide">
|
||||
<h2>Looking at the repository…</h2>
|
||||
<progress max="100"></progress>
|
||||
<p>Reading the release tags of <code>{{$u.Repository}}</code>.</p>
|
||||
{{if $u.GitRun.Log}}<pre class="log">{{$u.GitRun.Log}}</pre>{{end}}
|
||||
<p class="muted">The page reloads when it is done.</p>
|
||||
</div>
|
||||
</div>
|
||||
{{else if $u.Pending}}
|
||||
<section class="pending"><h2>Waiting for confirmation</h2>
|
||||
<p>A new system is active and not confirmed yet. Confirm it on the <a href="/">Overview</a>, or the router goes back to the
|
||||
|
||||
+36
-2
@@ -1,16 +1,23 @@
|
||||
# Signs $release (a store path) as a binary cache and writes, into --out:
|
||||
# router-update-<version>.bundle one file to upload in the web UI
|
||||
# latest, cache/ the same, laid out for `router pulls from a URL`
|
||||
# usage: router-release --key KEYFILE [--out DIR] [--compression zstd|none]
|
||||
#
|
||||
# Run in a git checkout it also tags the commit that was released (vX.Y.Z, the
|
||||
# tags routers that update from the repository look for). The tag is local: it
|
||||
# has to be pushed with the branch. It is made last, so a release that fails
|
||||
# leaves no tag.
|
||||
# usage: router-release --key KEYFILE [--out DIR] [--compression zstd|none] [--no-tag]
|
||||
key=""
|
||||
out=dist
|
||||
compression=zstd
|
||||
tag=1
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--key) key=$2; shift ;;
|
||||
--out) out=$2; shift ;;
|
||||
--compression) compression=$2; shift ;;
|
||||
*) echo "usage: router-release --key KEYFILE [--out DIR] [--compression zstd|none]" >&2; exit 2 ;;
|
||||
--no-tag) tag=0 ;;
|
||||
*) echo "usage: router-release --key KEYFILE [--out DIR] [--compression zstd|none] [--no-tag]" >&2; exit 2 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
@@ -28,3 +35,30 @@ tar -C "$out" -cf "$out/router-update-$version.bundle" latest cache
|
||||
echo "release $version ($(du -h "$out/router-update-$version.bundle" | cut -f1)):"
|
||||
echo " upload $out/router-update-$version.bundle in the router's web UI (Update)"
|
||||
echo " or serve $out over HTTP(S) and give the router that URL"
|
||||
|
||||
if [ "$tag" -eq 1 ]; then
|
||||
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
echo " tag none: not in a git repository"
|
||||
else
|
||||
head_version=$(git show HEAD:VERSION 2>/dev/null | tr -d '\n' || true)
|
||||
if [ "$head_version" != "$version" ]; then
|
||||
echo "router-release: the commit at HEAD is version '$head_version', not $version: not tagged" >&2
|
||||
echo " (commit the version, then: git tag -a v$version -m 'Release $version')" >&2
|
||||
exit 1
|
||||
fi
|
||||
head=$(git rev-parse HEAD)
|
||||
if git rev-parse -q --verify "refs/tags/v$version" >/dev/null; then
|
||||
if [ "$(git rev-parse "v$version^{commit}")" != "$head" ]; then
|
||||
echo "router-release: v$version is already a tag of another commit" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo " tag v$version exists"
|
||||
else
|
||||
git tag -a "v$version" -m "Release $version"
|
||||
echo " tag v$version on ${head:0:7}: push it with the branch (git push origin v$version)"
|
||||
fi
|
||||
if [ "$(cat "$release/rev")" != "$head" ]; then
|
||||
echo " note the release was built from a tree that differs from HEAD (uncommitted changes)"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user