diff --git a/.env.example b/.env.example index 4ab14fc..289298d 100644 --- a/.env.example +++ b/.env.example @@ -76,6 +76,13 @@ EMAIL_SYNC_ENABLED= QUARTZ_HOST=quartz QUARTZ_PORT=8080 +# SilverBullet, the notes editor at /sb/. Both default in nginx/entrypoint.sh, +# so they can be left blank. +SILVERBULLET_HOST=silverbullet +SILVERBULLET_PORT=3000 +# Seconds between notes commit/push cycles (default 300). +SILVERBULLET_GIT_INTERVAL= + # --- Go backend -------------------------------------------------------------- # BACKEND_HOST is the container name and the nginx upstream. # BACKEND_ENDPOINT is the public URL prefix nginx mounts the API at and then diff --git a/.gitignore b/.gitignore index a7e0cf1..6be0444 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,7 @@ sync-secrets.sh # Local-only outstanding-work notes, deliberately not published TODO-NEXT.md + +# SilverBullet git deploy key (key material only; the README stays) +silverbullet/ssh/* +!silverbullet/ssh/README.md diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index c37262f..1ae1fc7 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -55,6 +55,8 @@ backend icecast2 gitea hasura quartz python | | | db (Postgres 16) | `${POSTGRES_HOST}` | 5432 | none | no | | hasura | `${HASURA_HOST}` | `${HASURA_PORT}` | `/hasura/` (admin-gated) | no | | quartz (notes) | `${QUARTZ_HOST}` | `${QUARTZ_PORT}` | `/notes/` (admin-gated) | no | +| silverbullet | `${SILVERBULLET_HOST}` | `${SILVERBULLET_PORT}` | `/sb/` (admin-gated) | no | +| silverbullet-git | n/a | n/a | none (timer loop) | no | | python (FastAPI) | `${PYTHON_HOST}` | `${PYTHON_PORT}` | `/py/`, docs at `/py/docs` | no | | icecast2 + liquidsoap | `${ICECAST_HOST}` | `${ICECAST_PORT}` | `/radio/` | **harbor port only** | | gitea | `${GITEA_HOST}` | 3000, 2222 | `/gitea/` | **3000, 2222** | @@ -71,11 +73,14 @@ in one step — never change one without the other.** - **Canonical host.** `http://` → `https://`, and apex → `www`. The SPA, the cookies and the CORS rules all assume `www.`. - **Prefix stripping.** `/api`, `/radio`, `/gitea`, `/notes`, `/py` are stripped + — but `/sb/` deliberately is NOT: SilverBullet is told its own base path via + `SB_URL_PREFIX` and builds its service-worker scope from it, so stripping the + prefix serves a blank page with nothing in the log. by a `rewrite ... break` before proxying; each upstream serves from `/`. - **Per-request DNS.** Upstreams go through `set $upstream_* ...` variables with `resolver 127.0.0.11`, so names resolve per request. nginx boots fine with a backend down (502s until it appears) instead of refusing to start. -- **Admin gate.** `/hasura/` and `/notes/` are protected by an `auth_request` +- **Admin gate.** `/hasura/`, `/notes/` and `/sb/` are protected by an `auth_request` subrequest to the backend's `/auth/validate-admin`; a failure redirects to the SPA login. Neither service has any auth of its own at that path. - **Uploads served directly.** `/uploads/` is an alias onto the shared `uploads` @@ -207,7 +212,7 @@ of deleting the directory: | `./gitea/config` | Gitea's live `app.ini` | Gitignored; generated from the template on first boot and then owned by Gitea | | `./logs` | Backend logs | | | `./icecast2/fallback_music` | Radio fallback MP3s | Synced by `sync-secrets.sh`, not git | -| `${OBSIDIAN_DIR}` | The Obsidian vault | Read-write to backend, **read-only** to quartz | +| `${OBSIDIAN_DIR}` | The Obsidian vault (a git clone of the notes repo) | Read-write to backend and silverbullet, **read-only** to quartz | **Ephemeral:** anything else inside a container. Notably the Vue build, the rendered nginx/icecast/quartz configs, and the Gitea runner's downloaded binary diff --git a/README.md b/README.md index 6e69552..efed371 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ db (5432) ── PostgreSQL 16 icecast2 (8000) ── Audio Streaming (Icecast2 + Liquidsoap) gitea (3000) ── Self-Hosted Git quartz (8080) ── Obsidian Notes Publisher (Quartz v4.4.0) +silverbullet (3000) ── Obsidian Notes Editor (SilverBullet 2.11.0) +silverbullet-git ── Commits/pushes notes edits to the notes repo python (8000) ── Python API (FastAPI) hasura (8080) ── Hasura GraphQL Engine (Docker profile: hasura) autoheal ── Auto-restart unhealthy containers @@ -44,7 +46,7 @@ certbot ── SSL Certificate Management (disabled in dev) - Spotify integration (currently playing, recently played) - Steam integration (online status, recent games) -- Obsidian note viewer via Quartz +- Obsidian note viewer via Quartz, editable from any browser via SilverBullet - Live radio streaming via Icecast2 + Liquidsoap - Real-time chat over WebSockets with image/video uploads - Blog with admin panel (CRUD) @@ -56,7 +58,7 @@ certbot ── SSL Certificate Management (disabled in dev) - Job application tracker with status workflow and CSV export (admin-only, `/cv/jobs`) - Database-backed bookmarks grouped by category, managed via GraphQL (admin-only) - Hasura GraphQL console (admin-only) -- Admin-gated routes: `/notes`, `/hasura` require admin JWT via Nginx `auth_request` +- Admin-gated routes: `/notes`, `/sb`, `/hasura` require admin JWT via Nginx `auth_request` - Landing page with animated stamps section - Route transitions (slide/fade) and performance optimizations (gzip, WOFF2 fonts, lazy loading) - Backend healthcheck with autoheal container for automatic recovery @@ -72,6 +74,7 @@ certbot ── SSL Certificate Management (disabled in dev) | `/cv/jobs` | Job application tracker (admin-only, hidden print) | | `/bookmarks` | Bookmarks (database-backed, grouped by category) | | `/notes/:path` | Obsidian note viewer (via Quartz, admin-only) | +| `/sb/` | Obsidian note editor (via SilverBullet, admin-only) | | `/shrines` | Fan shrine index + individual shrines | ## API @@ -182,6 +185,7 @@ Access tokens are valid for 7 days; refresh tokens for 365 days. `ValidateAdmin` | `/gitea` | gitea:3000 | Git service | | `/hasura` | hasura:8080 | GraphQL console + WebSocket (admin-only) | | `/notes` | quartz:8080 | Obsidian notes (admin-only) | +| `/sb` | silverbullet:3000 | Obsidian notes editor (admin-only) | | `/py` | python:8000 | Python API (FastAPI; docs at `/py/docs`) | | `/uploads` | local alias | User-uploaded files | @@ -216,6 +220,9 @@ Create a `.env` file in the project root. All services read from this file. | `WALLABAG_PORT` | Wallabag port (planned) | | `QUARTZ_HOST` | Quartz hostname (use `quartz` for Docker) | | `QUARTZ_PORT` | Quartz port (typically `8080`) | +| `SILVERBULLET_HOST` | SilverBullet hostname (defaults to `silverbullet`) | +| `SILVERBULLET_PORT` | SilverBullet port (defaults to `3000`) | +| `SILVERBULLET_GIT_INTERVAL` | Seconds between notes commit/push cycles (defaults to `300`) | | `GITEA_RUNNER_HOST` | Gitea runner hostname | | `GITEA_RUNNER_NAME` | Gitea runner display name | | `GITEA_RUNNER_REGISTRATION_TOKEN` | Token to register Gitea Actions runner | @@ -267,7 +274,8 @@ Populate `LFS_JWT_SECRET`, `SECRET_KEY`, `INTERNAL_TOKEN`, `JWT_SECRET`, and the ### Obsidian Notes Setup 1. Set `OBSIDIAN_DIR` in `.env` to the absolute path of your Obsidian vault on the host machine -2. The vault is mounted read-only into the Quartz container at `/quartz/content` +2. The vault is mounted read-only into the Quartz container at `/quartz/content`, and + read-write into SilverBullet at `/data`, which serves it as an editor at `/sb/` 3. Quartz builds a static site from the vault on startup and serves it at `/notes/` 4. The backend also mounts the vault at `/backend/notes` (legacy, see deprecated endpoints above) diff --git a/docker-compose.yml b/docker-compose.yml index 2263c21..ba30b21 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -113,6 +113,7 @@ services: - gitea - hasura - quartz + - silverbullet - python networks: - app-network @@ -321,6 +322,73 @@ services: volumes: - ${OBSIDIAN_DIR}:/quartz/content:ro + # Browser-based editor for the SAME vault quartz renders read-only at /notes/. + # Quartz is a static site generator with no write path; this is what makes the + # notes editable from a phone. Proxied at /sb/ behind the same nginx admin gate. + # + # SINGLE-SPACE MODE is auto-detected because the mounted folder is not empty + # (the alternative, multi-space, expects /data to be a SilverBullet-owned + # folder of spaces). In this mode it treats the mount as the space itself and + # writes NO database or metadata files into the vault — the folder stays a + # plain directory of markdown that quartz and Obsidian still understand. + silverbullet: + image: ghcr.io/silverbulletmd/silverbullet:2.11.0 + container_name: "${SILVERBULLET_HOST:-silverbullet}" + restart: always + networks: + - app-network + environment: + SB_PORT: "${SILVERBULLET_PORT:-3000}" + # The app builds its service-worker scope and asset URLs from this, which + # is why nginx must NOT strip the /sb/ prefix. See nginx.conf.template. + SB_URL_PREFIX: /sb + # Mirrors quartz.config.ts.template's ignorePatterns so the editor hides + # what the published site hides. MUST be newline separated: a comma + # separated list is accepted silently and does nothing. + SB_SPACE_IGNORE: | + private + templates + .obsidian + # Pinned rather than inferred from the mount's owner, so the files it + # writes match the vault's ownership on the host. + PUID: "1000" + PGID: "1000" + # Uncomment for a look-but-don't-touch first boot against a real vault: + # SB_READ_ONLY: "true" + volumes: + - ${OBSIDIAN_DIR}:/data + + # SilverBullet has no concept of git, so this commits and pushes what it + # writes, and pulls what Obsidian pushes from elsewhere. + # + # WHY A SEPARATE CONTAINER and not SilverBullet's own shell backend: enabling + # that would give anyone who gets past the nginx admin gate command execution + # inside the container. Since SilverBullet itself runs with no SB_USER, that + # gate is the only thing protecting it, so the blast radius stays here. + silverbullet-git: + image: alpine/git:v2.49.1 + container_name: "${SILVERBULLET_GIT_HOST:-silverbullet-git}" + restart: always + networks: + - app-network + # Same uid SilverBullet writes as, so commits don't leave root-owned objects + # in .git that the host user can no longer clean up. + user: "1000:1000" + environment: + SYNC_INTERVAL: "${SILVERBULLET_GIT_INTERVAL:-300}" + GIT_AUTHOR_NAME: silverbullet + GIT_AUTHOR_EMAIL: "silverbullet@${DOMAIN}" + GIT_COMMITTER_NAME: silverbullet + GIT_COMMITTER_EMAIL: "silverbullet@${DOMAIN}" + # uid 1000 has no home in this image; give git somewhere writable. + HOME: /tmp + GIT_SSH_COMMAND: "ssh -i /ssh/id_ed25519 -o UserKnownHostsFile=/ssh/known_hosts -o IdentitiesOnly=yes" + entrypoint: ["/bin/sh", "/git-sync.sh"] + volumes: + - ${OBSIDIAN_DIR}:/space + - ./silverbullet/git-sync.sh:/git-sync.sh:ro + - ./silverbullet/ssh:/ssh:ro + # FastAPI side-service, proxied at /py/ with the prefix stripped by nginx. # ROOT_PATH=/py tells FastAPI it is mounted under a prefix so the generated # OpenAPI/Swagger URLs (/py/docs) are correct even though the app's own diff --git a/nginx/entrypoint.sh b/nginx/entrypoint.sh index bfcddfd..8e4a1ff 100755 --- a/nginx/entrypoint.sh +++ b/nginx/entrypoint.sh @@ -69,6 +69,7 @@ # GITEA_HOST / GITEA_PORT git server upstream # HASURA_HOST / HASURA_PORT Hasura console upstream # QUARTZ_HOST / QUARTZ_PORT notes site upstream +# SILVERBULLET_HOST / _PORT notes editor upstream (defaulted below) # PYTHON_HOST / PYTHON_PORT FastAPI upstream (defaulted below) # DEV_MODE "true" only via docker-compose.dev.yml # CERT_WATCH_INTERVAL optional, seconds between certificate-watch @@ -86,11 +87,13 @@ set -e # Defaults for optional services so envsubst never leaves an empty upstream export PYTHON_HOST="${PYTHON_HOST:-python}" export PYTHON_PORT="${PYTHON_PORT:-8000}" +export SILVERBULLET_HOST="${SILVERBULLET_HOST:-silverbullet}" +export SILVERBULLET_PORT="${SILVERBULLET_PORT:-3000}" # The envsubst allow-list, defined once and reused by both full-config branches # so the two lists cannot drift apart. It MUST stay single-quoted here and be # passed as "$ENVSUBST_VARS" (one argument) below. -ENVSUBST_VARS='${DOMAIN} ${BACKEND_HOST} ${BACKEND_PORT} ${BACKEND_ENDPOINT} ${ICECAST_HOST} ${ICECAST_PORT} ${GITEA_HOST} ${GITEA_PORT} ${HASURA_HOST} ${HASURA_PORT} ${QUARTZ_HOST} ${QUARTZ_PORT} ${PYTHON_HOST} ${PYTHON_PORT}' +ENVSUBST_VARS='${DOMAIN} ${BACKEND_HOST} ${BACKEND_PORT} ${BACKEND_ENDPOINT} ${ICECAST_HOST} ${ICECAST_PORT} ${GITEA_HOST} ${GITEA_PORT} ${HASURA_HOST} ${HASURA_PORT} ${QUARTZ_HOST} ${QUARTZ_PORT} ${SILVERBULLET_HOST} ${SILVERBULLET_PORT} ${PYTHON_HOST} ${PYTHON_PORT}' # Check if DEV_MODE if [ "$DEV_MODE" = "true" ]; then diff --git a/nginx/nginx.conf.template b/nginx/nginx.conf.template index a7a2425..e17c6c3 100644 --- a/nginx/nginx.conf.template +++ b/nginx/nginx.conf.template @@ -158,6 +158,7 @@ http { set $upstream_gitea http://$GITEA_HOST:$GITEA_PORT; set $upstream_hasura http://$HASURA_HOST:$HASURA_PORT; set $upstream_quartz http://$QUARTZ_HOST:$QUARTZ_PORT; + set $upstream_silverbullet http://$SILVERBULLET_HOST:$SILVERBULLET_PORT; set $upstream_python http://$PYTHON_HOST:$PYTHON_PORT; root /etc/nginx/html; @@ -433,6 +434,29 @@ http { proxy_set_header X-Forwarded-Proto $scheme; } + location /sb { + return 301 /sb/; + } + + # SilverBullet: the editor for the same vault quartz renders at /notes/. + # Deliberately NO prefix-strip rewrite, unlike every other proxied app + # here. SilverBullet is a PWA told its own base path via SB_URL_PREFIX=/sb, + # and its service worker scope and asset URLs are built from that. Strip + # the prefix and the app loads a blank page with no error in the log. + # Upgrade/Connection are for its sync websocket. + location /sb/ { + auth_request /internal/auth/admin-validate; + error_page 401 403 = @auth_denied; + proxy_pass $upstream_silverbullet; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + location /py { return 301 /py/; } diff --git a/nginx/nginx_dev_common.conf.template b/nginx/nginx_dev_common.conf.template index 0e19beb..4db1dcb 100644 --- a/nginx/nginx_dev_common.conf.template +++ b/nginx/nginx_dev_common.conf.template @@ -29,6 +29,7 @@ set $upstream_gitea http://$GITEA_HOST:$GITEA_PORT; set $upstream_hasura http://$HASURA_HOST:$HASURA_PORT; set $upstream_quartz http://$QUARTZ_HOST:$QUARTZ_PORT; + set $upstream_silverbullet http://$SILVERBULLET_HOST:$SILVERBULLET_PORT; set $upstream_python http://$PYTHON_HOST:$PYTHON_PORT; # PRIVATE attachments (admin-only). Attachments on *private* chat @@ -190,6 +191,29 @@ proxy_set_header X-Forwarded-Proto $scheme; } + location /sb { + return 301 /sb/; + } + + # SilverBullet: the editor for the same vault quartz renders at /notes/. + # Deliberately NO prefix-strip rewrite, unlike every other proxied app + # here. SilverBullet is a PWA told its own base path via SB_URL_PREFIX=/sb, + # and its service worker scope and asset URLs are built from that. Strip + # the prefix and the app loads a blank page with no error in the log. + # Upgrade/Connection are for its sync websocket. + location /sb/ { + auth_request /internal/auth/admin-validate; + error_page 401 403 = @auth_denied; + proxy_pass $upstream_silverbullet; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + location /py { return 301 /py/; } diff --git a/silverbullet/git-sync.sh b/silverbullet/git-sync.sh new file mode 100755 index 0000000..5d7c287 --- /dev/null +++ b/silverbullet/git-sync.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# Commits SilverBullet's edits to the notes repo and syncs them with the remote. +# +# SilverBullet writes plain markdown straight into the space folder and has no +# concept of git, so this sidecar is what keeps the notes repo moving. It is +# deliberately a separate container rather than SilverBullet's own shell backend: +# the editor is protected only by the nginx admin gate, and enabling a shell +# backend would hand anyone past that gate command execution inside the container. + +set -u + +SPACE=/space +INTERVAL="${SYNC_INTERVAL:-300}" + +log() { echo "[git-sync] $(date -Iseconds) $*"; } + +git config --global --add safe.directory "$SPACE" + +if [ ! -d "$SPACE/.git" ]; then + log "ERROR: $SPACE is not a git repository." + log "Clone the notes repo to the host path OBSIDIAN_DIR points at, then restart." + # Idle rather than crash-loop, so the logs stay readable. + while true; do sleep 3600; done +fi + +cd "$SPACE" || exit 1 +log "watching $SPACE every ${INTERVAL}s" + +while true; do + git add -A + if ! git diff --cached --quiet; then + if git commit -q -m "notes: $(date -Iseconds)"; then + log "committed local changes" + else + log "WARN: commit failed" + fi + fi + + if git remote get-url origin >/dev/null 2>&1; then + git pull --rebase --autostash -q || log "WARN: pull failed (conflict, auth or network)" + git push -q || log "WARN: push failed (conflict, auth or network)" + fi + + sleep "$INTERVAL" +done diff --git a/silverbullet/ssh/README.md b/silverbullet/ssh/README.md new file mode 100644 index 0000000..9fb08d0 --- /dev/null +++ b/silverbullet/ssh/README.md @@ -0,0 +1,19 @@ +# SilverBullet git credentials + +Drop the deploy key for the notes repo here as `id_ed25519` (plus `known_hosts` +for the Gitea host). The directory is mounted read-only into the `silverbullet-git` +sidecar at `/ssh`, and referenced via `GIT_SSH_COMMAND`. + +Generate and register one with: + + ssh-keygen -t ed25519 -N "" -f silverbullet/ssh/id_ed25519 -C silverbullet + ssh-keyscan -p 2222 > silverbullet/ssh/known_hosts + +Then add the public key as a write-enabled deploy key on the notes repo in Gitea. +Key material is gitignored; only this README is committed. + +The sidecar runs as uid 1000, so the private key must be readable by that uid. + +To use an HTTPS token instead, skip the key and embed the token in the clone's +remote URL on the host — the sidecar just runs `git push` against whatever +`origin` the clone already has. diff --git a/vue/src/views/home/Links.vue b/vue/src/views/home/Links.vue index 2646801..c53fb9c 100644 --- a/vue/src/views/home/Links.vue +++ b/vue/src/views/home/Links.vue @@ -21,6 +21,7 @@ const social_links = [ { name: "Github", link: "https://github.com/SteveThePug" }, { name: "Spotify", link: "https://open.spotify.com/user/stevethepug" }, { name: "Notes", link: "/notes/" }, + { name: "Notes (edit)", link: "/sb/" }, ];