create-freeholder 0.2.0-beta.4 → 0.2.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/template/.changeset/native-linux-install.md +6 -0
  2. package/dist/template/.changeset/public-beta-5.md +4 -0
  3. package/dist/template/.github/ISSUE_TEMPLATE/bug_report.yml +1 -1
  4. package/dist/template/.github/workflows/release-tarballs.yml +117 -0
  5. package/dist/template/AGENTS.md +15 -2
  6. package/dist/template/Dockerfile +3 -0
  7. package/dist/template/MASTER.md +34 -4
  8. package/dist/template/README.md +1 -1
  9. package/dist/template/deploy/README.md +26 -9
  10. package/dist/template/deploy/docker-selfhost/.env.example +11 -1
  11. package/dist/template/deploy/docker-selfhost/README.md +78 -50
  12. package/dist/template/deploy/docker-selfhost/infra/backup.sh +81 -0
  13. package/dist/template/deploy/docker-selfhost/infra/compose.https.yml +37 -1
  14. package/dist/template/deploy/docker-selfhost/infra/compose.yml +37 -1
  15. package/dist/template/deploy/docker-selfhost/migrate.md +8 -5
  16. package/dist/template/deploy/docker-selfhost/recipe.yaml +9 -10
  17. package/dist/template/deploy/docker-selfhost/selfhost.sh +206 -0
  18. package/dist/template/deploy/docker-selfhost/verify.md +11 -4
  19. package/dist/template/deploy/f-criteria-matrix.md +15 -0
  20. package/dist/template/deploy/linux/.env.example +28 -0
  21. package/dist/template/deploy/linux/README.md +181 -0
  22. package/dist/template/deploy/linux/freeholder +655 -0
  23. package/dist/template/deploy/linux/install.sh +173 -0
  24. package/dist/template/deploy/linux/migrate.md +17 -0
  25. package/dist/template/deploy/linux/recipe.yaml +50 -0
  26. package/dist/template/deploy/linux/share/Caddyfile.template +19 -0
  27. package/dist/template/deploy/linux/share/systemd/freeholder-backup.service +13 -0
  28. package/dist/template/deploy/linux/share/systemd/freeholder-backup.timer +12 -0
  29. package/dist/template/deploy/linux/share/systemd/freeholder.service +41 -0
  30. package/dist/template/deploy/linux/verify.md +22 -0
  31. package/dist/template/gitignore.template +1 -0
  32. package/dist/template/package.json +3 -2
  33. package/dist/template/packages/cli/package.json +1 -1
  34. package/dist/template/packages/create-freeholder/package.json +1 -1
  35. package/dist/template/packages/freeholder-app/package.json +1 -1
  36. package/dist/template/packages/mobile-app/package.json +1 -1
  37. package/dist/template/packages/plugin-kit/package.json +1 -1
  38. package/dist/template/packages/sdk/package.json +1 -1
  39. package/dist/template/packages/sdk/src/version.ts +1 -1
  40. package/dist/template/packages/templates/package.json +1 -1
  41. package/dist/template/scripts/build-release.d.mts +4 -0
  42. package/dist/template/scripts/build-release.mjs +171 -0
  43. package/dist/template/scripts/launch-prepare.mjs +6 -3
  44. package/dist/template/scripts/recipe-matrix.sh +22 -7
  45. package/dist/template/security/adversarial-audit-2026-10-08.md +1 -1
  46. package/dist/template/src/adapters/storage/local-mode.ts +54 -0
  47. package/dist/template/src/adapters/storage/local.ts +53 -26
  48. package/dist/template/src/core/doctor/index.ts +19 -10
  49. package/dist/template/src/core/env.ts +6 -1
  50. package/dist/template/src/core/update/preflight.ts +3 -2
  51. package/dist/template/src/core/update/release-declaration.json +1 -1
  52. package/dist/template/src/core/update/service.ts +7 -17
  53. package/dist/template/tests/core/agent-launch.test.ts +7 -2
  54. package/dist/template/tests/core/client-readiness-security.test.ts +3 -1
  55. package/dist/template/tests/core/deploy-recipe.test.ts +54 -4
  56. package/dist/template/tests/core/linux-install.test.ts +169 -0
  57. package/dist/template/tests/core/local-storage-mode.test.ts +29 -0
  58. package/dist/template/tests/core/storage.test.ts +38 -2
  59. package/dist/template-manifest.json +168 -63
  60. package/package.json +1 -1
@@ -0,0 +1,6 @@
1
+ ---
2
+ "freeholder": minor
3
+ ---
4
+ Install Freeholder by hand on your own server, without Docker or an AI assistant. Each release now ships a Linux tarball for x86_64 and arm64 that carries its own Node.js runtime, with its SHA-256, and an `install.sh`. On a fresh Ubuntu or Debian server, `sudo sh install.sh` installs PostgreSQL and Caddy, sets up HTTPS (on a temporary `<ip>.sslip.io` address until your domain is ready), generates the secrets, starts the site and prints your claim link. Uploaded media is kept on the server by default and included in a nightly backup of the database and media; S3-compatible storage remains an option. `sudo freeholder status`, `backup`, `restore`, `update` (with automatic rollback) and `domain` run it from then on.
5
+
6
+ The Docker Compose recipe no longer needs Node, pnpm or a storage bucket: `deploy/docker-selfhost/selfhost.sh prepare` writes the settings with openssl, media can stay on a Docker volume, a backup service runs nightly inside Compose, `selfhost.sh check` is a Docker-only health check, and the image defaults to the release you checked out instead of `edge`. A production instance may now keep media on local disk when `LOCAL_STORAGE_ROOT` names a persistent directory.
@@ -0,0 +1,4 @@
1
+ ---
2
+ "freeholder": patch
3
+ ---
4
+ Publish 0.2.0-beta.5, the first beta you can install by hand on your own server without Docker or an AI assistant. The release carries a Linux tarball for x86_64 and arm64 with its own Node.js runtime, its SHA-256, and `install.sh`: on a fresh Ubuntu or Debian server, `sudo sh install.sh` sets up PostgreSQL, HTTPS and nightly backups and prints your claim link. The Docker Compose recipe now defaults to this release's image instead of `edge`. It also carries everything merged since 0.2.0-beta.4. It is still active development, not a release candidate; live provider acceptance and the independent security review remain open.
@@ -31,7 +31,7 @@ body:
31
31
  id: version
32
32
  attributes:
33
33
  label: Freeholder version or commit
34
- placeholder: 0.2.0-beta.4, or a commit SHA
34
+ placeholder: 0.2.0-beta.5, or a commit SHA
35
35
  validations:
36
36
  required: true
37
37
  - type: dropdown
@@ -0,0 +1,117 @@
1
+ # Copyright (C) 2026 Tony Aly
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ # C3.44: the no-Docker Linux release. Builds freeholder-VERSION-linux-{x64,arm64}
4
+ # tarballs (each with its own Node runtime) on native runners, because sharp's
5
+ # binary in the standalone output is the build machine's. Every build is
6
+ # installed with deploy/linux/install.sh on the runner itself, booted against a
7
+ # real PostgreSQL, backed up and restored, before anything is published. A
8
+ # version tag attaches the tarballs, their .sha256 files and install.sh to the
9
+ # GitHub release that publish-image.yml creates.
10
+ name: Release tarballs
11
+
12
+ on:
13
+ push:
14
+ tags: ["v*"]
15
+ pull_request:
16
+ paths:
17
+ - "scripts/build-release.mjs"
18
+ - "deploy/linux/**"
19
+ - "deploy/docker-selfhost/selfhost.sh"
20
+ - "deploy/docker-selfhost/infra/backup.sh"
21
+ - ".github/workflows/release-tarballs.yml"
22
+
23
+ concurrency:
24
+ group: release-tarballs-${{ github.ref }}
25
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
26
+
27
+ permissions:
28
+ contents: read
29
+
30
+ jobs:
31
+ build:
32
+ name: Build and install linux-${{ matrix.arch }}
33
+ strategy:
34
+ fail-fast: false
35
+ matrix:
36
+ include:
37
+ - arch: x64
38
+ runner: ubuntu-24.04
39
+ - arch: arm64
40
+ runner: ubuntu-24.04-arm
41
+ runs-on: ${{ matrix.runner }}
42
+ timeout-minutes: 40
43
+ steps:
44
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
45
+ with:
46
+ persist-credentials: false
47
+ - name: Shellcheck the self-host scripts
48
+ run: shellcheck -s sh -S warning deploy/linux/install.sh deploy/linux/freeholder deploy/docker-selfhost/selfhost.sh deploy/docker-selfhost/infra/backup.sh
49
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
50
+ with:
51
+ node-version-file: .node-version
52
+ - name: Install dependencies
53
+ run: |
54
+ corepack enable
55
+ pnpm install --frozen-lockfile
56
+ - name: Build
57
+ run: pnpm build
58
+ - name: Package
59
+ run: pnpm release:build
60
+ - name: Install the tarball with the documented installer
61
+ run: |
62
+ tarball=$(ls dist/release/freeholder-*-linux-${{ matrix.arch }}.tar.gz)
63
+ # No domain: the runner cannot receive a certificate, so this proves
64
+ # everything up to Caddy's ACME request, which the installer reports
65
+ # as a warning rather than a failure.
66
+ sudo sh dist/release/install.sh --tarball "$tarball" --yes
67
+ - name: Health, backup and restore
68
+ run: |
69
+ curl -fsS http://127.0.0.1:3000/api/health | tee /dev/stderr | grep -q '"ok":true'
70
+ sudo freeholder status || true
71
+ sudo freeholder claim-link > /dev/null
72
+ sudo freeholder backup
73
+ sudo freeholder restore latest
74
+ curl -fsS http://127.0.0.1:3000/api/health | grep -q '"ok":true'
75
+ - name: Service log on failure
76
+ if: failure()
77
+ run: sudo journalctl -u freeholder -n 200 --no-pager | sed -E 's/(SECRET|PASSWORD|KEY)=[^ ]+/\1=[redacted]/g'
78
+ - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
79
+ with:
80
+ name: linux-${{ matrix.arch }}
81
+ path: |
82
+ dist/release/*.tar.gz
83
+ dist/release/*.sha256
84
+ dist/release/install.sh
85
+ if-no-files-found: error
86
+ retention-days: 14
87
+
88
+ attach:
89
+ name: Attach to the GitHub release
90
+ if: github.event_name == 'push'
91
+ needs: build
92
+ runs-on: ubuntu-latest
93
+ timeout-minutes: 45
94
+ permissions:
95
+ contents: write
96
+ id-token: write
97
+ attestations: write
98
+ steps:
99
+ - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
100
+ with:
101
+ path: assets
102
+ merge-multiple: true
103
+ - uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
104
+ with:
105
+ subject-path: assets/*.tar.gz
106
+ - name: Wait for the release, then upload
107
+ env:
108
+ GH_TOKEN: ${{ github.token }}
109
+ GH_REPO: ${{ github.repository }}
110
+ run: |
111
+ # publish-image.yml creates the release after its own checks.
112
+ for attempt in $(seq 1 80); do
113
+ if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then break; fi
114
+ sleep 30
115
+ done
116
+ gh release view "$GITHUB_REF_NAME" >/dev/null
117
+ gh release upload "$GITHUB_REF_NAME" assets/*.tar.gz assets/*.sha256 assets/install.sh --clobber
@@ -14,6 +14,17 @@ step that reveals the owner claim. Use the provider's own tools to provision
14
14
  Postgres and private object storage; do not substitute in-memory or workspace
15
15
  storage. Pick the path for where the owner wants to host:
16
16
 
17
+ - **The owner's own Linux server, no Docker** (any provider; Ubuntu 22.04+ or
18
+ Debian 12+). Give the owner the block under "Install on your own server" in
19
+ `GETTING_STARTED.md`: they download `install.sh` from the release and run
20
+ `sudo sh install.sh --domain THEIR-DOMAIN` (or no `--domain` for a temporary
21
+ `<ip>.sslip.io` address) in their own SSH session, because it prints the
22
+ owner claim link. It needs no Docker, Node or checkout. Afterwards
23
+ `sudo freeholder status` is the health check. Never read or print
24
+ `/etc/freeholder/freeholder.env`. See `deploy/linux/README.md`.
25
+ - **The owner's own server with Docker.** `deploy/docker-selfhost/README.md`:
26
+ `deploy/docker-selfhost/selfhost.sh prepare` needs only Docker and
27
+ openssl, then the owner runs `selfhost.sh claim-link` themselves.
17
28
  - **DigitalOcean, from a terminal agent** (Claude Code, Cursor, Codex). The
18
29
  owner signs in with `doctl auth init` (or sets `DIGITALOCEAN_TOKEN`) in their
19
30
  own shell and has an SSH key on the account. Run
@@ -44,8 +55,10 @@ tooling.
44
55
 
45
56
  ## The owner claims the site, then connects you
46
57
 
47
- The owner personally opens the claim link (`freeholder launch` prints it in
48
- their terminal; `launch:prepare` writes `.freeholder-launch/claim-link.txt`),
58
+ The owner personally opens the claim link (`freeholder launch` and the Linux
59
+ `install.sh` print it in their terminal, `sudo freeholder claim-link` and
60
+ `selfhost.sh claim-link` print it again; `launch:prepare` writes
61
+ `.freeholder-launch/claim-link.txt`),
49
62
  creates their account and passkey, and saves the recovery codes. Agents must
50
63
  not open or retain the claim link, and must not retain the owner's password,
51
64
  passkey or recovery codes.
@@ -43,6 +43,9 @@ COPY --from=build --chown=freeholder:freeholder /app/db ./db
43
43
  # The way back in when nobody can sign in. Needs only node:crypto, which is
44
44
  # why it can live in an image whose node_modules holds four packages.
45
45
  COPY --from=build --chown=freeholder:freeholder /app/scripts/owner-password.mjs ./scripts/owner-password.mjs
46
+ # C3.44: the docker-selfhost media volume mounts here. Docker copies this
47
+ # directory's ownership into a new named volume, so the app can write to it.
48
+ RUN mkdir -p /var/lib/freeholder/media && chown -R freeholder:freeholder /var/lib/freeholder
46
49
  USER freeholder
47
50
  EXPOSE 3000
48
51
  CMD ["node", "server.js"]
@@ -1519,7 +1519,7 @@ freeholder/ # Apache-2.0
1519
1519
  │ ├── adapters/ # vendor isolation layer (see §12)
1520
1520
  │ │ ├── payments/ (stripe/, paypal/, manual/)
1521
1521
  │ │ ├── mail/ (gmail/, outlook/, resend/, smtp/)
1522
- │ │ ├── storage/ (s3/, replit/, local/) # local = dev-only; production mandates managed object storage (§18)
1522
+ │ │ ├── storage/ (s3/, replit/, local/) # local = dev, or a persistent single-server directory (§18, C3.44)
1523
1523
  │ │ ├── calendar/ (none/ — Google/Microsoft live in core/connections)
1524
1524
  │ │ ├── sms/ (twilio/, none/)
1525
1525
  │ │ ├── ai/ (anthropic/, openai/, none/) # BYO key — grounding, drafting
@@ -1965,7 +1965,7 @@ tested_on: "2026-07-01"
1965
1965
 
1966
1966
  **Recipe rules:**
1967
1967
  - A recipe may pin *required* adapter choices only when the platform forces them (e.g., no-persistent-disk targets must use S3 storage). Everything else stays owner-choice.
1968
- - **Storage mandate (all tiers):** production media lives in managed object storage, never on instance disk. On Tier-1 targets this is pinned: **Replit → Replit Object Storage; DigitalOcean (both flavors) → Spaces.** Other recipes must mandate their platform's equivalent (R2, S3, GCS…). The `local/` storage adapter is dev-only and refuses to start with `NODE_ENV=production` unless explicitly overridden with `FREEHOLDER_UNSAFE_LOCAL_STORAGE=1` — a flag named to be embarrassing in a config review. Rationale: media is the least-recoverable asset a business has; a dead droplet or wiped container must never be able to take the photo archive with it. Object storage also makes cross-platform migration a bucket sync instead of a rescue operation.
1968
+ - **Storage mandate (all tiers):** production media lives where a rebuild cannot take it. On platforms without durable disk this is managed object storage, pinned by the recipe: **Replit → Replit Object Storage; DigitalOcean (both flavors) → Spaces;** App Platform, Render and Railway → S3-compatible. A **single-server self-host** (the `linux` recipe and `docker-selfhost`) may keep media on its own disk instead (C3.44, owner decision 2026-11-06, "freeholder is supposed to be a wordpress replacement"): an explicit absolute `LOCAL_STORAGE_ROOT` outside the replaceable release (`/var/lib/freeholder/media`, or the Compose `media` volume), kept across updates, served through the app's access-checked `/media` route and included in the recipe's nightly backup. The `local/` adapter refuses to start with `NODE_ENV=production` unless `LOCAL_STORAGE_ROOT` names such an existing, writable directory, or the legacy `FREEHOLDER_UNSAFE_LOCAL_STORAGE=1` override is set for an implicit one — a flag named to be embarrassing in a config review. Rationale: media is the least-recoverable asset a business has; a wiped container or a replaced release must never be able to take the photo archive with it. The single-server trade-off is stated in each recipe: losing the server loses the media unless its backups were copied off it, and a second app server cannot share the disk, so those recipes document moving media to S3 (a copy with the same keys). Object storage still makes cross-platform migration a bucket sync instead of a rescue operation.
1969
1969
  - **Migration mandate (Tier 1–2):** a recipe is not approved without a specced migration path. Every Tier 1–2 recipe ships `migrate.md` covering, at minimum, migration **to and from each Tier-1 target** (export archive → provision → import → storage sync → DNS repoint), with expected downtime and a verification checklist. Tier-1 pairs are round-trip tested in CI (see §23); Tier-2 paths are verified by the recipe maintainer per release. No approved platform is ever a dead end — that's the ownership promise expressed as a requirement.
1970
1970
  - **Update mandate (Tier 1–2):** a recipe declares an `update` strategy and a rollback for its target, and CI exercises it in the upgrade gate (§39.9). A platform an instance cannot be kept patched on is not an approved platform — the same argument as the migration mandate, applied to time rather than to place.
1971
1971
  - Every recipe must run the same app code. No target-specific forks of application logic — if a target needs a code change, that change goes behind a capability flag in core (e.g., `jobs: in-process | worker`), available to all targets.
@@ -2883,7 +2883,7 @@ outside them is replaceable:
2883
2883
  | **The database** | Pages, block trees, sections, products, settings, theme tokens, media records, every business record | §32 — structure is data. The site's design and content are rows, not code, so swapping the image cannot touch them. |
2884
2884
  | **Plugins** | Owner and third-party code | Installed artifacts with declared compatibility ranges (§24), loaded at boot, never merged into core |
2885
2885
  | **Configuration** | `freeholder.config.ts`, environment | §17 — the instance's choices, checked in or injected, never baked into the image |
2886
- | **Uploads** | Media in object storage | §18's storage mandate — never on instance disk, so the container is disposable by construction |
2886
+ | **Uploads** | Media in object storage, or a single-server self-host's persistent media directory (C3.44) | §18's storage mandate — never inside the release or the container layer, so either is disposable by construction |
2887
2887
 
2888
2888
  **Core is never patched in place.** That is the contract, stated as a rule. If
2889
2889
  an owner needs behaviour core does not have, the answer is a plugin, a
@@ -5173,7 +5173,7 @@ human, collaboratively, without code, lock-in markup or accidental publication.
5173
5173
  acceptance remain open.
5174
5174
  - [x] **C3.20** Add semantic platform/plugin/API versions, compatibility
5175
5175
  reporting and a truthful instance version in health, admin, CLI and contract.
5176
- (Platform and packages are `0.2.0-beta.4`; SDK `PLATFORM_VERSION` is stamped from
5176
+ (Platform and packages are `0.2.0-beta.5`; SDK `PLATFORM_VERSION` is stamped from
5177
5177
  `package.json`. Health, OpenAPI, Doctor, provenance, catalogue compatibility
5178
5178
  and admin chrome report that same string. `.github/workflows/publish-packages.yml`
5179
5179
  publishes packed tarballs on a matching `vX.Y.Z` tag; `scripts/release-packages.mjs`
@@ -5783,6 +5783,36 @@ deployments are portable, testable and incapable of silently forking the truth.
5783
5783
  secret. That covers key distribution for registries and publishers, key
5784
5784
  rotation, and refusal of a plugin whose signature does not verify against a
5785
5785
  trusted key. Release feeds already use Ed25519 (§39.3, C10.03). Open.
5786
+ - [ ] **C3.44** Make the by-hand install WordPress-easy on any host, with no
5787
+ AI and no Docker required (owner decision 2026-11-06: "native first, Docker
5788
+ optional"). A release ships `freeholder-VERSION-linux-{x64,arm64}.tar.gz`
5789
+ with its own Node runtime, a `.sha256` and `install.sh`; on a plain
5790
+ Ubuntu/Debian server `install.sh` installs PostgreSQL and Caddy from
5791
+ distribution or official packages, creates a `freeholder` user, the database
5792
+ and role, unpacks a root-owned release under `/opt/freeholder/releases` with
5793
+ a `current` symlink, generates secrets with openssl, writes systemd units and
5794
+ a nightly backup timer, serves HTTPS (with a temporary `<ip>.sslip.io`
5795
+ address before DNS is ready) and prints the claim link. Media defaults to a
5796
+ persistent local directory (§18 single-server mode) with S3 optional;
5797
+ `freeholder status|backup|restore|update|rollback|domain` operate it, and a
5798
+ failed update rolls back the release and the pre-update database. The Docker
5799
+ recipe gets the same local-volume media, release-tag image default, nightly
5800
+ backup service, openssl-only prepare (`selfhost.sh`) and a Docker-only health
5801
+ check. Open until a release carries the tarballs and the documented steps
5802
+ pass on a fresh server: HTTPS, claim to the owner form, a published page, a
5803
+ backup and a restore.
5804
+ *(Progress 2026-11-06: `src/adapters/storage/local-mode.ts` decides the
5805
+ persistent mode for the adapter, Doctor, update screen and preflight;
5806
+ `scripts/build-release.mjs`, `deploy/linux/` and
5807
+ `.github/workflows/release-tarballs.yml`, which installs every tarball with
5808
+ `install.sh` on x64 and arm64 runners and backs up and restores it;
5809
+ `deploy/docker-selfhost/selfhost.sh` and `infra/backup.sh`. Evidence
5810
+ `tests/core/linux-install.test.ts`, `tests/core/local-storage-mode.test.ts`,
5811
+ `tests/core/storage.test.ts`, `tests/core/deploy-recipe.test.ts`; changeset
5812
+ `native-linux-install.md`. A throwaway DigitalOcean droplet ran the
5813
+ documented native steps with a tarball built from this branch; the result is
5814
+ recorded in the pull request. The tarballs reach a release only when the
5815
+ next version is tagged.)*
5786
5816
 
5787
5817
  ### 43.9 C4 — Safe agent workforce, connections, scheduling, and briefing
5788
5818
 
@@ -10,7 +10,7 @@ replaces the stack with one self-hosted platform where a contact is **one
10
10
  record**: their bookings, orders, quotes, gallery access, messages, and email
11
11
  history all hang off one CRM timeline.
12
12
 
13
- > **Status: 0.2.0-beta.4, in active development; no stable release is published.**
13
+ > **Status: 0.2.0-beta.5, in active development; no stable release is published.**
14
14
  > This is not a release candidate. The implemented platform is undergoing
15
15
  > final release acceptance. Independent
16
16
  > security review, real provider settlement, specification reconciliation and
@@ -12,18 +12,35 @@ in core, never a fork (§18).
12
12
  | [`replit`](replit/) | 1 | Replit Postgres | Replit Object Storage | $25 |
13
13
  | [`railway`](railway/) | 1 | Railway Postgres | S3-compatible | $25 |
14
14
  | [`render`](render/) | 1 | Render Postgres | S3-compatible | $28 |
15
- | [`docker-selfhost`](docker-selfhost/) | 1 | Compose Postgres | S3 / MinIO (dev) | $20 |
15
+ | [`docker-selfhost`](docker-selfhost/) | 1 | Compose Postgres | Docker volume or S3 | $12–24 |
16
+ | [`linux`](linux/) (no Docker) | 2 | Distribution Postgres | Server disk or S3 | $12–24 |
16
17
 
17
- ## The storage mandate
18
+ **By hand, without an AI assistant:** [`linux`](linux/) is the WordPress-style
19
+ path: download `install.sh` from a release, run it on any Ubuntu or Debian
20
+ server, open the claim link it prints. It needs no Docker, Node, pnpm or
21
+ checkout. [`docker-selfhost`](docker-selfhost/) is the same on a host that
22
+ already runs Docker.
18
23
 
19
- Production media lives in managed object storage, never on instance disk
20
- (§18). Media is the least recoverable asset a business has: a dead droplet or a
21
- wiped container must never take the photo archive with it, and object storage
22
- makes moving providers a bucket sync rather than a rescue operation.
24
+ ## The storage mandate
23
25
 
24
- The `local` adapter is development-only and **refuses to start** with
25
- `NODE_ENV=production` unless overridden with `FREEHOLDER_UNSAFE_LOCAL_STORAGE=1`
26
- — a flag named to be embarrassing in a config review.
26
+ Production media must live somewhere a rebuild cannot take it (§18). On
27
+ platforms with no durable disk (App Platform, Render, Railway, Replit) that is
28
+ object storage, and the recipe pins it. Media is the least recoverable asset a
29
+ business has, and object storage makes moving providers a bucket sync rather
30
+ than a rescue operation.
31
+
32
+ A single-server install may instead keep media on its own disk (C3.44): the
33
+ `linux` recipe's `/var/lib/freeholder/media` and the `docker-selfhost` media
34
+ volume. Both are outside the replaceable release, kept across updates and
35
+ included in the nightly backup, which is why they are supported. The trade-off
36
+ is that losing the server loses the media unless its backups were copied off
37
+ it, and a second app server cannot share it. Each recipe's README says how to
38
+ copy backups elsewhere and how to move media to S3 later.
39
+
40
+ The `local` adapter **refuses to start** with `NODE_ENV=production` unless
41
+ `LOCAL_STORAGE_ROOT` names such an absolute, existing directory. The legacy
42
+ `FREEHOLDER_UNSAFE_LOCAL_STORAGE=1` override for an implicit directory remains,
43
+ named to be embarrassing in a config review.
27
44
 
28
45
  ## Adding a recipe
29
46
 
@@ -1,5 +1,8 @@
1
1
  # Copyright (C) 2026 Tony Aly
2
2
  # SPDX-License-Identifier: Apache-2.0
3
+ # `selfhost.sh prepare` writes deploy/docker-selfhost/.env and generates every
4
+ # secret with `openssl rand -hex 32`. This shows what is in it; never use the
5
+ # example as a live file.
3
6
  POSTGRES_PASSWORD=
4
7
  # Independent random secret required for first owner setup (32+ characters).
5
8
  BOOTSTRAP_SECRET=
@@ -9,10 +12,17 @@ APP_URL=http://localhost:3000
9
12
  # For a public site: APP_URL=https://example.com, this hostname, and
10
13
  # infra/compose.https.yml, whose Caddy obtains the certificate.
11
14
  FREEHOLDER_DOMAIN=
12
- FREEHOLDER_STORAGE=s3
15
+ # The release image; `selfhost.sh update VERSION` changes it.
16
+ FREEHOLDER_IMAGE=ghcr.io/campdenman/freeholder:0.2.0-beta.5
17
+ # Media on the Compose `media` volume (default) or S3-compatible storage.
18
+ FREEHOLDER_STORAGE=local
19
+ # For FREEHOLDER_STORAGE=s3:
13
20
  S3_BUCKET=
14
21
  S3_ENDPOINT=
15
22
  S3_ACCESS_KEY_ID=
16
23
  S3_SECRET_ACCESS_KEY=
17
24
  S3_REGION=
18
25
  S3_ADDRESSING_STYLE=path
26
+ # Backups: hour (UTC) and how many to keep.
27
+ BACKUP_HOUR_UTC=3
28
+ BACKUP_KEEP=14
@@ -1,72 +1,100 @@
1
1
  # Docker Compose (Tier 1)
2
2
 
3
- This recipe runs the published image and PostgreSQL 16. Production media must
4
- use a private S3-compatible store; local disk is not a durable Tier-1 target.
3
+ This recipe runs the published release image, PostgreSQL 16 and a nightly
4
+ backup service with Docker Compose. The host needs only Docker (with the
5
+ Compose plugin), `openssl` and `curl`: no Node, pnpm or `pnpm install`.
6
+
7
+ Prefer no Docker at all? [`../linux/README.md`](../linux/README.md) installs
8
+ the same release natively on Ubuntu or Debian.
5
9
 
6
10
  Two Compose files, one project:
7
11
 
12
+ - `infra/compose.https.yml` puts Caddy in front with automatic HTTPS from
13
+ Let's Encrypt, for a public server. Owner passkeys need HTTPS, so a public
14
+ site uses this file. The app port is not published; Caddy is the only way
15
+ in.
8
16
  - `infra/compose.yml` serves plain HTTP on port 3000, for your own machine
9
17
  (`http://localhost:3000`).
10
- - `infra/compose.https.yml` puts Caddy in front with automatic HTTPS from
11
- Let's Encrypt, for a public host. Owner passkeys only work over HTTPS (or on
12
- localhost), so a public site uses this file. The app port is not published;
13
- Caddy is the only way in.
14
18
 
15
- Both files live in `infra/`, so they share one Compose project and database
16
- volume: moving from one to the other keeps your data.
19
+ Both live in `infra/`, so they share one Compose project and its volumes:
20
+ moving from one to the other keeps your data.
17
21
 
18
22
  ## Install
19
23
 
20
- From the repository root, prepare the private configuration:
24
+ On a server with Docker and ports 80 and 443 open:
21
25
 
22
26
  ```sh
23
- pnpm launch:prepare --target docker-selfhost --url https://YOUR-DOMAIN --json
24
- # or, on your own machine: --url http://localhost:3000
27
+ git clone --depth 1 --branch v0.2.0-beta.5 https://github.com/CampDenman/freeholder.git
28
+ cd freeholder
29
+ deploy/docker-selfhost/selfhost.sh prepare # or: prepare --domain example.com
30
+ deploy/docker-selfhost/selfhost.sh start # prints your private claim link
25
31
  ```
26
32
 
27
- This writes `deploy/docker-selfhost/.env` (mode 600), where Compose reads it.
28
- It generates independent `BOOTSTRAP_SECRET`, `SESSION_SECRET`,
29
- `CREDENTIAL_KEY` and `POSTGRES_PASSWORD` values, and sets `FREEHOLDER_DOMAIN`
30
- from an HTTPS URL. It preserves values already there on a rerun, and writes the
31
- owner claim link to `.freeholder-launch/claim-link.txt` (mode 600). It prints
32
- only a redacted report. Exit 2 means something is still missing, usually the
33
- S3 bucket values: add `S3_BUCKET`, `S3_ENDPOINT`, `S3_REGION`,
34
- `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` to that file and rerun.
35
- `DATABASE_URL` is not needed: Compose runs PostgreSQL and builds it from
36
- `POSTGRES_PASSWORD`.
37
-
38
- To fill the file by hand instead, copy `.env.example` to
39
- `deploy/docker-selfhost/.env` and generate each secret with
40
- `node -e "console.log(crypto.randomBytes(32).toString('hex'))"`. Compose
41
- refuses to start while `POSTGRES_PASSWORD` is empty.
42
-
43
- Then start the stack with the report's `startCommand`, which is the
44
- recipe's `install-https` operation for an HTTPS URL and `install` for
45
- localhost:
33
+ `prepare` writes `deploy/docker-selfhost/.env` (mode 600) with
34
+ `POSTGRES_PASSWORD`, `BOOTSTRAP_SECRET`, `SESSION_SECRET` and `CREDENTIAL_KEY`
35
+ from `openssl rand -hex 32`, `APP_URL`, `FREEHOLDER_DOMAIN`, the release image
36
+ (`FREEHOLDER_IMAGE=ghcr.io/campdenman/freeholder:VERSION`, this checkout's
37
+ release, never `edge`) and `FREEHOLDER_STORAGE=local`. Rerunning keeps existing
38
+ values. Without `--domain` it uses a temporary `https://<ip>.sslip.io`
39
+ address, so you can start before DNS is ready; later run
40
+ `prepare --domain example.com` and `start` again. Passkeys belong to the
41
+ address they were made on, so add one again after the move. On your own
42
+ machine use `prepare --localhost`.
43
+
44
+ `start` pulls the image, starts the stack, waits for the site and prints the
45
+ claim link. Open it yourself, create the owner account and save the recovery
46
+ codes. `selfhost.sh claim-link` prints it again.
47
+
48
+ `pnpm launch:prepare --target docker-selfhost --url https://YOUR-DOMAIN` still
49
+ writes the same `.env` from a checkout with Node and pnpm.
50
+
51
+ ## Media: Docker volume or S3
52
+
53
+ By default media lives on the Compose `media` volume, mounted at
54
+ `/var/lib/freeholder/media` and served through the app with the same access
55
+ checks as every other storage (`LOCAL_STORAGE_ROOT`). It survives image
56
+ updates and container rebuilds, and it is in every backup. It does not
57
+ survive losing the server unless the backups were copied off it, and a second
58
+ app server cannot share it.
59
+
60
+ For S3-compatible storage instead, run `prepare --storage s3` and add
61
+ `S3_ENDPOINT`, `S3_REGION`, `S3_BUCKET`, `S3_ACCESS_KEY_ID` and
62
+ `S3_SECRET_ACCESS_KEY` to the `.env`. To move existing media to a bucket, copy
63
+ the volume's files to it with the same paths, then switch.
64
+
65
+ ## Backups and restore
66
+
67
+ The `backup` service backs up every night at 03:15 UTC (`BACKUP_HOUR_UTC`)
68
+ into the `backups` volume: `database.dump` (`pg_dump` custom format),
69
+ `media.tar.gz` and `SHA256SUMS` per backup, newest 14 kept (`BACKUP_KEEP`).
46
70
 
47
71
  ```sh
48
- # Public host: point the domain's A record here and open ports 80 and 443 first.
49
- docker compose --env-file deploy/docker-selfhost/.env -f deploy/docker-selfhost/infra/compose.https.yml up -d
50
- # Your own machine:
51
- docker compose --env-file deploy/docker-selfhost/.env -f deploy/docker-selfhost/infra/compose.yml up -d
72
+ deploy/docker-selfhost/selfhost.sh backup # one now
73
+ deploy/docker-selfhost/selfhost.sh backups # list them
74
+ deploy/docker-selfhost/selfhost.sh restore latest # or a name from the list
52
75
  ```
53
76
 
54
- Always pass `--env-file deploy/docker-selfhost/.env`: the services'
55
- `env_file` does not supply values for `${POSTGRES_PASSWORD}` or
56
- `${FREEHOLDER_DOMAIN}` interpolation. Compose waits for PostgreSQL health and
57
- restarts the services.
58
-
59
- Open the private claim link yourself, create your passkey and save the
60
- recovery codes. Then issue any assistant's key at `/admin/connect`.
77
+ Restore verifies the checksums, takes a safety backup, stops the app, restores
78
+ into a scratch database and swaps it in (the replaced one is kept as
79
+ `freeholder_previous`), restores the media volume and starts the app. Copy
80
+ backups off the server, for example
81
+ `docker run --rm -v infra_backups:/b alpine tar -C /b -c . | ssh other-host 'cat > backups.tar'`
82
+ (the Compose project is named after the `infra` directory; `docker volume ls`
83
+ shows the volumes). Keep a
84
+ copy of `.env` too: `CREDENTIAL_KEY` is not in the backup.
61
85
 
62
86
  ## Operate
63
87
 
64
- - With HTTPS, use `infra/compose.https.yml` in place of `infra/compose.yml`
65
- in every operation below and in `recipe.yaml`.
66
- - Use `verify.md` plus the recipe's `verify` command after each change.
67
- - Use `backup` and `restore` for the database and `pnpm media:transfer` for
68
- object bytes. Rehearse restore into a scratch database.
69
- - Set `FREEHOLDER_IMAGE` to a digest, run `update`, and retain the former digest
70
- as `PREVIOUS_FREEHOLDER_IMAGE` for `rollback`.
71
- - Use `migrate.md` for any provider move. Never use `.env.example` as a live
72
- environment file.
88
+ ```sh
89
+ deploy/docker-selfhost/selfhost.sh check # containers healthy, /api/health over HTTPS, latest backup
90
+ deploy/docker-selfhost/selfhost.sh update 0.2.0-beta.6 # back up, switch image, roll back if unhealthy
91
+ deploy/docker-selfhost/selfhost.sh logs
92
+ ```
93
+
94
+ `check` is this recipe's Docker-only health check. `update` backs up first and
95
+ keeps the old image as `PREVIOUS_FREEHOLDER_IMAGE`; if the new image is not
96
+ healthy it switches back (restore the pre-update backup if that release had
97
+ already migrated the database). Update the checkout to the same tag
98
+ (`git fetch --depth 1 origin tag vVERSION && git checkout vVERSION`) so the
99
+ Compose files match the image. Use `migrate.md` for a provider move. Never use
100
+ `.env.example` as a live environment file.
@@ -0,0 +1,81 @@
1
+ #!/bin/sh
2
+ # shellcheck disable=SC2010 # the listed names are our own timestamps.
3
+ # Copyright (C) 2026 Tony Aly
4
+ # SPDX-License-Identifier: Apache-2.0
5
+ # C3.44: the docker-selfhost backup service (postgres:16-alpine, so pg_dump
6
+ # matches the database). Each backup is /backups/<UTC stamp>/ with
7
+ # database.dump (custom format), media.tar.gz (the media volume) and
8
+ # SHA256SUMS, the same layout as the Linux recipe's `freeholder backup`.
9
+ #
10
+ # schedule run forever, one backup a day at BACKUP_HOUR_UTC:15
11
+ # now one backup
12
+ # restore X restore backup X (the app must be stopped; selfhost.sh does it)
13
+ set -eu
14
+
15
+ keep=${BACKUP_KEEP:-14}
16
+ case "$keep" in ''|*[!0-9]*) echo "backup: BACKUP_KEEP must be a number" >&2; exit 1 ;; esac
17
+
18
+ backup_now() {
19
+ stamp=$(date -u +%Y-%m-%dT%H-%M-%SZ)
20
+ dir="/backups/$stamp"
21
+ rm -rf "$dir.partial"
22
+ mkdir -p "$dir.partial"
23
+ chmod 700 /backups "$dir.partial"
24
+ pg_dump --format=custom --no-owner --no-privileges > "$dir.partial/database.dump"
25
+ size=$(stat -c %s "$dir.partial/database.dump")
26
+ if [ "$size" -lt 1024 ]; then
27
+ rm -rf "$dir.partial"
28
+ echo "backup: the database dump is only $size bytes; refusing to keep a likely-empty backup" >&2
29
+ return 1
30
+ fi
31
+ if [ -n "$(ls -A /srv/media 2>/dev/null)" ]; then
32
+ tar -C /srv -czf "$dir.partial/media.tar.gz" media
33
+ fi
34
+ (cd "$dir.partial" && sha256sum ./* > SHA256SUMS)
35
+ mv "$dir.partial" "$dir"
36
+ echo "backup: $stamp ($(du -sh "$dir" | cut -f1))"
37
+ ls -1 /backups | grep -E '^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9-]+Z$' | sort | head -n "-$keep" | while read -r old; do
38
+ rm -rf "/backups/$old"
39
+ done
40
+ }
41
+
42
+ restore() {
43
+ dir="/backups/$1"
44
+ [ -f "$dir/database.dump" ] || { echo "restore: no backup named $1" >&2; exit 1; }
45
+ (cd "$dir" && sha256sum -c -s SHA256SUMS) || { echo "restore: $1 failed its checksum; nothing was changed" >&2; exit 1; }
46
+ export PGOPTIONS="--client-min-messages=warning"
47
+ dropdb --if-exists freeholder_restore
48
+ createdb freeholder_restore
49
+ if ! pg_restore --no-owner --no-privileges --exit-on-error -d freeholder_restore "$dir/database.dump"; then
50
+ dropdb --if-exists freeholder_restore
51
+ echo "restore: pg_restore failed; the current database was not changed" >&2
52
+ exit 1
53
+ fi
54
+ dropdb --if-exists freeholder_previous
55
+ psql -v ON_ERROR_STOP=1 -qtA -d postgres <<'SQL'
56
+ SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'freeholder' AND pid <> pg_backend_pid();
57
+ ALTER DATABASE freeholder RENAME TO freeholder_previous;
58
+ ALTER DATABASE freeholder_restore RENAME TO freeholder;
59
+ SQL
60
+ # The media volume becomes exactly what the backup held (empty if it held
61
+ # none, as with S3 storage, where the volume is unused).
62
+ find /srv/media -mindepth 1 -delete
63
+ [ ! -f "$dir/media.tar.gz" ] || tar -C /srv -xzf "$dir/media.tar.gz"
64
+ echo "restore: $1 restored; the replaced database is kept as freeholder_previous"
65
+ }
66
+
67
+ case "${1:-}" in
68
+ now) backup_now ;;
69
+ restore) [ $# -eq 2 ] || { echo "usage: restore NAME" >&2; exit 2; }; restore "$2" ;;
70
+ schedule)
71
+ hour=${BACKUP_HOUR_UTC:-3}
72
+ while :; do
73
+ now=$(date -u +%s)
74
+ next=$(date -u -d "@$(( now - now % 86400 + hour * 3600 + 900 ))" +%s)
75
+ [ "$next" -gt "$now" ] || next=$(( next + 86400 ))
76
+ echo "backup: next backup at $(date -u -d "@$next" +%Y-%m-%dT%H:%MZ)"
77
+ sleep $(( next - now ))
78
+ backup_now || echo "backup: failed; will try again tomorrow" >&2
79
+ done ;;
80
+ *) echo "usage: backup.sh schedule|now|restore NAME" >&2; exit 2 ;;
81
+ esac