From 16745d13d9b2c24d013bdf98c6ad47fbfe3e5188 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sat, 10 Oct 2026 19:11:16 +0000 Subject: [PATCH 1/4] feat(updates): release check, backups and one-click upgrade through a machine agent Lens checks GitHub for a new release once a day, backs the database up and installs a release from the API: install.sh sets up a small agent on the machine (systemd path unit on Linux, launchd on a Mac) that watches .lens-control/inbox, reruns install.sh for the requested release and writes how it went back for the web app. Backups can be listed, taken, downloaded and deleted. __version__ now follows releases. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XturGhybJzfgZvbFxfNB2o --- .github/scripts/release.py | 2 + .github/workflows/install.yml | 21 + .gitignore | 1 + docker-compose.prod.yml | 4 + docs/database.md | 3 +- docs/updates.md | 53 ++ fastapi_backend/app/api/v1/router.py | 2 + fastapi_backend/app/api/v1/routes/updates.py | 78 +++ fastapi_backend/app/cli.py | 3 +- fastapi_backend/app/core/runtime.py | 2 + fastapi_backend/app/domain/__init__.py | 2 +- fastapi_backend/app/domain/backups.py | 72 +++ fastapi_backend/app/domain/settings.py | 14 + fastapi_backend/app/domain/store.py | 3 + fastapi_backend/app/domain/updates.py | 305 ++++++++++ fastapi_backend/app/schemas/updates.py | 63 ++ fastapi_backend/tests/api/test_updates.py | 234 +++++++ install.sh | 56 +- microsandbox/run.sh | 2 + mkdocs.yml | 1 + nextjs-frontend/app/openapi-client/index.ts | 34 ++ nextjs-frontend/app/openapi-client/sdk.gen.ts | 122 ++++ .../app/openapi-client/types.gen.ts | 368 +++++++++++ nextjs-frontend/openapi.json | 572 +++++++++++++++++- packaging/host/lens-upgrade.sh | 78 +++ 25 files changed, 2090 insertions(+), 5 deletions(-) create mode 100644 docs/updates.md create mode 100644 fastapi_backend/app/api/v1/routes/updates.py create mode 100644 fastapi_backend/app/domain/backups.py create mode 100644 fastapi_backend/app/domain/updates.py create mode 100644 fastapi_backend/app/schemas/updates.py create mode 100644 fastapi_backend/tests/api/test_updates.py create mode 100755 packaging/host/lens-upgrade.sh diff --git a/.github/scripts/release.py b/.github/scripts/release.py index 29148a75c..f39984a2b 100644 --- a/.github/scripts/release.py +++ b/.github/scripts/release.py @@ -35,6 +35,8 @@ "fastapi_backend/uv.lock": r'(^name = "lens"\nversion = ")([^"]+)(")', "nextjs-frontend/package.json": r'(^ "version": ")([^"]+)(")', "CloudronManifest.json": r'(^ "version": ")([^"]+)(")', + # what a running Lens says it is (the API, MCP, telemetry, and the update check in docs/updates.md) + "fastapi_backend/app/domain/__init__.py": r'(^__version__ = ")([^"]+)(")', } TYPES = { diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 08d3b9a91..9773d8aa4 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -16,6 +16,7 @@ on: - nextjs-frontend/Dockerfile - nextjs-frontend/package.json - nextjs-frontend/pnpm-lock.yaml + - packaging/host/** - .github/workflows/install.yml push: branches: [main] @@ -23,6 +24,7 @@ on: - install.sh - docker-compose.prod.yml - microsandbox/** + - packaging/host/** - .github/workflows/install.yml schedule: - cron: "17 4 * * 1" @@ -74,6 +76,24 @@ jobs: test "$before" = "$after" || { echo "the second run changed the secrets"; exit 1; } curl -fsS -o /dev/null "$(cat setup-url)" + - name: An upgrade asked for in the web app is installed by the machine's agent + run: | + ctl="$LENS_DIR/.lens-control" + grep -qx 'kind=systemd' "$ctl/agent" || { echo "install.sh set up no upgrade agent"; exit 1; } + # what the web app writes (docs/updates.md): the branch this install follows, as a release tag would be + printf 'id=ci\nref=%s\n' "$LENS_REF" > "$ctl/inbox/.upgrade.ci" && mv "$ctl/inbox/.upgrade.ci" "$ctl/inbox/upgrade" + i=0 + until grep -qE '^state=(done|failed)$' "$ctl/upgrade-status" 2>/dev/null; do + i=$((i + 1)); [ $i -gt 450 ] && { echo "the agent didn't finish within 15 minutes"; break; } + sleep 2 + done + cat "$ctl/upgrade-status" || true + tail -20 "$ctl/upgrade.log" || true + grep -qx 'id=ci' "$ctl/upgrade-status" && grep -qx 'state=done' "$ctl/upgrade-status" + curl -fsS -o /dev/null "$(cat setup-url)" + # and the containers see the folder, to ask for the next one + cd "$LENS_DIR" && docker compose -f docker-compose.prod.yml exec -T backend sh -c 'test -w /control/inbox && cat /control/agent' + - name: What the containers said if: failure() run: cd "$LENS_DIR" && docker compose -f docker-compose.prod.yml ps -a && docker compose -f docker-compose.prod.yml logs --tail 200 @@ -81,6 +101,7 @@ jobs: - name: Stop if: always() run: | + sudo systemctl disable --now lens-upgrade.path 2>/dev/null || true if [ -d "$LENS_DIR" ]; then cd "$LENS_DIR" docker compose -f docker-compose.prod.yml down -v || true diff --git a/.gitignore b/.gitignore index 3fdb9c328..71c68ed07 100644 --- a/.gitignore +++ b/.gitignore @@ -172,3 +172,4 @@ local-shared-data/* /.local-ci/ .lens-build .lens-sandbox +.lens-control/ diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index d373401fe..62e7df3b3 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -58,8 +58,12 @@ x-backend: &backend LENS_TELEMETRY_HEADERS: ${LENS_TELEMETRY_HEADERS:-} # the volume shared with the matterbridge service (its config, written from Settings → Chat rooms) LENS_MATTERBRIDGE_DIR: /matterbridge + # upgrading from the web app (docs/updates.md): the folder install.sh's upgrade agent watches, and the install folder + LENS_CONTROL_DIR: /control + LENS_HOST_DIR: ${LENS_DIR:-} volumes: - archive-data:/data + - ./.lens-control:/control - ${AUDIO_DIR:-./local-audio}:/audio:ro - matterbridge-data:/matterbridge depends_on: diff --git a/docs/database.md b/docs/database.md index 5aaebd3d6..393727ea8 100644 --- a/docs/database.md +++ b/docs/database.md @@ -131,7 +131,8 @@ single statements and for `run()` transactions (which roll back as a whole, so r ## Backups -`lens backup` writes one into `/backups` (Lens also takes one before upgrading the database): +`lens backup` writes one into `/backups`, as does Back up now in the web app ([Updates and backups](updates.md)); +Lens also takes one before upgrading the database or installing a release: * With a server, `manual-