From ad4be8a2a6ba16f86b2537832a204f58e237d609 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 12:30:07 +0000 Subject: [PATCH 1/3] Package Lens as a self-contained QPKG for QNAP NAS packaging/qnap/build.sh builds the images for the NAS's platform, saves them into the package with SurrealDB, and runs QDK's qbuild (in a container, so only Docker is needed). On the NAS, lens.sh loads the images into Container Station on the first start, writes lens.env with fresh secrets in a data folder that outlasts removal, logs the first-admin setup code to the QTS system log, and runs the stack with docker compose. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01KSuGMk2LX7Csu1f7pKqoFC --- CHANGELOG.md | 8 + packaging/qnap/.gitignore | 2 + packaging/qnap/README.md | 107 +++++++++ packaging/qnap/build.sh | 103 +++++++++ packaging/qnap/qpkg/icons/Lens.gif | Bin 0 -> 1948 bytes packaging/qnap/qpkg/icons/Lens_80.gif | Bin 0 -> 2289 bytes packaging/qnap/qpkg/icons/Lens_gray.gif | Bin 0 -> 1311 bytes packaging/qnap/qpkg/package_routines | 9 + packaging/qnap/qpkg/qpkg.cfg | 27 +++ packaging/qnap/qpkg/shared/docker-compose.yml | 73 ++++++ packaging/qnap/qpkg/shared/lens.sh | 207 ++++++++++++++++++ 11 files changed, 536 insertions(+) create mode 100644 packaging/qnap/.gitignore create mode 100644 packaging/qnap/README.md create mode 100755 packaging/qnap/build.sh create mode 100644 packaging/qnap/qpkg/icons/Lens.gif create mode 100644 packaging/qnap/qpkg/icons/Lens_80.gif create mode 100644 packaging/qnap/qpkg/icons/Lens_gray.gif create mode 100644 packaging/qnap/qpkg/package_routines create mode 100644 packaging/qnap/qpkg/qpkg.cfg create mode 100644 packaging/qnap/qpkg/shared/docker-compose.yml create mode 100755 packaging/qnap/qpkg/shared/lens.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index ddf835383..f07ee878a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ The backend (`fastapi_backend`) and the frontend (`nextjs-frontend`) are version ## Unreleased +- **Lens for QNAP NAS.** `packaging/qnap/build.sh` builds a self-contained QPKG (with + [QDK](https://github.com/qnap-dev/QDK)) for Intel/AMD or ARM models that installs from the App Center's Install + Manually: it carries the Lens images and SurrealDB, loads them into Container Station on its first start, and runs + the stack there, so there are no containers to set up by hand. The first start writes the settings with fresh + secrets to a data folder (`/share/Container/lens`) that outlasts removing the app, and puts the first-admin setup + code in the QTS system log; the NAS's `Multimedia` share appears in Lens as `/audio` for watched folders. + Upgrades install over the old version and remove its images. Steps in packaging/qnap/README.md. + - **Fix: Chat answers no longer break off with "The answer stopped before it finished".** With some model servers an answer ended mid-stream with nothing saved, so the question sat unanswered in the conversation. Now each one ends in an answer, or an error that's shown and saved with the conversation. diff --git a/packaging/qnap/.gitignore b/packaging/qnap/.gitignore new file mode 100644 index 000000000..0a5f58e88 --- /dev/null +++ b/packaging/qnap/.gitignore @@ -0,0 +1,2 @@ +.work/ +build/ diff --git a/packaging/qnap/README.md b/packaging/qnap/README.md new file mode 100644 index 000000000..9edc64c12 --- /dev/null +++ b/packaging/qnap/README.md @@ -0,0 +1,107 @@ +# Lens for QNAP NAS + +A self-contained QPKG, built with [QDK](https://github.com/qnap-dev/QDK), that installs Lens from the App Center like +any other app. Lens runs in **Container Station**, but you don't set up any containers: the package carries the +Lens images (API and worker, web app) and SurrealDB, loads them on its first start, and runs the stack. Nothing is +built or downloaded on the NAS. + +- **NAS:** QTS 5 or QuTS hero 5 with Container Station 3, on an Intel/AMD (`x86_64`) or ARM 64-bit (`arm_64`) model. + 4 GB of RAM or more; transcription and the full image's document conversion are heavy. +- **Space:** a few GB on the volume: the package's image files while they're loaded on the first start (they're + deleted afterwards), the images in Container Station, and whatever your archive holds. + +## Build the package + +On any machine with Docker and buildx (Linux, macOS, Windows with WSL), from the repository root: + +```bash +packaging/qnap/build.sh # Intel/AMD NAS: packaging/qnap/build/Lens_0.3.0_x86_64.qpkg +packaging/qnap/build.sh --arch arm_64 # ARM NAS: packaging/qnap/build/Lens_0.3.0_arm_64.qpkg +``` + +- The version comes from `fastapi_backend/pyproject.toml` (`--version` overrides it, 10 characters at most). +- The backend image is the `full` target by default, as `make run` uses: LibreOffice and Chromium to read Office files, + text, web pages and emails, and object detection. `--target lean` makes a much smaller package that reads PDFs + and images only. `--extras "msg"` adds Outlook `.msg` emails (see docs/deployment.md). +- Building for the other architecture than your machine's uses QEMU. Docker Desktop has it; on Linux, once: + `docker run --privileged --rm tonistiigi/binfmt --install arm64` (or `amd64`). It's slow; building on a machine of + the NAS's architecture is quicker. +- The first run builds a small `lens-qdk` image with QDK in it, so QDK needn't be installed. +- `--prebuilt` packages the `lens-backend:` and `lens-frontend:` images already in Docker instead + of building them (from CI, say). + +## Install on the NAS + +1. Install **Container Station** from the App Center and open it once, so it finishes its setup. +2. App Center > the gear icon (top right) > **Install Manually** > choose the `.qpkg` for your NAS > **Install**. + QTS warns that the app isn't digitally signed; accept to continue. (Or, over SSH: + `sh Lens_0.3.0_x86_64.qpkg`.) +3. The first start loads the images into Container Station, which takes a few minutes. When Lens shows as running, + click **Open** in the App Center (or browse to `http://:3000`). +4. Create the first admin account with the **setup code**. It's in the QTS system log (Control Panel > System > + System Logs, an entry from Lens saying "create the first admin account with setup code …"), in `lens.env` in the + data folder (`LENS_SETUP_CODE`), and over SSH: `/share/CACHEDEV1_DATA/.qpkg/Lens/lens.sh setup-code` (the + path depends on the volume you installed to: `getcfg Lens Install_Path -f /etc/config/qpkg.conf`). + +The containers show up in Container Station as the application `lens` (surrealdb, backend, worker, frontend), where +you can see their logs and resource use. + +## Where things are + +The **data folder** is `/share/Container/lens` (the `Container` shared folder Container Station creates), or +`Lens-data` next to the app's folder if that share doesn't exist. It holds: + +| Path | What | +|---|---| +| `lens.env` | Settings and secrets, written on the first start. Keep it with the rest: losing `ARCHIVE_SECRET_KEY` makes stored credentials and model API keys unreadable. | +| `surrealdb/` | The database. | +| `archive/` | Uploads, media and derived files. | + +Back up the whole folder (Hybrid Backup Sync works, as it's a shared folder) with Lens stopped. Removing the app keeps +the data folder and drops the images; reinstalling picks up where it was. Delete the folder yourself to remove +everything. + +Your **recordings and documents** on the NAS appear inside Lens as `/audio` (read-only), for watched folders. By +default that's the `Multimedia` share; set `AUDIO_DIR` in `lens.env` to use another folder. + +## Settings + +Edit `lens.env` in the data folder, then stop and start Lens in the App Center (or `lens.sh restart` over SSH). + +- **Address and port.** `FRONTEND_URL` is the NAS's LAN address at install time, `http://:3000`. Change it, and + add the host name to `ARCHIVE_ALLOWED_HOSTS`, if you reach Lens another way: a fixed host name, a reverse proxy with + HTTPS (QTS's own reverse proxy in Control Panel > Network Access, or myQNAPcloud), or if the NAS's address changes. + For another port set `LENS_PORT` and the port in `FRONTEND_URL` alike. Sharing and IIIF need HTTPS. +- **Mail** for password resets: the `MAIL_*` settings. +- **Models.** Lens talks to OpenAI-compatible servers; set them up in the web app. A model server on the NAS itself + (Ollama in Container Station, say) is reachable at the NAS's LAN address, not `localhost`. +- To move the data folder: stop Lens, move the folder, then + `setcfg Lens Data_Path /share/ -f /etc/config/qpkg.conf` and start Lens. + +## Over SSH + +`lens.sh` in the app's folder (`getcfg Lens Install_Path -f /etc/config/qpkg.conf`): + +```bash +lens.sh status # the containers +lens.sh logs [backend] # follow the logs (all, or one service) +lens.sh setup-code # the first-admin setup code +lens.sh restart +``` + +## Upgrading + +Build the new version's package and install it over the old one, as in step 2. The new images are loaded on the +next start and the old version's are removed; the data folder carries over. + +## How the package is made + +`build.sh` builds the images for the NAS's platform, saves them into `/images/` next to the `qpkg/` sources +(with a `manifest` naming each one), and runs QDK's `qbuild` on the lot. In the package: + +- `qpkg.cfg`: requires Container Station 3, opens the web app on port 3000, gives the first start 15 minutes. +- `lens.sh`: the service script. On start it waits for Container Station's Docker, writes `lens.env` with fresh + secrets on the first run, loads any image that isn't in Docker yet, and runs `docker compose up` on + `docker-compose.yml` as the project `lens`. On removal it stops the stack and removes the Lens images. +- `docker-compose.yml`: the same stack as `docker-compose.prod.yml`, with the bundled images, the data folder as bind + mounts and the web app on the NAS's port 3000. diff --git a/packaging/qnap/build.sh b/packaging/qnap/build.sh new file mode 100755 index 000000000..bd6873ce8 --- /dev/null +++ b/packaging/qnap/build.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +# Builds the Lens QPKG for QNAP NAS: one self-contained .qpkg per architecture, with the Lens images (API and worker, +# web app) and SurrealDB inside, so the NAS needs nothing but Container Station. +# +# packaging/qnap/build.sh # x86_64 (Intel and AMD NAS), the full image +# packaging/qnap/build.sh --arch arm_64 # ARM NAS (on an x86 machine this needs QEMU, see README.md) +# packaging/qnap/build.sh --arch x86_64 --arch arm_64 --target lean --extras "msg" +# +# Needs only Docker with buildx (Linux, macOS, or Windows with WSL); QDK runs in a container built the first time. +# Output: packaging/qnap/build/Lens__.qpkg +set -euo pipefail + +HERE=$(cd "$(dirname "$0")" && pwd) +REPO=$(cd "$HERE/../.." && pwd) +QDK_REF=v2.5.3 +WORK="$HERE/.work" +OUT="$HERE/build" +SURREAL_IMAGE=surrealdb/surrealdb:v3.2.4 + +ARCHES=() +TARGET=full # full: LibreOffice and Chromium, to read Office files, text, web pages and emails (as `make run`) +EXTRAS="" +PREBUILT="" # --prebuilt: package the lens-backend: and lens-frontend: images already in Docker +VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' "$REPO/fastapi_backend/pyproject.toml" | head -n 1) + +while [ $# -gt 0 ]; do + case "$1" in + --arch) ARCHES+=("$2"); shift 2 ;; + --target) TARGET="$2"; shift 2 ;; + --extras) EXTRAS="$2"; shift 2 ;; + --version) VERSION="$2"; shift 2 ;; + --prebuilt) PREBUILT=yes; shift ;; + -h|--help) sed -n '2,10p' "$0"; exit 0 ;; + *) echo "unknown option: $1" >&2; exit 2 ;; + esac +done +[ ${#ARCHES[@]} -gt 0 ] || ARCHES=(x86_64) +[ ${#VERSION} -le 10 ] || { echo "QPKG versions are at most 10 characters: $VERSION" >&2; exit 2; } + +platform_of() { + case "$1" in + x86_64) echo linux/amd64 ;; + arm_64) echo linux/arm64 ;; + *) echo "unsupported architecture: $1 (x86_64 or arm_64)" >&2; exit 2 ;; + esac +} +for a in "${ARCHES[@]}"; do platform_of "$a" >/dev/null; done + +# --- QDK, in a small Linux image of its own (qbuild expects GNU tools under /bin) -------------------------------- +docker image inspect "lens-qdk:${QDK_REF#v}" >/dev/null 2>&1 || +docker build -q -t "lens-qdk:${QDK_REF#v}" --build-arg QDK_REF="$QDK_REF" - >/dev/null <<'DOCKERFILE' +FROM debian:bookworm-slim +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates git gcc libc6-dev rsync bsdextrautils \ + && rm -rf /var/lib/apt/lists/* +ARG QDK_REF +RUN git clone -q --depth 1 --branch "$QDK_REF" https://github.com/qnap-dev/QDK.git /tmp/QDK \ + && cp -R /tmp/QDK/shared /usr/share/QDK && mkdir -p /etc/config \ + && printf 'QDK_VERSION=%s\nQDK_PATH=/usr/share/QDK\n' "${QDK_REF#v}" > /etc/config/qdk.conf \ + && gcc -o /usr/local/bin/qpkg_encrypt /tmp/QDK/src/qpkg_encrypt.c && rm -rf /tmp/QDK +ENV PATH="/usr/share/QDK/bin:$PATH" +DOCKERFILE + +qbuild() { + docker run --rm -u "$(id -u):$(id -g)" -v "$HERE:/qnap" -w /qnap/.work "lens-qdk:${QDK_REF#v}" qbuild "$@" +} + +save_args=() +mkdir -p "$OUT" +for arch in "${ARCHES[@]}"; do + platform=$(platform_of "$arch") + echo "==> Lens $VERSION for $arch ($platform), backend target $TARGET" + + rm -rf "$WORK" + mkdir -p "$WORK" + cp -R "$HERE/qpkg/." "$WORK/" + images="$WORK/$arch/images" + mkdir -p "$images" + + if [ -z "$PREBUILT" ]; then + docker buildx build --platform "$platform" --target "$TARGET" --build-arg EXTRAS="$EXTRAS" \ + --load -t "lens-backend:$VERSION" "$REPO/fastapi_backend" + docker buildx build --platform "$platform" -f "$REPO/nextjs-frontend/Dockerfile.prod" \ + --load -t "lens-frontend:$VERSION" "$REPO/nextjs-frontend" + fi + [ "$(docker image inspect -f '{{.Os}}/{{.Architecture}}' "$SURREAL_IMAGE" 2>/dev/null)" = "$platform" ] || + docker pull -q --platform "$platform" "$SURREAL_IMAGE" + + # With Docker's containerd image store, save only the platform being packaged + docker save --help 2>/dev/null | grep -q -- '--platform' && save_args=(--platform "$platform") + : > "$images/manifest" + for ref in "lens-backend:$VERSION" "lens-frontend:$VERSION" "$SURREAL_IMAGE"; do + got=$(docker image inspect -f '{{.Os}}/{{.Architecture}}' "$ref") + [ "$got" = "$platform" ] || { echo "$ref is $got, expected $platform" >&2; exit 1; } + file=$(echo "$ref" | tr '/:' '__').tar # left uncompressed: qbuild compresses the whole package + echo " saving $ref" + docker save ${save_args[@]+"${save_args[@]}"} -o "$images/$file" "$ref" + echo "$ref $file" >> "$images/manifest" + done + + qbuild --build-arch "$arch" --build-version "$VERSION" --build-dir /qnap/build +done +rm -rf "$WORK" +ls -lh "$OUT"/*.qpkg diff --git a/packaging/qnap/qpkg/icons/Lens.gif b/packaging/qnap/qpkg/icons/Lens.gif new file mode 100644 index 0000000000000000000000000000000000000000..319bc77ac1b32996c001eff0484222549c1d9483 GIT binary patch literal 1948 zcmdUu`9Bkk1Auqr?tQai%^dA!b8VWd?^oI8m?E1Nd0#b?P~vSwswvy>Wpd|EjU21U zkqSw}mb03xR8k9-N{;AI@_za=zR&X)JU=`hp6-rLTo-@~;41(Cfk2>8sGgplzP`SJ zfdLE#+q`)*91b@$G(;c}Mn*;^CMKq)rdzgbK_ZbT6bg+-V=x#j7K_8-@OZqLnVGq{ zIe|bR5{VWT7M7NlR#sNl*48#QHY5^>OeWjf+HT#tl|rG|+1c6K+dDWoI668yJ3DXR zzJ14z9WE{|R4SE5qtWSfS65dL4-ZdI&z(DW?%K7>%gf8#+k5x!-9A1(OeT}XV)^>| z?%A`4&1U=g`T6_%2LuEJ1_timzyH9213^JSTrM{_IQZbfgCQXyhYlSI4Gj$o3kweq zKYaLbWMpJiR8(|ybWBXl@#Dv1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cmV?d00001 diff --git a/packaging/qnap/qpkg/icons/Lens_gray.gif b/packaging/qnap/qpkg/icons/Lens_gray.gif new file mode 100644 index 0000000000000000000000000000000000000000..14f1da9cd6b2764161fecea45a49d9c059fa8e87 GIT binary patch literal 1311 zcmd6k3sVvX0DzHHawjc|TxqQU(Oj=X?L`w68;a<(GE*=W6e0{o1f0tU0?Jz+f+&LW zQWVWl%RF*-KDr*8y6Q4D)0%EgTixuvb}P63#lBzg-S@@eu!jzlq5;u>w*Wv!Mh1aE zAQFk0nVF|gpU%q4%FfQt$;ly+NMtfOH#avgFONc@P^nZJjdu3zSvsAbpPzs3+&Kn= zQBY7&SXjtpGK-3eSS(g?aWR|C=5RP%F1Mtlq_nj3{Q2``Wo6~%DL?V$&r81dJE|)75irU&*rBbO z9u;^;+*eHBUf6mi2+mg=xeYWO+!i?RQ3WiPu-ohZ1htW%l+JG1tRY=2JY28+v%K>20vKQV&$77 zU~v_`87#Rvt%n<+E(nJ8KgGy`p`S&B!_P#0>E7k$Tp6_NrV)FguD)U5`m6KL6ZbfJ z#)MnH<0-d1^Z$c(DSg7|je;W^@XBNVNEVX3$YCcEF_wo^_9{INU+l-Cq8_8@DaN<= zoQ_%R8`Dx}+#7jve)rKBq6Q@L)lCrPfZ%D^=j=;IOZC6L6Z!>ErWAgF1DMQk7h+_d zVPsMt;@<9$4M5Bt4qrI)l5-g+N&d@~N=jSS-Sk+AO#db7rHLjH?MdK}m|+!ZiyIT5 z$D^g&uD7pUl_f9TTwC|bXGSgs({ry?02`<_cvL~%JT&lo!7Snf^3@~Qx(yx80Pnl6 zhM_*FQ8R+%es>B(y(@|rqfk?W67EZk&gTS+SH5 zQkG{1MTvVd-4j7WJ%J7};7dEpHo4niT_dec;{01TCNGO<%QM;i7+3r+(Tv)V+MlvWH;CJ@Ecp{H4JrR`f6=PJBI{c9?PI_5tJFy?4J}M~l z`V+$3HMlS1@p5uZn640ww!1v8A|qCYyhF$OlH4CR!<64lq~{6O<8D6#M System Logs), where the first-admin setup code is easiest to find + say "$1" + /sbin/write_log "[$QPKG_NAME] $1" "${2:-4}" 2>/dev/null || /sbin/log_tool -t "${3:-0}" -a "[$QPKG_NAME] $1" 2>/dev/null || true +} +fail() { syslog "$1" 1 2; exit 1; } + +# --- Container Station ------------------------------------------------------------------------------------------ +CS_ROOT=$(/sbin/getcfg container-station Install_Path -f $CONF) +export PATH="$CS_ROOT/bin:$CS_ROOT/usr/bin:$PATH" +DOCKER=$(command -v docker || echo "$CS_ROOT/bin/docker") + +compose() { + if "$DOCKER" compose version >/dev/null 2>&1; then + "$DOCKER" compose -p lens -f "$COMPOSE_FILE" --env-file "$LENS_DATA/lens.env" "$@" + elif command -v docker-compose >/dev/null 2>&1; then + docker-compose -p lens -f "$COMPOSE_FILE" --env-file "$LENS_DATA/lens.env" "$@" + else + fail "Docker Compose was not found in Container Station ($CS_ROOT). Update Container Station to version 3." + fi +} + +wait_for_docker() { # at boot, Container Station may still be starting + i=0 + until "$DOCKER" info >/dev/null 2>&1; do + i=$((i + 1)) + [ $i -gt 90 ] && fail "Container Station's Docker engine is not running. Start Container Station, then Lens." + sleep 2 + done +} + +# --- The data folder and lens.env ------------------------------------------------------------------------------- +data_path() { + p=$(/sbin/getcfg $QPKG_NAME Data_Path -f $CONF) + if [ -z "$p" ]; then + if [ -d /share/Container ]; then p=/share/Container/lens; else p="$(dirname "$QPKG_ROOT")/Lens-data"; fi + /sbin/setcfg $QPKG_NAME Data_Path "$p" -f $CONF + fi + echo "$p" +} +LENS_DATA=$(data_path) + +random_hex() { openssl rand -hex "$1" 2>/dev/null || head -c "$1" /dev/urandom | od -An -tx1 | tr -d ' \n'; } + +lan_address() { + a=$(ip -4 route get 1.1.1.1 2>/dev/null | sed -n 's/.* src \([0-9.]*\).*/\1/p' | head -n 1) + [ -n "$a" ] || a=$(ifconfig 2>/dev/null | sed -n 's/.*inet addr:\([0-9.]*\).*/\1/p' | grep -v '^127\.' | head -n 1) + [ -n "$a" ] || a=$(hostname) + echo "$a" +} + +write_env() { + host=$(lan_address) + hosts=backend + for h in localhost 127.0.0.1 "$host" "$(hostname)"; do + case ",$hosts," in *",$h,"*) ;; *) hosts="$hosts,$h" ;; esac + done + if [ -d /share/Multimedia ]; then audio=/share/Multimedia; else audio="$LENS_DATA/audio"; fi + umask 077 + cat > "$LENS_DATA/lens.env" < " per line. Each image is loaded once; its file is then deleted to give +# the space back (an upgrade brings new ones). Images of earlier Lens versions are removed after an upgrade. +load_images() { + [ -f "$IMAGES_DIR/manifest" ] || return 0 + while read -r ref file; do + [ -n "$ref" ] || continue + if ! "$DOCKER" image inspect "$ref" >/dev/null 2>&1; then + [ -f "$IMAGES_DIR/$file" ] || fail "The image $ref is missing and its file is gone. Reinstall Lens from the .qpkg file." + say "loading $ref (first start after install or upgrade; this takes a few minutes)" + "$DOCKER" load -i "$IMAGES_DIR/$file" >/dev/null || fail "Could not load $ref into Container Station (is the volume full?)." + fi + rm -f "$IMAGES_DIR/$file" + done < "$IMAGES_DIR/manifest" + for repo in lens-backend lens-frontend; do + "$DOCKER" image ls --format '{{.Repository}}:{{.Tag}}' "$repo" 2>/dev/null | grep -v ":$LENS_VERSION\$" | while read -r old; do + "$DOCKER" image rm "$old" >/dev/null 2>&1 || true + done + done +} + +# --- Commands --------------------------------------------------------------------------------------------------- +export LENS_VERSION LENS_DATA +FIRST_START="" + +case "$1" in + start) + ENABLED=$(/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF) + if [ "$ENABLED" != "TRUE" ]; then + say "disabled in the App Center." + exit 1 + fi + wait_for_docker + prepare_data + load_images + compose up -d --remove-orphans || fail "The containers did not start. Details: $QPKG_ROOT/lens.sh logs" + if [ -n "$FIRST_START" ]; then + syslog "Open $(env_value FRONTEND_URL) and create the first admin account with setup code $(env_value LENS_SETUP_CODE). Settings: $LENS_DATA/lens.env" + else + say "running at $(env_value FRONTEND_URL)" + fi + ;; + + stop) + "$DOCKER" info >/dev/null 2>&1 || exit 0 # Container Station already stopped (shutdown): its containers are too + [ -f "$LENS_DATA/lens.env" ] && compose down --remove-orphans + ;; + + restart) + $0 stop + $0 start + ;; + + status) + compose ps + ;; + + logs) + shift + compose logs --tail 200 -f "$@" + ;; + + setup-code) + echo "Open $(env_value FRONTEND_URL) and create the first admin with setup code: $(env_value LENS_SETUP_CODE)" + echo "(It works only until the first account exists.)" + ;; + + remove) + # Called by the uninstaller: stop the stack and drop its images. The data folder stays. + if "$DOCKER" info >/dev/null 2>&1; then + [ -f "$LENS_DATA/lens.env" ] && compose down --remove-orphans + for repo in lens-backend lens-frontend; do + "$DOCKER" image ls --format '{{.Repository}}:{{.Tag}}' "$repo" 2>/dev/null | while read -r img; do + "$DOCKER" image rm "$img" >/dev/null 2>&1 || true + done + done + fi + syslog "Removed. The data folder $LENS_DATA was kept; delete it to remove the database and archive too." + ;; + + *) + echo "Usage: $0 {start|stop|restart|status|logs [service]|setup-code}" + exit 1 + ;; +esac + +exit 0 From 01bbfba6f74437969075f4da278d36f92b7bce2e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 12:35:03 +0000 Subject: [PATCH 2/3] Build the QNAP packages for each published release .github/workflows/qnap.yml builds the x86_64 and arm_64 QPKGs when a release is published (or by hand for a tag) and attaches them to the release. ARM builds run under QEMU unless the QNAP_ARM_RUNNER variable names an ARM runner. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01KSuGMk2LX7Csu1f7pKqoFC --- .github/workflows/qnap.yml | 67 ++++++++++++++++++++++++++++++++++++++ CHANGELOG.md | 3 +- packaging/qnap/README.md | 5 +++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/qnap.yml diff --git a/.github/workflows/qnap.yml b/.github/workflows/qnap.yml new file mode 100644 index 000000000..ece9e9826 --- /dev/null +++ b/.github/workflows/qnap.yml @@ -0,0 +1,67 @@ +name: QNAP packages + +# Builds the Lens QPKGs (packaging/qnap) for Intel/AMD and ARM NAS and attaches them to the release. +# Runs when a release is published (release.yml makes the draft; publishing it starts this), or by hand for a tag. +on: + release: + types: [published] + workflow_dispatch: + inputs: + tag: + description: "Release tag to build and attach the packages to" + required: true + type: string + +permissions: + contents: write + +concurrency: + group: qnap-${{ github.event.release.tag_name || inputs.tag }} + cancel-in-progress: false + +jobs: + qpkg: + name: QPKG ${{ matrix.arch }} + strategy: + fail-fast: false + matrix: + include: + - arch: x86_64 + runner: ubuntu-latest + # Built under QEMU unless the repository variable QNAP_ARM_RUNNER names an ARM runner (ubuntu-24.04-arm) + - arch: arm_64 + runner: ${{ vars.QNAP_ARM_RUNNER || 'ubuntu-latest' }} + runs-on: ${{ matrix.runner }} + timeout-minutes: 300 + env: + TAG: ${{ github.event.release.tag_name || inputs.tag }} + GH_TOKEN: ${{ github.token }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ env.TAG }} + + - name: Make room for the images + run: | + sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL + docker system prune -af >/dev/null + df -h / + + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + with: + driver: docker # images go straight into the local Docker, where build.sh saves them from + + - name: Build the package + run: | + version="${TAG#v}" + packaging/qnap/build.sh --arch "${{ matrix.arch }}" --version "$version" + + - name: Attach to the release + run: | + ls -lh packaging/qnap/build/ + # GitHub release assets are limited to 2 GiB each + for f in packaging/qnap/build/*.qpkg; do + [ "$(stat -c %s "$f")" -lt 2147483648 ] || { echo "::error::$f is over 2 GiB, too big for a release asset"; exit 1; } + done + gh release upload "$TAG" packaging/qnap/build/*.qpkg packaging/qnap/build/*.qpkg.md5 --clobber diff --git a/CHANGELOG.md b/CHANGELOG.md index f07ee878a..5310f194d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ The backend (`fastapi_backend`) and the frontend (`nextjs-frontend`) are version the stack there, so there are no containers to set up by hand. The first start writes the settings with fresh secrets to a data folder (`/share/Container/lens`) that outlasts removing the app, and puts the first-admin setup code in the QTS system log; the NAS's `Multimedia` share appears in Lens as `/audio` for watched folders. - Upgrades install over the old version and remove its images. Steps in packaging/qnap/README.md. + Upgrades install over the old version and remove its images. Publishing a GitHub release builds both packages and + attaches them to it (`.github/workflows/qnap.yml`). Steps in packaging/qnap/README.md. - **Fix: Chat answers no longer break off with "The answer stopped before it finished".** With some model servers an answer ended mid-stream with nothing saved, so the question sat unanswered in the conversation. Now each one ends diff --git a/packaging/qnap/README.md b/packaging/qnap/README.md index 9edc64c12..5aa060618 100644 --- a/packaging/qnap/README.md +++ b/packaging/qnap/README.md @@ -30,6 +30,11 @@ packaging/qnap/build.sh --arch arm_64 # ARM NAS: packaging/qnap/build - `--prebuilt` packages the `lens-backend:` and `lens-frontend:` images already in Docker instead of building them (from CI, say). +Releases get the packages automatically: publishing a GitHub release runs `.github/workflows/qnap.yml`, which builds +both and attaches `Lens__x86_64.qpkg` and `Lens__arm_64.qpkg` to it (run it by hand from the Actions tab, +with a tag, to rebuild them). The ARM package is built under QEMU, which is slow; set the repository variable +`QNAP_ARM_RUNNER` to an ARM runner (`ubuntu-24.04-arm`) if the repository has one. + ## Install on the NAS 1. Install **Container Station** from the App Center and open it once, so it finishes its setup. From 18f716e05ddfcacee8de0ca632ad54063814c8f9 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 12:52:26 +0000 Subject: [PATCH 3/3] QNAP: own config and folder, own image tags, lean by default, setup answers from lens.env - A QNAP archive.yaml (mounted read-only) with a media namespace on /audio, and /audio is now just Multimedia/Lens, created on the first start, not the whole share. - The package's images are tagged qnap-; upgrades and removal touch only those, so Lens images built some other way (lens-backend:prod) stay. - build.sh builds the lean backend by default (--target full for documents). - The compose file passes the LENS_ADMIN_*, LENS_NAMESPACE, LENS_LLM_* and LENS_SETUP_WIZARD settings through from lens.env, empty by default. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01KSuGMk2LX7Csu1f7pKqoFC --- CHANGELOG.md | 2 +- packaging/qnap/README.md | 24 ++++++++++++------- packaging/qnap/build.sh | 14 +++++------ packaging/qnap/qpkg/shared/archive.yaml | 14 +++++++++++ packaging/qnap/qpkg/shared/docker-compose.yml | 18 +++++++++++--- packaging/qnap/qpkg/shared/lens.sh | 24 +++++++++++++++---- 6 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 packaging/qnap/qpkg/shared/archive.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 5310f194d..64a0cd44b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ The backend (`fastapi_backend`) and the frontend (`nextjs-frontend`) are version Manually: it carries the Lens images and SurrealDB, loads them into Container Station on its first start, and runs the stack there, so there are no containers to set up by hand. The first start writes the settings with fresh secrets to a data folder (`/share/Container/lens`) that outlasts removing the app, and puts the first-admin setup - code in the QTS system log; the NAS's `Multimedia` share appears in Lens as `/audio` for watched folders. + code in the QTS system log; files put in `Multimedia/Lens` on the NAS are picked up into a `media` namespace. Upgrades install over the old version and remove its images. Publishing a GitHub release builds both packages and attaches them to it (`.github/workflows/qnap.yml`). Steps in packaging/qnap/README.md. diff --git a/packaging/qnap/README.md b/packaging/qnap/README.md index 5aa060618..37c525091 100644 --- a/packaging/qnap/README.md +++ b/packaging/qnap/README.md @@ -6,7 +6,7 @@ Lens images (API and worker, web app) and SurrealDB, loads them on its first sta built or downloaded on the NAS. - **NAS:** QTS 5 or QuTS hero 5 with Container Station 3, on an Intel/AMD (`x86_64`) or ARM 64-bit (`arm_64`) model. - 4 GB of RAM or more; transcription and the full image's document conversion are heavy. + 4 GB of RAM or more; transcription is heavy. - **Space:** a few GB on the volume: the package's image files while they're loaded on the first start (they're deleted afterwards), the images in Container Station, and whatever your archive holds. @@ -20,15 +20,16 @@ packaging/qnap/build.sh --arch arm_64 # ARM NAS: packaging/qnap/build ``` - The version comes from `fastapi_backend/pyproject.toml` (`--version` overrides it, 10 characters at most). -- The backend image is the `full` target by default, as `make run` uses: LibreOffice and Chromium to read Office files, - text, web pages and emails, and object detection. `--target lean` makes a much smaller package that reads PDFs - and images only. `--extras "msg"` adds Outlook `.msg` emails (see docs/deployment.md). +- The backend image is the `lean` target by default: it reads audio, video, PDFs and images. `--target full` adds + LibreOffice and Chromium, to read Office files, text, web pages and emails, and object detection, for a much bigger + package. `--extras "msg"` adds Outlook `.msg` emails (see docs/deployment.md). - Building for the other architecture than your machine's uses QEMU. Docker Desktop has it; on Linux, once: `docker run --privileged --rm tonistiigi/binfmt --install arm64` (or `amd64`). It's slow; building on a machine of the NAS's architecture is quicker. - The first run builds a small `lens-qdk` image with QDK in it, so QDK needn't be installed. -- `--prebuilt` packages the `lens-backend:` and `lens-frontend:` images already in Docker instead - of building them (from CI, say). +- The package's images are tagged `lens-backend:qnap-` and `lens-frontend:qnap-`, so they never + clash with Lens images built some other way. `--prebuilt` packages images with those tags already in Docker + instead of building them (from CI, say). Releases get the packages automatically: publishing a GitHub release runs `.github/workflows/qnap.yml`, which builds both and attaches `Lens__x86_64.qpkg` and `Lens__arm_64.qpkg` to it (run it by hand from the Actions tab, @@ -66,8 +67,10 @@ Back up the whole folder (Hybrid Backup Sync works, as it's a shared folder) wit the data folder and drops the images; reinstalling picks up where it was. Delete the folder yourself to remove everything. -Your **recordings and documents** on the NAS appear inside Lens as `/audio` (read-only), for watched folders. By -default that's the `Multimedia` share; set `AUDIO_DIR` in `lens.env` to use another folder. +Your **recordings and documents**: Lens sees one folder on the NAS, `Lens` in the `Multimedia` share +(`/share/Multimedia/Lens`, created on the first start), as `/audio`, read-only. Files you put there are picked up into +the `media` namespace, and its subfolders can be watched from the web app. Set `AUDIO_DIR` in `lens.env` to use another +folder. The package's `archive.yaml` sets this up; settings changed in the web app are kept in the database. ## Settings @@ -78,6 +81,8 @@ Edit `lens.env` in the data folder, then stop and start Lens in the App Center ( HTTPS (QTS's own reverse proxy in Control Panel > Network Access, or myQNAPcloud), or if the NAS's address changes. For another port set `LENS_PORT` and the port in `FRONTEND_URL` alike. Sharing and IIIF need HTTPS. - **Mail** for password resets: the `MAIL_*` settings. +- **Unattended setup.** The `LENS_ADMIN_*`, `LENS_NAMESPACE`, `LENS_LLM_*` and `LENS_SETUP_WIZARD` settings answer the + first-run setup instead of the web app (see docs/configuration.md); empty ones are left to the web app. - **Models.** Lens talks to OpenAI-compatible servers; set them up in the web app. A model server on the NAS itself (Ollama in Container Station, say) is reachable at the NAS's LAN address, not `localhost`. - To move the data folder: stop Lens, move the folder, then @@ -107,6 +112,7 @@ next start and the old version's are removed; the data folder carries over. - `qpkg.cfg`: requires Container Station 3, opens the web app on port 3000, gives the first start 15 minutes. - `lens.sh`: the service script. On start it waits for Container Station's Docker, writes `lens.env` with fresh secrets on the first run, loads any image that isn't in Docker yet, and runs `docker compose up` on - `docker-compose.yml` as the project `lens`. On removal it stops the stack and removes the Lens images. + `docker-compose.yml` as the project `lens`. On removal it stops the stack and removes its own images (tagged `qnap-`). - `docker-compose.yml`: the same stack as `docker-compose.prod.yml`, with the bundled images, the data folder as bind mounts and the web app on the NAS's port 3000. +- `archive.yaml`: the processing configuration, with the `media` namespace on `/audio`. diff --git a/packaging/qnap/build.sh b/packaging/qnap/build.sh index bd6873ce8..b0dd1522d 100755 --- a/packaging/qnap/build.sh +++ b/packaging/qnap/build.sh @@ -2,9 +2,9 @@ # Builds the Lens QPKG for QNAP NAS: one self-contained .qpkg per architecture, with the Lens images (API and worker, # web app) and SurrealDB inside, so the NAS needs nothing but Container Station. # -# packaging/qnap/build.sh # x86_64 (Intel and AMD NAS), the full image +# packaging/qnap/build.sh # x86_64 (Intel and AMD NAS), the lean image # packaging/qnap/build.sh --arch arm_64 # ARM NAS (on an x86 machine this needs QEMU, see README.md) -# packaging/qnap/build.sh --arch x86_64 --arch arm_64 --target lean --extras "msg" +# packaging/qnap/build.sh --arch x86_64 --arch arm_64 --target full --extras "msg" # # Needs only Docker with buildx (Linux, macOS, or Windows with WSL); QDK runs in a container built the first time. # Output: packaging/qnap/build/Lens__.qpkg @@ -18,9 +18,9 @@ OUT="$HERE/build" SURREAL_IMAGE=surrealdb/surrealdb:v3.2.4 ARCHES=() -TARGET=full # full: LibreOffice and Chromium, to read Office files, text, web pages and emails (as `make run`) +TARGET=lean # full: adds LibreOffice and Chromium, to read Office files, text, web pages and emails EXTRAS="" -PREBUILT="" # --prebuilt: package the lens-backend: and lens-frontend: images already in Docker +PREBUILT="" # --prebuilt: package the lens-backend:qnap- and lens-frontend:qnap- images already in Docker VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' "$REPO/fastapi_backend/pyproject.toml" | head -n 1) while [ $# -gt 0 ]; do @@ -78,9 +78,9 @@ for arch in "${ARCHES[@]}"; do if [ -z "$PREBUILT" ]; then docker buildx build --platform "$platform" --target "$TARGET" --build-arg EXTRAS="$EXTRAS" \ - --load -t "lens-backend:$VERSION" "$REPO/fastapi_backend" + --load -t "lens-backend:qnap-$VERSION" "$REPO/fastapi_backend" docker buildx build --platform "$platform" -f "$REPO/nextjs-frontend/Dockerfile.prod" \ - --load -t "lens-frontend:$VERSION" "$REPO/nextjs-frontend" + --load -t "lens-frontend:qnap-$VERSION" "$REPO/nextjs-frontend" fi [ "$(docker image inspect -f '{{.Os}}/{{.Architecture}}' "$SURREAL_IMAGE" 2>/dev/null)" = "$platform" ] || docker pull -q --platform "$platform" "$SURREAL_IMAGE" @@ -88,7 +88,7 @@ for arch in "${ARCHES[@]}"; do # With Docker's containerd image store, save only the platform being packaged docker save --help 2>/dev/null | grep -q -- '--platform' && save_args=(--platform "$platform") : > "$images/manifest" - for ref in "lens-backend:$VERSION" "lens-frontend:$VERSION" "$SURREAL_IMAGE"; do + for ref in "lens-backend:qnap-$VERSION" "lens-frontend:qnap-$VERSION" "$SURREAL_IMAGE"; do got=$(docker image inspect -f '{{.Os}}/{{.Architecture}}' "$ref") [ "$got" = "$platform" ] || { echo "$ref is $got, expected $platform" >&2; exit 1; } file=$(echo "$ref" | tr '/:' '__').tar # left uncompressed: qbuild compresses the whole package diff --git a/packaging/qnap/qpkg/shared/archive.yaml b/packaging/qnap/qpkg/shared/archive.yaml new file mode 100644 index 000000000..c8c8d81f1 --- /dev/null +++ b/packaging/qnap/qpkg/shared/archive.yaml @@ -0,0 +1,14 @@ +# Processing configuration for Lens on a QNAP NAS (lens.sh mounts it read-only; settings changed in the app are kept in +# the database). The folder AUDIO_DIR in lens.env (/share/Multimedia/Lens by default) appears inside Lens as /audio. +data_dir: /data +namespaces: + media: + paths: [/audio] # recordings and documents put in that folder are picked up here + graph: shared +server: + # "backend" is the Host the web app uses to reach the API inside the compose network + allowed_hosts: [127.0.0.1, localhost, backend] +workers: + inline: 0 # the worker service does the work +sources: + local_roots: [/audio] # folders the web app may watch diff --git a/packaging/qnap/qpkg/shared/docker-compose.yml b/packaging/qnap/qpkg/shared/docker-compose.yml index 9e5cb0460..2eab62b62 100644 --- a/packaging/qnap/qpkg/shared/docker-compose.yml +++ b/packaging/qnap/qpkg/shared/docker-compose.yml @@ -1,12 +1,13 @@ # The Lens stack on a QNAP NAS, run by lens.sh in Container Station's Docker engine (project "lens"). -# The images come inside the QPKG (lens-backend, lens-frontend and SurrealDB, tagged with the package version) and +# The images come inside the QPKG (lens-backend and lens-frontend tagged qnap-, and SurrealDB) and # are loaded on the first start, so nothing is pulled or built on the NAS. # Settings and secrets: lens.env in the data folder (LENS_DATA), written on the first start. Everything Lens keeps # lives under LENS_DATA, which outlasts removing the app. x-backend: &backend - image: lens-backend:${LENS_VERSION:?} + image: lens-backend:qnap-${LENS_VERSION:?} environment: + ARCHIVE_CONFIG: /qnap/archive.yaml ACCESS_SECRET_KEY: ${ACCESS_SECRET_KEY:?set ACCESS_SECRET_KEY in lens.env} ARCHIVE_SECRET_KEY: ${ARCHIVE_SECRET_KEY:?set ARCHIVE_SECRET_KEY in lens.env} LENS_SETUP_CODE: ${LENS_SETUP_CODE:-} @@ -22,7 +23,18 @@ x-backend: &backend MAIL_USERNAME: ${MAIL_USERNAME:-} MAIL_PASSWORD: ${MAIL_PASSWORD:-} MAIL_FROM: ${MAIL_FROM:-} + # Optional answers to the first-run setup (empty means the web app asks) + LENS_ADMIN_EMAIL: ${LENS_ADMIN_EMAIL:-} + LENS_ADMIN_PASSWORD: ${LENS_ADMIN_PASSWORD:-} + LENS_ADMIN_NAME: ${LENS_ADMIN_NAME:-} + LENS_NAMESPACE: ${LENS_NAMESPACE:-} + LENS_LLM_BASE_URL: ${LENS_LLM_BASE_URL:-} + LENS_LLM_MODEL: ${LENS_LLM_MODEL:-} + LENS_LLM_API_KEY: ${LENS_LLM_API_KEY:-} + LENS_LLM_VISION_MODEL: ${LENS_LLM_VISION_MODEL:-} + LENS_SETUP_WIZARD: ${LENS_SETUP_WIZARD:-} volumes: + - ./archive.yaml:/qnap/archive.yaml:ro - ${LENS_DATA:?}/archive:/data - ${AUDIO_DIR:?set AUDIO_DIR in lens.env}:/audio:ro depends_on: @@ -56,7 +68,7 @@ services: disable: true frontend: - image: lens-frontend:${LENS_VERSION:?} + image: lens-frontend:qnap-${LENS_VERSION:?} environment: API_BASE_URL: http://backend:8000 AUTH_SECRET: ${AUTH_SECRET:?set AUTH_SECRET in lens.env} diff --git a/packaging/qnap/qpkg/shared/lens.sh b/packaging/qnap/qpkg/shared/lens.sh index 6ae30e1b6..0af459248 100755 --- a/packaging/qnap/qpkg/shared/lens.sh +++ b/packaging/qnap/qpkg/shared/lens.sh @@ -72,7 +72,7 @@ write_env() { for h in localhost 127.0.0.1 "$host" "$(hostname)"; do case ",$hosts," in *",$h,"*) ;; *) hosts="$hosts,$h" ;; esac done - if [ -d /share/Multimedia ]; then audio=/share/Multimedia; else audio="$LENS_DATA/audio"; fi + if [ -d /share/Multimedia ]; then audio=/share/Multimedia/Lens; else audio="$LENS_DATA/media"; fi umask 077 cat > "$LENS_DATA/lens.env" < " per line. Each image is loaded once; its file is then deleted to give -# the space back (an upgrade brings new ones). Images of earlier Lens versions are removed after an upgrade. +# the space back (an upgrade brings new ones). This package's images are tagged qnap-; earlier versions' are +# removed after an upgrade, and other Lens images in Docker (built by hand, say) are left alone. load_images() { [ -f "$IMAGES_DIR/manifest" ] || return 0 while read -r ref file; do @@ -133,7 +147,7 @@ load_images() { rm -f "$IMAGES_DIR/$file" done < "$IMAGES_DIR/manifest" for repo in lens-backend lens-frontend; do - "$DOCKER" image ls --format '{{.Repository}}:{{.Tag}}' "$repo" 2>/dev/null | grep -v ":$LENS_VERSION\$" | while read -r old; do + "$DOCKER" image ls --format '{{.Repository}}:{{.Tag}}' "$repo" 2>/dev/null | grep ":qnap-" | grep -v ":qnap-$LENS_VERSION\$" | while read -r old; do "$DOCKER" image rm "$old" >/dev/null 2>&1 || true done done @@ -190,7 +204,7 @@ case "$1" in if "$DOCKER" info >/dev/null 2>&1; then [ -f "$LENS_DATA/lens.env" ] && compose down --remove-orphans for repo in lens-backend lens-frontend; do - "$DOCKER" image ls --format '{{.Repository}}:{{.Tag}}' "$repo" 2>/dev/null | while read -r img; do + "$DOCKER" image ls --format '{{.Repository}}:{{.Tag}}' "$repo" 2>/dev/null | grep ":qnap-" | while read -r img; do "$DOCKER" image rm "$img" >/dev/null 2>&1 || true done done