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

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 (158) hide show
  1. package/dist/template/.changeset/blog-playground-content.md +4 -0
  2. package/dist/template/.changeset/blog-wordpress-structure.md +6 -0
  3. package/dist/template/.changeset/managed-preview-assistant.md +4 -0
  4. package/dist/template/.changeset/native-linux-install.md +6 -0
  5. package/dist/template/.changeset/public-beta-5.md +4 -0
  6. package/dist/template/.changeset/public-beta-6.md +4 -0
  7. package/dist/template/.github/ISSUE_TEMPLATE/bug_report.yml +1 -1
  8. package/dist/template/.github/workflows/release-tarballs.yml +117 -0
  9. package/dist/template/AGENTS.md +15 -2
  10. package/dist/template/Dockerfile +3 -0
  11. package/dist/template/MASTER.md +114 -11
  12. package/dist/template/README.md +1 -1
  13. package/dist/template/app/(admin)/admin/assistant/page.tsx +9 -1
  14. package/dist/template/app/(admin)/admin/blog/PostSettings.tsx +26 -0
  15. package/dist/template/app/(admin)/admin/blog/[kind]/page.tsx +53 -0
  16. package/dist/template/app/(admin)/admin/blog/actions.ts +186 -6
  17. package/dist/template/app/(admin)/admin/blog/comments/page.tsx +25 -0
  18. package/dist/template/app/(admin)/admin/blog/page.tsx +21 -5
  19. package/dist/template/app/(admin)/admin/imports/[id]/page.tsx +2 -0
  20. package/dist/template/app/(admin)/admin/pages/[id]/page.tsx +3 -0
  21. package/dist/template/app/(admin)/assistant-actions.ts +13 -6
  22. package/dist/template/app/(public)/[[...slug]]/ReaderComments.tsx +25 -0
  23. package/dist/template/app/(public)/[[...slug]]/blog-parts.tsx +153 -0
  24. package/dist/template/app/(public)/[[...slug]]/comment-actions.ts +16 -0
  25. package/dist/template/app/(public)/[[...slug]]/page.tsx +182 -18
  26. package/dist/template/app/api/chat/assistant/call/route.ts +35 -0
  27. package/dist/template/db/migrations/0061_blog_structure.sql +89 -0
  28. package/dist/template/db/migrations/0062_blog_reader_comments.sql +24 -0
  29. package/dist/template/db/migrations/meta/_journal.json +14 -0
  30. package/dist/template/deploy/README.md +26 -9
  31. package/dist/template/deploy/blog-wordpress-2026-11-07.md +146 -0
  32. package/dist/template/deploy/docker-selfhost/.env.example +11 -1
  33. package/dist/template/deploy/docker-selfhost/README.md +79 -50
  34. package/dist/template/deploy/docker-selfhost/infra/backup.sh +81 -0
  35. package/dist/template/deploy/docker-selfhost/infra/compose.https.yml +37 -1
  36. package/dist/template/deploy/docker-selfhost/infra/compose.yml +37 -1
  37. package/dist/template/deploy/docker-selfhost/migrate.md +8 -5
  38. package/dist/template/deploy/docker-selfhost/recipe.yaml +9 -10
  39. package/dist/template/deploy/docker-selfhost/selfhost.sh +206 -0
  40. package/dist/template/deploy/docker-selfhost/verify.md +11 -4
  41. package/dist/template/deploy/f-criteria-matrix.md +89 -0
  42. package/dist/template/deploy/linux/.env.example +28 -0
  43. package/dist/template/deploy/linux/README.md +181 -0
  44. package/dist/template/deploy/linux/freeholder +655 -0
  45. package/dist/template/deploy/linux/install.sh +173 -0
  46. package/dist/template/deploy/linux/migrate.md +17 -0
  47. package/dist/template/deploy/linux/recipe.yaml +50 -0
  48. package/dist/template/deploy/linux/share/Caddyfile.template +19 -0
  49. package/dist/template/deploy/linux/share/systemd/freeholder-backup.service +13 -0
  50. package/dist/template/deploy/linux/share/systemd/freeholder-backup.timer +12 -0
  51. package/dist/template/deploy/linux/share/systemd/freeholder.service +41 -0
  52. package/dist/template/deploy/linux/verify.md +22 -0
  53. package/dist/template/deploy/managed-preview-assistant.md +99 -0
  54. package/dist/template/eslint.config.mjs +3 -1
  55. package/dist/template/gitignore.template +1 -0
  56. package/dist/template/locales/ar.json +85 -6
  57. package/dist/template/locales/en.json +83 -4
  58. package/dist/template/locales/es.json +83 -4
  59. package/dist/template/locales/fr.json +85 -6
  60. package/dist/template/next.config.ts +2 -0
  61. package/dist/template/package.json +3 -2
  62. package/dist/template/packages/cli/package.json +1 -1
  63. package/dist/template/packages/create-freeholder/package.json +1 -1
  64. package/dist/template/packages/freeholder-app/package.json +1 -1
  65. package/dist/template/packages/mobile-app/package.json +1 -1
  66. package/dist/template/packages/plugin-kit/package.json +1 -1
  67. package/dist/template/packages/sdk/package.json +1 -1
  68. package/dist/template/packages/sdk/src/generated.ts +177 -9
  69. package/dist/template/packages/sdk/src/version.ts +1 -1
  70. package/dist/template/packages/templates/package.json +1 -1
  71. package/dist/template/proxy.ts +18 -1
  72. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/NOTICE.txt +117 -0
  73. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/audio-output-processor.js +267 -0
  74. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.js +847 -0
  75. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.wasm +0 -0
  76. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/encoderWorker.min.js +1 -0
  77. package/dist/template/public/managed-assistant/0.1.10/manifest.json +12 -0
  78. package/dist/template/public/managed-assistant/0.1.10/pm-ai-duplex-client.js +1376 -0
  79. package/dist/template/scripts/build-release.d.mts +4 -0
  80. package/dist/template/scripts/build-release.mjs +171 -0
  81. package/dist/template/scripts/launch-prepare.mjs +6 -3
  82. package/dist/template/scripts/license-headers.mjs +3 -0
  83. package/dist/template/scripts/recipe-matrix.sh +22 -7
  84. package/dist/template/scripts/verify-wordpress-migration.d.mts +8 -0
  85. package/dist/template/scripts/verify-wordpress-migration.mjs +105 -0
  86. package/dist/template/security/adversarial-audit-2026-10-08.md +1 -1
  87. package/dist/template/src/adapters/ai/types.ts +5 -0
  88. package/dist/template/src/adapters/paradise/assistant.ts +37 -0
  89. package/dist/template/src/adapters/paradise/http.ts +4 -3
  90. package/dist/template/src/adapters/storage/local-mode.ts +54 -0
  91. package/dist/template/src/adapters/storage/local.ts +53 -26
  92. package/dist/template/src/core/contract/json-schema.ts +8 -0
  93. package/dist/template/src/core/demo/playground-inserts.ts +29 -0
  94. package/dist/template/src/core/demo/playground-policy.ts +9 -0
  95. package/dist/template/src/core/doctor/index.ts +19 -10
  96. package/dist/template/src/core/env.ts +8 -1
  97. package/dist/template/src/core/http/csp.ts +10 -2
  98. package/dist/template/src/core/http/csrf-client.ts +10 -0
  99. package/dist/template/src/core/import/service.ts +217 -12
  100. package/dist/template/src/core/import/wordpress.ts +80 -15
  101. package/dist/template/src/core/notifications/service.ts +1 -0
  102. package/dist/template/src/core/retention/registry.ts +2 -0
  103. package/dist/template/src/core/search/registry.ts +2 -0
  104. package/dist/template/src/core/seo/feeds.ts +2 -0
  105. package/dist/template/src/core/seo/jsonld.ts +46 -2
  106. package/dist/template/src/core/seo/legacy-proxy.ts +53 -0
  107. package/dist/template/src/core/seo/meta.ts +10 -7
  108. package/dist/template/src/core/seo/service.ts +14 -1
  109. package/dist/template/src/core/update/preflight.ts +3 -2
  110. package/dist/template/src/core/update/release-declaration.json +1 -1
  111. package/dist/template/src/core/update/service.ts +7 -17
  112. package/dist/template/src/modules/assistant/contract.ts +1 -1
  113. package/dist/template/src/modules/assistant/limits.ts +3 -0
  114. package/dist/template/src/modules/assistant/preview.ts +124 -0
  115. package/dist/template/src/modules/assistant/provider.ts +7 -0
  116. package/dist/template/src/modules/assistant/service.ts +21 -5
  117. package/dist/template/src/modules/cms/blocks/PreviewAssistantCall.tsx +176 -0
  118. package/dist/template/src/modules/cms/blocks/SiteChatClient.tsx +10 -4
  119. package/dist/template/src/modules/cms/blocks/surfaces.tsx +10 -0
  120. package/dist/template/src/modules/cms/blog-comments-schema.ts +27 -0
  121. package/dist/template/src/modules/cms/blog-comments.ts +111 -0
  122. package/dist/template/src/modules/cms/blog-schema.ts +146 -0
  123. package/dist/template/src/modules/cms/blog-service.ts +999 -0
  124. package/dist/template/src/modules/cms/blog.tsx +245 -25
  125. package/dist/template/src/modules/cms/manifest.ts +7 -1
  126. package/dist/template/src/modules/cms/read.ts +18 -0
  127. package/dist/template/src/modules/cms/service.ts +22 -4
  128. package/dist/template/src/modules/cms/tables.ts +2 -0
  129. package/dist/template/src/modules/seed/launch.ts +31 -3
  130. package/dist/template/tests/browser/blog-structure.spec.ts +69 -0
  131. package/dist/template/tests/core/agent-launch.test.ts +7 -2
  132. package/dist/template/tests/core/analytics-consent.test.ts +1 -1
  133. package/dist/template/tests/core/blog-playground.test.ts +106 -0
  134. package/dist/template/tests/core/blog-structure-comments.test.ts +166 -0
  135. package/dist/template/tests/core/client-readiness-security.test.ts +3 -1
  136. package/dist/template/tests/core/csp.test.ts +1 -1
  137. package/dist/template/tests/core/deploy-recipe.test.ts +54 -4
  138. package/dist/template/tests/core/internal-services.test.ts +4 -0
  139. package/dist/template/tests/core/legacy-redirect-proxy.test.ts +59 -0
  140. package/dist/template/tests/core/linux-install.test.ts +169 -0
  141. package/dist/template/tests/core/local-storage-mode.test.ts +29 -0
  142. package/dist/template/tests/core/locale-routing.test.ts +1 -1
  143. package/dist/template/tests/core/playground-cache.test.ts +1 -1
  144. package/dist/template/tests/core/playground.test.ts +3 -3
  145. package/dist/template/tests/core/preview-assistant-call.test.ts +88 -0
  146. package/dist/template/tests/core/private-preview-webhooks.test.ts +1 -1
  147. package/dist/template/tests/core/private-preview.test.ts +1 -1
  148. package/dist/template/tests/core/proxy-locale.test.ts +1 -1
  149. package/dist/template/tests/core/sdk-schema.test.ts +20 -0
  150. package/dist/template/tests/core/seo.test.ts +1 -1
  151. package/dist/template/tests/core/site-chat-client.test.ts +50 -0
  152. package/dist/template/tests/core/storage.test.ts +38 -2
  153. package/dist/template/tests/core/wordpress-import-flow.test.ts +81 -18
  154. package/dist/template/tests/core/wordpress-import.test.ts +25 -12
  155. package/dist/template/tests/core/wordpress-migration-verification.test.ts +37 -0
  156. package/dist/template/tests/modules/preview-assistant.test.ts +164 -0
  157. package/dist/template-manifest.json +490 -175
  158. package/package.json +1 -1
@@ -0,0 +1,146 @@
1
+ <!--
2
+ Copyright (C) 2026 Tony Aly
3
+ SPDX-License-Identifier: Apache-2.0
4
+ -->
5
+ # Blog structure and WordPress migration qualification
6
+
7
+ Canonical work: MASTER §43 C2.27, C2.28, C2.29 and C3.46. These remain open until
8
+ review, release and deployed acceptance. C3.45 is implemented in a separate
9
+ preview-assistant branch; this change reserves its agreed checklist text only.
10
+
11
+ When replacing a live post, bylines, taxonomy and approved imported comments
12
+ stay staged until publication in the same transaction as the body cutover.
13
+ Rollback restores the prior publication date and working copy as well as post
14
+ metadata; an imported draft must be renamed when it collides with a live page.
15
+ Republishing an edit keeps the first publication date and updates the post’s
16
+ modified date. Registered publication vetoes also hide bylines, comment threads
17
+ and archives. A slug lookup must resolve to the exact selected page ID: a
18
+ public row in another locale cannot authorize a hidden duplicate. Ordinary-page
19
+ replacements remove the old blog marker only at cutover; comments reference
20
+ the underlying page so kind changes hide history without deleting rollback data.
21
+
22
+ The original WXR post permalink stays the CMS page address, including date
23
+ segments. Blog membership is explicit metadata, so the blog listing does not
24
+ require a move under `/blog`. Original imported search titles and descriptions
25
+ carry preservation flags; new composed titles keep the existing suggested
26
+ lengths. Supported Yoast/Rank Math title, description, canonical, noindex,
27
+ nofollow and social overrides carry across; same-source canonical addresses
28
+ are rebased to the new site. Reviewed Freeholder translations supply hreflang;
29
+ an export cannot establish which source translations were actually live.
30
+
31
+ Categories, tags and authors are real records with owner screens and scoped
32
+ services. Hierarchical WordPress category paths and guest author paths are
33
+ retained. Existing matching records are reused; an old archive alias points to
34
+ an existing archive when its path differs. Private author email is absent from
35
+ public bylines and archive responses. Public category navigation includes only
36
+ categories with published posts. Date archive and old `/page/N` links use the
37
+ same published listing and filters.
38
+
39
+ Reader comments use their own table, separate from editorial annotations.
40
+ Reader history and the moderation queue paginate, so older imported comments
41
+ remain reachable. New submissions are plain text and pending, have a honeypot and per-email/post
42
+ rate limit, resolve a contact without marketing consent, and notify the owner
43
+ through ordinary notification preferences. Owner moderation and site/post
44
+ switches control new submissions; approved history remains readable when new
45
+ comments are closed. WXR ordinary comments retain dates, moderation state and
46
+ parentage. Unsupported comment types and comments on ordinary pages remain
47
+ reported as skipped. Contact merge/undo, private export and erasure include the
48
+ comment reference. Rollback removes this import's comments and unused profiles,
49
+ retaining profiles and ancestors used elsewhere.
50
+
51
+ Publication activates query-ID and parented attachment aliases. The proxy asks
52
+ the public redirect service at configured APP_URL without forwarding cookies,
53
+ credentials or request headers, follows stored chains in the service and emits
54
+ a literal 301 before slash normalization. It performs one bounded (1.5 second)
55
+ internal request per public GET/HEAD page; internal routes and assets bypass it.
56
+ A resolver outage preserves content availability, but may degrade historical
57
+ redirects: the verification must fail that path rather than accept it.
58
+
59
+ ## Read-only acceptance report
60
+
61
+ After reconciliation and explicit import publication, export the JSON result of
62
+ `imports.wordpressVerificationPlan` for the run. This scoped query changes no
63
+ site content. Run:
64
+
65
+ ```sh
66
+ node scripts/verify-wordpress-migration.mjs PLAN.json https://destination.example REPORT.json
67
+ ```
68
+
69
+ The operator-owned plan and report stay private. The script fetches source and
70
+ destination without cookies, requires final HTTP 200 after at most one redirect,
71
+ requires literal 301 for aliases, checks canonical/imported search and social
72
+ text, compares rendered source title/description/robots/hreflang and records
73
+ missing source evidence. A report with failures, warnings or unresolved source
74
+ features exits nonzero. This is cutover evidence, not permission to change DNS.
75
+
76
+ ## Remaining cutover decisions and limits
77
+
78
+ - WordPress `/feed` collides with Freeholder's existing member feed. The new blog
79
+ Atom feed is `/feeds/blog.xml`; root `?feed=rss2`, `?feed=atom` and `?feed=rss`
80
+ aliases reach it. The reserved path needs an owner-selected migration plan
81
+ before DNS cutover; it is not silently overwritten.
82
+ - Orphan attachment pages need an owner-selected destination. Parented
83
+ attachment pages and `?attachment_id` links redirect to their parent post.
84
+ - WXR omits rendered hreflang and plugin-generated metadata. A source crawl is
85
+ required for parity acceptance; an inaccessible source remains uncertainty.
86
+ - External Open Graph image URLs remain their original source URL. Confirm
87
+ long-term image availability or replace them with an owned image before
88
+ retiring the original host. Failed media downloads remain visible in the
89
+ original importer report.
90
+ - Source subdirectory roots, plugin-specific archive bases, multilingual-plugin
91
+ URL routing and custom post types require source-crawl comparison. No blanket
92
+ WordPress parity claim is made for data an export does not carry.
93
+ - No production deployment, release, DNS cutover or LinkedIn publication is
94
+ authorized by a local passing test. The LinkedIn draft remains on hold.
95
+
96
+ ## Validation record
97
+
98
+ Disposable PostgreSQL 16 at a private loopback port, containing only fixtures,
99
+ was used for migrations and importer/comment tests. No production database or
100
+ personal browser state was used. Exact final commands and results are recorded
101
+ in the pull request; browser, release and deployed acceptance remain separate.
102
+
103
+ ## Peer-review regressions
104
+
105
+ A two-locale, same-slug fixture returned a vetoed row's approved comment before
106
+ the exact-ID correction. The preserved failing result was a local fixture, not
107
+ a production disclosure. The new regression verifies refused reads/submissions,
108
+ no hidden archive/category, canonical byline identity and one visible listing.
109
+ A second regression replaces a live post with an ordinary WordPress page, then
110
+ rolls back, preserving the same approved comment ID and its privacy boundary.
111
+ Both fixes belong to C2.29/C3.46; deployed acceptance remains pending.
112
+
113
+ The standalone browser run completed owner/public functionality, email/XSS
114
+ privacy checks and eight light/dark Axe scans, then reproduced a redirect500:
115
+ native Response.redirect headers are immutable. The proxy correction creates
116
+ a mutable NextResponse before applying CSP; the full-proxy regression and the
117
+ repeated real-browser literal301 assertion qualify that boundary separately.
118
+
119
+ The next browser run returned the required301 and a valid relative Location;
120
+ the overly strict absolute-header assertion was a harness defect. The harness
121
+ now resolves that header against the trusted test origin before asserting the
122
+ exact destination, retaining the one-hop and origin checks.
123
+
124
+ Full CI found the new comment contact foreign key and public submission were
125
+ unclassified in the existing search, retention and playground completeness
126
+ guards. These were product integration omissions. Comments remain discoverable
127
+ through the scoped moderation queue; page deletion and `cms.readerComments`
128
+ privacy erasure govern their discussion history instead of a notes TTL.
129
+ Playground submissions use a 200-row comment cap and the existing shared
130
+ contact/client limits, with external notification delivery still blocked.
131
+
132
+ The new native playground regression first reproduced two content-service
133
+ refusals, then called the actual create-blog server action using a genuine
134
+ disposable session cookie and reproduced its redirect back with a refusal.
135
+ The form unnecessarily invoked operator-only bootstrap even though playground
136
+ startup already seeds chrome. It now uses that seeded chrome and explicit
137
+ content permissions. Pages/authors/terms have limits; a shared transaction
138
+ insert guard also covers inline tag batches and concurrent last-slot creators.
139
+ The framework request context/redirect is simulated; actor resolution, grants,
140
+ services and PostgreSQL are real. Deployed demo acceptance remains open.
141
+
142
+ Separate source-review limitation (CMS/kernel, C1.38): the page cap remains a
143
+ preflight outside `createPage`'s insertion transaction. These author/term and
144
+ inline-tag tests do not qualify a strict concurrent page cap. Native race
145
+ reproduction, shared page-insertion serialization and deployed acceptance are
146
+ a scoped follow-up; no live page-overflow incident has been demonstrated.
@@ -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.6
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,101 @@
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.6 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
+ # Replace VERSION with a published release, for example 0.2.0-beta.6.
91
+ deploy/docker-selfhost/selfhost.sh update VERSION # back up, switch image, roll back if unhealthy
92
+ deploy/docker-selfhost/selfhost.sh logs
93
+ ```
94
+
95
+ `check` is this recipe's Docker-only health check. `update` backs up first and
96
+ keeps the old image as `PREVIOUS_FREEHOLDER_IMAGE`; if the new image is not
97
+ healthy it switches back (restore the pre-update backup if that release had
98
+ already migrated the database). Update the checkout to the same tag
99
+ (`git fetch --depth 1 origin tag vVERSION && git checkout vVERSION`) so the
100
+ Compose files match the image. Use `migrate.md` for a provider move. Never use
101
+ `.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
@@ -25,7 +25,9 @@ services:
25
25
  depends_on:
26
26
  - app
27
27
  app:
28
- image: ${FREEHOLDER_IMAGE:-ghcr.io/campdenman/freeholder:edge}
28
+ # The release this checkout belongs to (tests/core/linux-install.test.ts
29
+ # keeps it equal to package.json). Update: selfhost.sh update VERSION.
30
+ image: ${FREEHOLDER_IMAGE:-ghcr.io/campdenman/freeholder:0.2.0-beta.6}
29
31
  restart: unless-stopped
30
32
  # Not published to the host: Caddy is the only way in.
31
33
  expose:
@@ -33,9 +35,15 @@ services:
33
35
  env_file: ../.env
34
36
  environment:
35
37
  DATABASE_URL: postgres://freeholder:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@db:5432/freeholder
38
+ # C3.44: used when FREEHOLDER_STORAGE=local (the default from
39
+ # selfhost.sh prepare): media on the `media` volume, kept across image
40
+ # updates and included in the nightly backup.
41
+ LOCAL_STORAGE_ROOT: /var/lib/freeholder/media
36
42
  # Caddy overwrites this header with the connecting address, and the app
37
43
  # port is not published, so rate limits can tell visitors apart (C11.10).
38
44
  TRUSTED_CLIENT_IP_HEADER: x-freeholder-client-ip
45
+ volumes:
46
+ - media:/var/lib/freeholder/media
39
47
  depends_on:
40
48
  db:
41
49
  condition: service_healthy
@@ -64,7 +72,35 @@ services:
64
72
  interval: 5s
65
73
  timeout: 5s
66
74
  retries: 20
75
+ # C3.44: nightly database and media backup into the `backups` volume,
76
+ # inside Compose so no host cron is needed. `selfhost.sh backup` runs one
77
+ # now and `selfhost.sh restore` restores one.
78
+ backup:
79
+ image: postgres:16-alpine
80
+ restart: unless-stopped
81
+ command: ["sh", "/usr/local/bin/freeholder-backup", "schedule"]
82
+ environment:
83
+ PGHOST: db
84
+ PGUSER: freeholder
85
+ PGDATABASE: freeholder
86
+ PGPASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
87
+ BACKUP_HOUR_UTC: ${BACKUP_HOUR_UTC:-3}
88
+ BACKUP_KEEP: ${BACKUP_KEEP:-14}
89
+ volumes:
90
+ - ./backup.sh:/usr/local/bin/freeholder-backup:ro
91
+ # Not /media: Alpine ships one, and its contents would seed the volume.
92
+ - media:/srv/media
93
+ - backups:/backups
94
+ # After app: Docker gives a new named volume the ownership of the first
95
+ # container's mount point, and only the app image's is the app user's.
96
+ depends_on:
97
+ db:
98
+ condition: service_healthy
99
+ app:
100
+ condition: service_started
67
101
  volumes:
68
102
  pgdata:
103
+ media:
104
+ backups:
69
105
  caddy_data:
70
106
  caddy_config:
@@ -2,13 +2,21 @@
2
2
  # SPDX-License-Identifier: Apache-2.0
3
3
  services:
4
4
  app:
5
- image: ${FREEHOLDER_IMAGE:-ghcr.io/campdenman/freeholder:edge}
5
+ # The release this checkout belongs to (tests/core/linux-install.test.ts
6
+ # keeps it equal to package.json). Update: selfhost.sh update VERSION.
7
+ image: ${FREEHOLDER_IMAGE:-ghcr.io/campdenman/freeholder:0.2.0-beta.6}
6
8
  restart: unless-stopped
7
9
  ports:
8
10
  - "3000:3000"
9
11
  env_file: ../.env
10
12
  environment:
11
13
  DATABASE_URL: postgres://freeholder:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@db:5432/freeholder
14
+ # C3.44: used when FREEHOLDER_STORAGE=local (the default from
15
+ # selfhost.sh prepare): media on the `media` volume, kept across image
16
+ # updates and included in the nightly backup.
17
+ LOCAL_STORAGE_ROOT: /var/lib/freeholder/media
18
+ volumes:
19
+ - media:/var/lib/freeholder/media
12
20
  depends_on:
13
21
  db:
14
22
  condition: service_healthy
@@ -37,5 +45,33 @@ services:
37
45
  interval: 5s
38
46
  timeout: 5s
39
47
  retries: 20
48
+ # C3.44: nightly database and media backup into the `backups` volume,
49
+ # inside Compose so no host cron is needed. `selfhost.sh backup` runs one
50
+ # now and `selfhost.sh restore` restores one.
51
+ backup:
52
+ image: postgres:16-alpine
53
+ restart: unless-stopped
54
+ command: ["sh", "/usr/local/bin/freeholder-backup", "schedule"]
55
+ environment:
56
+ PGHOST: db
57
+ PGUSER: freeholder
58
+ PGDATABASE: freeholder
59
+ PGPASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
60
+ BACKUP_HOUR_UTC: ${BACKUP_HOUR_UTC:-3}
61
+ BACKUP_KEEP: ${BACKUP_KEEP:-14}
62
+ volumes:
63
+ - ./backup.sh:/usr/local/bin/freeholder-backup:ro
64
+ # Not /media: Alpine ships one, and its contents would seed the volume.
65
+ - media:/srv/media
66
+ - backups:/backups
67
+ # After app: Docker gives a new named volume the ownership of the first
68
+ # container's mount point, and only the app image's is the app user's.
69
+ depends_on:
70
+ db:
71
+ condition: service_healthy
72
+ app:
73
+ condition: service_started
40
74
  volumes:
41
75
  pgdata:
76
+ media:
77
+ backups:
@@ -2,8 +2,11 @@
2
2
 
3
3
  Target: `docker-selfhost`
4
4
 
5
- Follow the complete [Tier-1 migration runbook](../migration-runbook.md). Restore
6
- with the Compose Postgres service, but copy production media to the configured
7
- private S3-compatible store—local disk and the local-development MinIO profile
8
- are not migration targets. Keep the prior image digest in
9
- `PREVIOUS_FREEHOLDER_IMAGE` until database, media and public URL checks pass.
5
+ Follow the complete [Tier-1 migration runbook](../migration-runbook.md).
6
+ Restore with the Compose Postgres service (`selfhost.sh restore` takes a
7
+ backup directory in the `backups` volume with the same layout as the Linux
8
+ recipe's, so backups move between the two directly). Media goes to the
9
+ `media` volume with its storage keys as paths, or to the configured private
10
+ S3-compatible store; the local-development MinIO profile is not a migration
11
+ target. Keep the prior image in `PREVIOUS_FREEHOLDER_IMAGE` until database,
12
+ media and public URL checks pass.
@@ -7,32 +7,31 @@ maintainers: ["@tonyaly"]
7
7
  freeholder_min_version: "0.0.0"
8
8
  provides:
9
9
  database: compose-postgres
10
- storage: minio-or-s3
10
+ storage: volume-or-s3
11
11
  jobs: web-process
12
- cron: host-cron
12
+ cron: compose-backup-service
13
13
  estimated_monthly_cost_usd: { min: 0, typical: 20 }
14
14
  limits:
15
- - "Production media MUST leave the compose volume for real S3/R2/Spaces"
15
+ - "One server: media on the compose volume cannot be shared by a second app server; use S3 to scale out"
16
+ - "Copy the backups volume off the server; a backup on the same disk does not survive losing it"
16
17
  - "MinIO is the local-dev profile only"
17
18
  artifacts:
18
19
  - deploy/docker-selfhost/infra/compose.yml
19
20
  - deploy/docker-selfhost/infra/compose.https.yml
20
21
  - deploy/docker-selfhost/infra/Caddyfile.https
22
+ - deploy/docker-selfhost/infra/backup.sh
23
+ - deploy/docker-selfhost/selfhost.sh
21
24
  required_environment:
22
25
  - POSTGRES_PASSWORD
23
26
  - BOOTSTRAP_SECRET
24
27
  - SESSION_SECRET
25
28
  - CREDENTIAL_KEY
26
29
  - APP_URL
27
- - S3_BUCKET
28
- - S3_ENDPOINT
29
- - S3_REGION
30
- - S3_ACCESS_KEY_ID
31
- - S3_SECRET_ACCESS_KEY
30
+ - FREEHOLDER_STORAGE
32
31
  operations:
33
32
  install: "docker compose --env-file deploy/docker-selfhost/.env -f deploy/docker-selfhost/infra/compose.yml up -d"
34
33
  install-https: "docker compose --env-file deploy/docker-selfhost/.env -f deploy/docker-selfhost/infra/compose.https.yml up -d"
35
- verify: "pnpm doctor --url $FREEHOLDER_URL --email $FREEHOLDER_EMAIL --password $FREEHOLDER_PASSWORD"
34
+ verify: "deploy/docker-selfhost/selfhost.sh check"
36
35
  backup: "docker compose --env-file deploy/docker-selfhost/.env -f deploy/docker-selfhost/infra/compose.yml exec -T db pg_dump --format=custom --no-owner --no-privileges -U freeholder freeholder > freeholder.dump"
37
36
  restore: "docker compose --env-file deploy/docker-selfhost/.env -f deploy/docker-selfhost/infra/compose.yml exec -T db pg_restore --no-owner --no-privileges -U freeholder -d freeholder < freeholder.dump"
38
37
  migrate-in: "docker compose --env-file deploy/docker-selfhost/.env -f deploy/docker-selfhost/infra/compose.yml exec -T db pg_restore --no-owner --no-privileges -U freeholder -d freeholder < freeholder.dump && pnpm media:transfer -- --manifest ownership-export/media-manifest.json"
@@ -42,4 +41,4 @@ operations:
42
41
  update:
43
42
  strategy: image-swap
44
43
  rollback: compose pull the previous tag
45
- tested_on: "2026-08-25"
44
+ tested_on: "2026-11-06"