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.
- package/dist/template/.changeset/native-linux-install.md +6 -0
- package/dist/template/.changeset/public-beta-5.md +4 -0
- package/dist/template/.github/ISSUE_TEMPLATE/bug_report.yml +1 -1
- package/dist/template/.github/workflows/release-tarballs.yml +117 -0
- package/dist/template/AGENTS.md +15 -2
- package/dist/template/Dockerfile +3 -0
- package/dist/template/MASTER.md +34 -4
- package/dist/template/README.md +1 -1
- package/dist/template/deploy/README.md +26 -9
- package/dist/template/deploy/docker-selfhost/.env.example +11 -1
- package/dist/template/deploy/docker-selfhost/README.md +78 -50
- package/dist/template/deploy/docker-selfhost/infra/backup.sh +81 -0
- package/dist/template/deploy/docker-selfhost/infra/compose.https.yml +37 -1
- package/dist/template/deploy/docker-selfhost/infra/compose.yml +37 -1
- package/dist/template/deploy/docker-selfhost/migrate.md +8 -5
- package/dist/template/deploy/docker-selfhost/recipe.yaml +9 -10
- package/dist/template/deploy/docker-selfhost/selfhost.sh +206 -0
- package/dist/template/deploy/docker-selfhost/verify.md +11 -4
- package/dist/template/deploy/f-criteria-matrix.md +15 -0
- package/dist/template/deploy/linux/.env.example +28 -0
- package/dist/template/deploy/linux/README.md +181 -0
- package/dist/template/deploy/linux/freeholder +655 -0
- package/dist/template/deploy/linux/install.sh +173 -0
- package/dist/template/deploy/linux/migrate.md +17 -0
- package/dist/template/deploy/linux/recipe.yaml +50 -0
- package/dist/template/deploy/linux/share/Caddyfile.template +19 -0
- package/dist/template/deploy/linux/share/systemd/freeholder-backup.service +13 -0
- package/dist/template/deploy/linux/share/systemd/freeholder-backup.timer +12 -0
- package/dist/template/deploy/linux/share/systemd/freeholder.service +41 -0
- package/dist/template/deploy/linux/verify.md +22 -0
- package/dist/template/gitignore.template +1 -0
- package/dist/template/package.json +3 -2
- package/dist/template/packages/cli/package.json +1 -1
- package/dist/template/packages/create-freeholder/package.json +1 -1
- package/dist/template/packages/freeholder-app/package.json +1 -1
- package/dist/template/packages/mobile-app/package.json +1 -1
- package/dist/template/packages/plugin-kit/package.json +1 -1
- package/dist/template/packages/sdk/package.json +1 -1
- package/dist/template/packages/sdk/src/version.ts +1 -1
- package/dist/template/packages/templates/package.json +1 -1
- package/dist/template/scripts/build-release.d.mts +4 -0
- package/dist/template/scripts/build-release.mjs +171 -0
- package/dist/template/scripts/launch-prepare.mjs +6 -3
- package/dist/template/scripts/recipe-matrix.sh +22 -7
- package/dist/template/security/adversarial-audit-2026-10-08.md +1 -1
- package/dist/template/src/adapters/storage/local-mode.ts +54 -0
- package/dist/template/src/adapters/storage/local.ts +53 -26
- package/dist/template/src/core/doctor/index.ts +19 -10
- package/dist/template/src/core/env.ts +6 -1
- package/dist/template/src/core/update/preflight.ts +3 -2
- package/dist/template/src/core/update/release-declaration.json +1 -1
- package/dist/template/src/core/update/service.ts +7 -17
- package/dist/template/tests/core/agent-launch.test.ts +7 -2
- package/dist/template/tests/core/client-readiness-security.test.ts +3 -1
- package/dist/template/tests/core/deploy-recipe.test.ts +54 -4
- package/dist/template/tests/core/linux-install.test.ts +169 -0
- package/dist/template/tests/core/local-storage-mode.test.ts +29 -0
- package/dist/template/tests/core/storage.test.ts +38 -2
- package/dist/template-manifest.json +168 -63
- package/package.json +1 -1
|
@@ -55,7 +55,10 @@ export async function prepareLaunch({ directory = process.cwd(), target = "repli
|
|
|
55
55
|
const inferred = target === "replit" && environment.REPLIT_DOMAINS ? `https://${environment.REPLIT_DOMAINS.split(",")[0]}` : undefined;
|
|
56
56
|
const siteOrigin = publicOrigin(url ?? values.APP_URL ?? inferred ?? "http://localhost:3000");
|
|
57
57
|
values.APP_URL = siteOrigin;
|
|
58
|
-
|
|
58
|
+
// C3.44: Docker keeps media on the recipe's volume unless the owner chose
|
|
59
|
+
// S3 (FREEHOLDER_STORAGE=s3 or an S3 bucket supplied).
|
|
60
|
+
const s3Chosen = values.FREEHOLDER_STORAGE === "s3" || Boolean(values.S3_BUCKET);
|
|
61
|
+
values.FREEHOLDER_STORAGE = target === "replit" ? "replit" : s3Chosen ? "s3" : "local";
|
|
59
62
|
values.FREEHOLDER_SEED_DEMO ??= "0";
|
|
60
63
|
const publicHttps = new URL(siteOrigin).protocol === "https:";
|
|
61
64
|
// The HTTPS Compose file's Caddy requests a certificate for this name.
|
|
@@ -73,7 +76,7 @@ export async function prepareLaunch({ directory = process.cwd(), target = "repli
|
|
|
73
76
|
const claimPath = join(privateDirectory, "claim-link.txt"); await regularFile(claimPath);
|
|
74
77
|
await writeFile(claimPath, `${siteOrigin}/setup#claim=${encodeURIComponent(values.BOOTSTRAP_SECRET)}\n`, { mode: 0o600 }); await chmod(claimPath, 0o600);
|
|
75
78
|
// Compose runs PostgreSQL and builds DATABASE_URL from POSTGRES_PASSWORD itself.
|
|
76
|
-
const required = target === "replit" ? ["DATABASE_URL", "REPLIT_BUCKET_ID"] : ["S3_ENDPOINT", "S3_REGION", "S3_BUCKET", "S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY"];
|
|
79
|
+
const required = target === "replit" ? ["DATABASE_URL", "REPLIT_BUCKET_ID"] : values.FREEHOLDER_STORAGE === "s3" ? ["S3_ENDPOINT", "S3_REGION", "S3_BUCKET", "S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY"] : [];
|
|
77
80
|
const composeFile = `deploy/docker-selfhost/infra/${publicHttps ? "compose.https.yml" : "compose.yml"}`;
|
|
78
81
|
const startCommand = recipeStat ? `docker compose --env-file deploy/docker-selfhost/.env -f ${composeFile} up -d` : undefined;
|
|
79
82
|
const missing = required.filter(name => !values[name]);
|
|
@@ -83,7 +86,7 @@ export async function prepareLaunch({ directory = process.cwd(), target = "repli
|
|
|
83
86
|
...(docker && startCommand ? { composeFile, startCommand } : {}),
|
|
84
87
|
setupUrl: `${siteOrigin}/setup`, mcpUrl: `${siteOrigin}/api/mcp`,
|
|
85
88
|
next: target === "replit" ? ["Provision Replit PostgreSQL and Object Storage using Replit Agent.", "Import the private .env into Replit Secrets; preserve these same secrets in the Deployment.", "Set APP_URL to the published HTTPS URL and rerun preparation with --url.", "Run pnpm start:replit for development; publish using the checked-in Deployment configuration.", "Open the private claim link yourself, create a passkey, and connect your assistant in /admin/connect."] : [
|
|
86
|
-
"
|
|
89
|
+
values.FREEHOLDER_STORAGE === "s3" ? "Put the S3 bucket values in the private .env. Compose runs PostgreSQL itself." : "Media stays on the recipe's Docker volume and is in the nightly backup; for S3 instead, set FREEHOLDER_STORAGE=s3 and the S3_* values and rerun. Compose runs PostgreSQL itself.",
|
|
87
90
|
publicHttps ? `Point ${new URL(siteOrigin).hostname}'s DNS A record at this server and open ports 80 and 443; Caddy obtains the certificate itself.` : "This serves plain HTTP for local use. For a public site, rerun with --url https://YOUR-DOMAIN to use the HTTPS Compose file; passkeys need HTTPS.",
|
|
88
91
|
startCommand ? `Start it from the repository root: ${startCommand}` : "Start it with deploy/docker-selfhost/README.md.",
|
|
89
92
|
"Open the private claim link yourself, create a passkey, and issue your assistant's key in /admin/connect.",
|
|
@@ -26,6 +26,27 @@ for target in "${TARGETS[@]}"; do
|
|
|
26
26
|
psql -h "$PGHOST" -U "$PGUSER" -d postgres -c "drop database if exists ${database}" >/dev/null
|
|
27
27
|
psql -h "$PGHOST" -U "$PGUSER" -d postgres -c "create database ${database}" >/dev/null
|
|
28
28
|
|
|
29
|
+
# C3.44: docker-selfhost's default keeps media on a named volume at
|
|
30
|
+
# /var/lib/freeholder/media, so boot that target the way its Compose file
|
|
31
|
+
# does. Doctor's storage round trip then proves the image's volume mount
|
|
32
|
+
# point is writable and the production local-disk mode starts.
|
|
33
|
+
storage=(
|
|
34
|
+
-e FREEHOLDER_STORAGE=s3
|
|
35
|
+
-e S3_ENDPOINT=http://127.0.0.1:9000
|
|
36
|
+
-e S3_REGION=us-east-1
|
|
37
|
+
-e S3_BUCKET=freeholder-recipe-gate
|
|
38
|
+
-e S3_ACCESS_KEY_ID=freeholder-ci
|
|
39
|
+
-e S3_SECRET_ACCESS_KEY=freeholder-ci-secret
|
|
40
|
+
-e S3_ADDRESSING_STYLE=path
|
|
41
|
+
)
|
|
42
|
+
if [ "$target" = "docker-selfhost" ]; then
|
|
43
|
+
docker volume rm -f freeholder-recipe-gate-media >/dev/null 2>&1 || true
|
|
44
|
+
storage=(
|
|
45
|
+
-e FREEHOLDER_STORAGE=local
|
|
46
|
+
-e LOCAL_STORAGE_ROOT=/var/lib/freeholder/media
|
|
47
|
+
-v freeholder-recipe-gate-media:/var/lib/freeholder/media
|
|
48
|
+
)
|
|
49
|
+
fi
|
|
29
50
|
docker run -d --name freeholder-recipe-gate --network host \
|
|
30
51
|
-e PORT="$PORT" \
|
|
31
52
|
-e NODE_ENV=production \
|
|
@@ -35,13 +56,7 @@ for target in "${TARGETS[@]}"; do
|
|
|
35
56
|
-e CREDENTIAL_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= \
|
|
36
57
|
-e DATABASE_URL="postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:5432/${database}" \
|
|
37
58
|
-e FREEHOLDER_SEED_DEMO=1 \
|
|
38
|
-
|
|
39
|
-
-e S3_ENDPOINT=http://127.0.0.1:9000 \
|
|
40
|
-
-e S3_REGION=us-east-1 \
|
|
41
|
-
-e S3_BUCKET=freeholder-recipe-gate \
|
|
42
|
-
-e S3_ACCESS_KEY_ID=freeholder-ci \
|
|
43
|
-
-e S3_SECRET_ACCESS_KEY=freeholder-ci-secret \
|
|
44
|
-
-e S3_ADDRESSING_STYLE=path \
|
|
59
|
+
"${storage[@]}" \
|
|
45
60
|
-e FREEHOLDER_RECIPE_TARGET="$target" \
|
|
46
61
|
"$IMAGE" >/dev/null
|
|
47
62
|
|
|
@@ -5,7 +5,7 @@ independent security sign-off. Three adversarial agents reviewed separate
|
|
|
5
5
|
customer, security and platform worktrees based on main
|
|
6
6
|
`4ba5daac5eeea6a2202b1b3972defed13cb325a1`; the integrating agent reviewed
|
|
7
7
|
public CMS delivery and editor concurrency. C11.10 remains unchecked, and
|
|
8
|
-
Freeholder remains `0.2.0-beta.
|
|
8
|
+
Freeholder remains `0.2.0-beta.5` in active development.
|
|
9
9
|
|
|
10
10
|
## Findings and repairs
|
|
11
11
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// C3.44: when local-disk media is allowed, decided in one place. The storage
|
|
4
|
+
// adapter, Doctor, the update screen and update preflight all ask this module,
|
|
5
|
+
// so they cannot disagree about whether an instance's uploads are safe.
|
|
6
|
+
//
|
|
7
|
+
// The mistake §18 guards against is media written to somewhere that a rebuild
|
|
8
|
+
// throws away: a container's writable layer, or a relative directory inside
|
|
9
|
+
// the release that an update replaces. A single-server install that names an
|
|
10
|
+
// absolute directory it keeps across updates and includes in its nightly
|
|
11
|
+
// backup (the native installer's /var/lib/freeholder/media, or the Docker
|
|
12
|
+
// recipe's named volume) is not that mistake, so it is a supported mode.
|
|
13
|
+
|
|
14
|
+
import { isAbsolute } from "node:path";
|
|
15
|
+
|
|
16
|
+
export type LocalStorageMode =
|
|
17
|
+
/** Not production: local disk is the development default. */
|
|
18
|
+
| "development"
|
|
19
|
+
/** Production with an explicit absolute directory the operator keeps. */
|
|
20
|
+
| "persistent"
|
|
21
|
+
/** Production on an implicit directory, accepted only by the legacy override. */
|
|
22
|
+
| "unsafe"
|
|
23
|
+
/** Production on an implicit directory, refused. */
|
|
24
|
+
| "refused";
|
|
25
|
+
|
|
26
|
+
export interface LocalStorageEnvironment {
|
|
27
|
+
NODE_ENV: string;
|
|
28
|
+
LOCAL_STORAGE_ROOT?: string;
|
|
29
|
+
FREEHOLDER_UNSAFE_LOCAL_STORAGE?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function localStorageMode(e: LocalStorageEnvironment): LocalStorageMode {
|
|
33
|
+
if (e.NODE_ENV !== "production") return "development";
|
|
34
|
+
// The legacy override keeps its exact meaning, including creating the
|
|
35
|
+
// directory on demand: the hourly playground runs on a tmpfs /tmp/media
|
|
36
|
+
// that is deliberately disposable.
|
|
37
|
+
if (e.FREEHOLDER_UNSAFE_LOCAL_STORAGE === "1") return "unsafe";
|
|
38
|
+
if (e.LOCAL_STORAGE_ROOT && isAbsolute(e.LOCAL_STORAGE_ROOT)) return "persistent";
|
|
39
|
+
return "refused";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** One sentence for Doctor and the update screen. */
|
|
43
|
+
export function describeLocalStorage(e: LocalStorageEnvironment): string {
|
|
44
|
+
switch (localStorageMode(e)) {
|
|
45
|
+
case "development":
|
|
46
|
+
return "Local disk storage is for development.";
|
|
47
|
+
case "persistent":
|
|
48
|
+
return `Uploads are on this server's disk in ${e.LOCAL_STORAGE_ROOT}, which updates keep. Include it in backups (the self-host backup does).`;
|
|
49
|
+
case "unsafe":
|
|
50
|
+
return "Uploads are on this machine's disk because FREEHOLDER_UNSAFE_LOCAL_STORAGE=1.";
|
|
51
|
+
case "refused":
|
|
52
|
+
return "Uploads are configured for local disk in production without a persistent LOCAL_STORAGE_ROOT, so a rebuild or update would lose them.";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
// Copyright (C) 2026 Tony Aly
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// Filesystem storage.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// Filesystem storage. The development default, and (C3.44) a supported
|
|
4
|
+
// production mode for a single-server install that keeps its media directory
|
|
5
|
+
// across updates and backs it up: the native Linux installer's
|
|
6
|
+
// /var/lib/freeholder/media, or the Docker recipe's named volume. What §18
|
|
7
|
+
// still refuses is the implicit relative directory, which lives inside the
|
|
8
|
+
// release or the container layer and is thrown away by a rebuild.
|
|
6
9
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
import { createReadStream } from "node:fs";
|
|
10
|
+
// One app process only: two processes on two machines cannot share it. Move
|
|
11
|
+
// to S3-compatible storage before scaling out (deploy/linux/README.md).
|
|
12
|
+
import { accessSync, constants, createReadStream, statSync } from "node:fs";
|
|
11
13
|
import { mkdir, open, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
12
14
|
import { dirname, join, resolve, sep } from "node:path";
|
|
13
15
|
import type { StorageAdapter, StoredObject } from "@/adapters/storage/types";
|
|
14
16
|
import { env } from "@/core/env";
|
|
17
|
+
import { localStorageMode } from "@/adapters/storage/local-mode";
|
|
15
18
|
|
|
16
19
|
export interface LocalConfig {
|
|
17
20
|
/** Directory to write under. Created on demand. */
|
|
@@ -22,21 +25,41 @@ export interface LocalConfig {
|
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* §18's storage mandate, enforced rather than documented: media is the least
|
|
25
|
-
* recoverable asset a business has
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
+
* recoverable asset a business has. A production instance may keep it on
|
|
29
|
+
* local disk only in a directory it names explicitly (an absolute
|
|
30
|
+
* LOCAL_STORAGE_ROOT), which the self-host recipes keep across updates and
|
|
31
|
+
* include in the nightly backup. That directory must already exist: creating
|
|
32
|
+
* it on demand would quietly write to the container layer when a volume was
|
|
33
|
+
* forgotten.
|
|
28
34
|
*
|
|
29
|
-
* The override
|
|
30
|
-
*
|
|
31
|
-
* a config review, which is the point.
|
|
35
|
+
* The legacy override remains for an implicit directory, and it is still
|
|
36
|
+
* named to be embarrassing in a config review.
|
|
32
37
|
*/
|
|
33
|
-
function refuseInProduction(): void {
|
|
38
|
+
function refuseInProduction(root: string): void {
|
|
34
39
|
// Through env() like everything else: a guard that decides for itself what
|
|
35
40
|
// production means can disagree with the platform that configured it, and
|
|
36
41
|
// the disagreement is only discovered by losing an owner's media.
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
if (
|
|
42
|
+
const current = env();
|
|
43
|
+
const mode = localStorageMode(current);
|
|
44
|
+
if (mode === "development") return;
|
|
45
|
+
if (mode === "persistent") {
|
|
46
|
+
let directory = false;
|
|
47
|
+
try {
|
|
48
|
+
directory = statSync(/* turbopackIgnore: true */ root).isDirectory();
|
|
49
|
+
accessSync(/* turbopackIgnore: true */ root, constants.W_OK);
|
|
50
|
+
} catch {
|
|
51
|
+
directory = false;
|
|
52
|
+
}
|
|
53
|
+
if (!directory) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`LOCAL_STORAGE_ROOT (${root}) must be an existing directory this ` +
|
|
56
|
+
"process can write. Create it on persistent disk (the self-host " +
|
|
57
|
+
"installers do), or mount the recipe's media volume there.",
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (mode === "unsafe") {
|
|
40
63
|
console.warn(
|
|
41
64
|
"[storage] Using local disk in production because " +
|
|
42
65
|
"FREEHOLDER_UNSAFE_LOCAL_STORAGE=1. Uploaded media will be lost if " +
|
|
@@ -45,20 +68,22 @@ function refuseInProduction(): void {
|
|
|
45
68
|
return;
|
|
46
69
|
}
|
|
47
70
|
throw new Error(
|
|
48
|
-
"Storage is set to \"local\"
|
|
49
|
-
"
|
|
50
|
-
"(MASTER.md §18).\n" +
|
|
51
|
-
"Set
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
71
|
+
"Storage is set to \"local\" without a persistent directory. In " +
|
|
72
|
+
"production, local disk is for development only unless it is a " +
|
|
73
|
+
"directory you keep and back up (MASTER.md §18).\n" +
|
|
74
|
+
"Set LOCAL_STORAGE_ROOT to an absolute path on persistent disk (the " +
|
|
75
|
+
"self-host installers use /var/lib/freeholder/media), or set " +
|
|
76
|
+
"adapters.storage to \"s3\" in freeholder.config.ts and configure S3_* " +
|
|
77
|
+
"in the environment: DigitalOcean Spaces, Cloudflare R2, MinIO and AWS " +
|
|
78
|
+
"all work.\n" +
|
|
79
|
+
"To keep media in an implicit directory anyway, set " +
|
|
55
80
|
"FREEHOLDER_UNSAFE_LOCAL_STORAGE=1.",
|
|
56
81
|
);
|
|
57
82
|
}
|
|
58
83
|
|
|
59
84
|
export function createLocalStorage(config: LocalConfig): StorageAdapter {
|
|
60
|
-
refuseInProduction();
|
|
61
85
|
const root = resolve(config.root);
|
|
86
|
+
refuseInProduction(root);
|
|
62
87
|
|
|
63
88
|
/**
|
|
64
89
|
* A key is attacker-influenced (it derives from an uploaded filename), so
|
|
@@ -78,7 +103,9 @@ export function createLocalStorage(config: LocalConfig): StorageAdapter {
|
|
|
78
103
|
|
|
79
104
|
return {
|
|
80
105
|
id: "local",
|
|
81
|
-
|
|
106
|
+
// Objects are served by the app's /media route, which re-checks the
|
|
107
|
+
// object inventory on every request; nothing reaches them directly.
|
|
108
|
+
isPublic: false,
|
|
82
109
|
|
|
83
110
|
async put(key, body, contentType): Promise<StoredObject> {
|
|
84
111
|
const target = pathFor(key);
|
|
@@ -637,7 +637,16 @@ async function checkSecurity(): Promise<Check[]> {
|
|
|
637
637
|
const e = env();
|
|
638
638
|
const checks: Check[] = [];
|
|
639
639
|
|
|
640
|
-
|
|
640
|
+
const { localStorageMode, describeLocalStorage } = await import("@/adapters/storage/local-mode");
|
|
641
|
+
const configuredStorage =
|
|
642
|
+
e.FREEHOLDER_STORAGE ?? (await import("../../../freeholder.config")).default.adapters.storage;
|
|
643
|
+
if (configuredStorage === "local" && localStorageMode(e) === "persistent") {
|
|
644
|
+
// C3.44: a supported single-server mode, so it is information, not a
|
|
645
|
+
// warning. The owner still needs to know the backup must include it.
|
|
646
|
+
checks.push(
|
|
647
|
+
ok("security.localStorage", "Media on this server", describeLocalStorage(e)),
|
|
648
|
+
);
|
|
649
|
+
} else if (e.NODE_ENV === "production" && e.FREEHOLDER_UNSAFE_LOCAL_STORAGE === "1") {
|
|
641
650
|
checks.push(
|
|
642
651
|
warn(
|
|
643
652
|
"security.localStorage",
|
|
@@ -1081,22 +1090,24 @@ async function checkUpdateSeams(): Promise<Check[]> {
|
|
|
1081
1090
|
),
|
|
1082
1091
|
);
|
|
1083
1092
|
const storage = e.FREEHOLDER_STORAGE ?? instanceConfig.adapters.storage;
|
|
1084
|
-
|
|
1093
|
+
const { localStorageMode, describeLocalStorage } = await import("@/adapters/storage/local-mode");
|
|
1094
|
+
const mode = storage === "local" ? localStorageMode(e) : undefined;
|
|
1095
|
+
if (mode === "refused") {
|
|
1085
1096
|
checks.push(
|
|
1086
1097
|
fail(
|
|
1087
1098
|
"update.seams.uploads",
|
|
1088
1099
|
"Uploads seam",
|
|
1089
|
-
|
|
1090
|
-
"Set
|
|
1100
|
+
describeLocalStorage(e),
|
|
1101
|
+
"Set LOCAL_STORAGE_ROOT to a persistent absolute directory, or set adapters.storage to s3 or replit.",
|
|
1091
1102
|
),
|
|
1092
1103
|
);
|
|
1093
|
-
} else if (
|
|
1104
|
+
} else if (mode === "unsafe") {
|
|
1094
1105
|
checks.push(
|
|
1095
1106
|
warn(
|
|
1096
1107
|
"update.seams.uploads",
|
|
1097
1108
|
"Uploads seam",
|
|
1098
|
-
|
|
1099
|
-
"
|
|
1109
|
+
describeLocalStorage(e),
|
|
1110
|
+
"Set LOCAL_STORAGE_ROOT to a directory updates keep, or move media to object storage.",
|
|
1100
1111
|
),
|
|
1101
1112
|
);
|
|
1102
1113
|
} else {
|
|
@@ -1104,9 +1115,7 @@ async function checkUpdateSeams(): Promise<Check[]> {
|
|
|
1104
1115
|
ok(
|
|
1105
1116
|
"update.seams.uploads",
|
|
1106
1117
|
"Uploads seam",
|
|
1107
|
-
storage
|
|
1108
|
-
? "Local disk storage is for development. Production must use object storage."
|
|
1109
|
-
: `Uploads use ${storage} object storage, not instance disk.`,
|
|
1118
|
+
mode ? describeLocalStorage(e) : `Uploads use ${storage} object storage, not instance disk.`,
|
|
1110
1119
|
),
|
|
1111
1120
|
);
|
|
1112
1121
|
}
|
|
@@ -277,7 +277,12 @@ const envSchema = z.object({
|
|
|
277
277
|
/** Replit Object Storage (§20). Discovered from the environment on Replit. */
|
|
278
278
|
REPLIT_BUCKET_ID: z.string().optional(),
|
|
279
279
|
|
|
280
|
-
/**
|
|
280
|
+
/**
|
|
281
|
+
* Where `local` storage writes. Defaults to `.data/media` for development.
|
|
282
|
+
* In production it must be an absolute directory kept across updates and
|
|
283
|
+
* included in backups (C3.44): `/var/lib/freeholder/media` on the native
|
|
284
|
+
* Linux install, the media volume in Docker. See local-mode.ts.
|
|
285
|
+
*/
|
|
281
286
|
LOCAL_STORAGE_ROOT: z.string().optional(),
|
|
282
287
|
|
|
283
288
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright (C) 2026 Tony Aly
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// Update preflight (MASTER.md §39.4, C10.05). Honest about what it cannot know.
|
|
4
|
+
import { describeLocalStorage, localStorageMode } from "@/adapters/storage/local-mode";
|
|
4
5
|
import { randomUUID } from "node:crypto";
|
|
5
6
|
import { statfs } from "node:fs/promises";
|
|
6
7
|
import { sql } from "drizzle-orm";
|
|
@@ -114,8 +115,8 @@ export async function environmentPreflight(): Promise<PreflightStep[]> {
|
|
|
114
115
|
|
|
115
116
|
const e = env();
|
|
116
117
|
const storage = e.FREEHOLDER_STORAGE ?? instanceConfig.adapters.storage;
|
|
117
|
-
if (storage === "local" && e
|
|
118
|
-
steps.push(step("adapters", "fail",
|
|
118
|
+
if (storage === "local" && localStorageMode(e) === "refused") {
|
|
119
|
+
steps.push(step("adapters", "fail", describeLocalStorage(e)));
|
|
119
120
|
} else {
|
|
120
121
|
steps.push(step("adapters", "ok", `Storage adapter is ${storage}.`));
|
|
121
122
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright (C) 2026 Tony Aly
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// Customization seams (C10.01), channels (C10.02), signed feed (C10.03), daily check (C10.04), preflight (C10.05), apply (C10.06).
|
|
4
|
+
import { describeLocalStorage, localStorageMode, type LocalStorageEnvironment } from "@/adapters/storage/local-mode";
|
|
4
5
|
import { z } from "zod";
|
|
5
6
|
import { desc, eq, inArray, sql } from "drizzle-orm";
|
|
6
7
|
import { access } from "node:fs/promises";
|
|
@@ -91,7 +92,7 @@ export const inspectSeams = defineService({
|
|
|
91
92
|
() => false,
|
|
92
93
|
);
|
|
93
94
|
const storage = e.FREEHOLDER_STORAGE ?? instanceConfig.adapters.storage;
|
|
94
|
-
const uploads = uploadsStatus(storage, e
|
|
95
|
+
const uploads = uploadsStatus(storage, e);
|
|
95
96
|
const core = await inspectCoreFiles({
|
|
96
97
|
root,
|
|
97
98
|
expectedDigest: e.FREEHOLDER_CORE_DIGEST ?? null,
|
|
@@ -191,8 +192,7 @@ export const describeRelease = defineService({
|
|
|
191
192
|
|
|
192
193
|
function uploadsStatus(
|
|
193
194
|
storage: string,
|
|
194
|
-
|
|
195
|
-
unsafeLocal: boolean,
|
|
195
|
+
e: LocalStorageEnvironment,
|
|
196
196
|
): { status: "ok" | "warn" | "fail"; detail: string } {
|
|
197
197
|
if (storage !== "local") {
|
|
198
198
|
return {
|
|
@@ -200,21 +200,11 @@ function uploadsStatus(
|
|
|
200
200
|
detail: `Uploads use ${storage} object storage, not instance disk.`,
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
status: "ok",
|
|
206
|
-
detail: "Local disk storage is for development. Production must use object storage.",
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
if (unsafeLocal) {
|
|
210
|
-
return {
|
|
211
|
-
status: "warn",
|
|
212
|
-
detail: "Uploads are on this machine's disk because FREEHOLDER_UNSAFE_LOCAL_STORAGE=1.",
|
|
213
|
-
};
|
|
214
|
-
}
|
|
203
|
+
// C3.44: one rule for adapter, Doctor, preflight and this screen.
|
|
204
|
+
const mode = localStorageMode(e);
|
|
215
205
|
return {
|
|
216
|
-
status: "fail",
|
|
217
|
-
detail:
|
|
206
|
+
status: mode === "refused" ? "fail" : mode === "unsafe" ? "warn" : "ok",
|
|
207
|
+
detail: describeLocalStorage(e),
|
|
218
208
|
};
|
|
219
209
|
}
|
|
220
210
|
|
|
@@ -66,18 +66,23 @@ describe("Docker Compose launch preparation", () => {
|
|
|
66
66
|
const secrets = ["BOOTSTRAP_SECRET", "SESSION_SECRET", "CREDENTIAL_KEY", "POSTGRES_PASSWORD"];
|
|
67
67
|
for (const name of secrets) { expect(values[name]).toMatch(/^[a-f0-9]{64}$/); expect(JSON.stringify(result)).not.toContain(values[name]); }
|
|
68
68
|
expect(new Set(secrets.map((name) => values[name])).size).toBe(4);
|
|
69
|
-
|
|
69
|
+
// C3.44: media defaults to the recipe's volume, so nothing is missing.
|
|
70
|
+
expect(values).toMatchObject({ APP_URL: "https://shop.example.com", FREEHOLDER_DOMAIN: "shop.example.com", FREEHOLDER_STORAGE: "local" });
|
|
70
71
|
expect(values.DATABASE_URL).toBeUndefined();
|
|
71
|
-
expect(result.missing).toEqual([
|
|
72
|
+
expect(result.missing).toEqual([]);
|
|
73
|
+
expect(result.configurationReady).toBe(true);
|
|
72
74
|
expect(result.composeFile).toBe("deploy/docker-selfhost/infra/compose.https.yml");
|
|
73
75
|
expect(result.startCommand).toBe("docker compose --env-file deploy/docker-selfhost/.env -f deploy/docker-selfhost/infra/compose.https.yml up -d");
|
|
74
76
|
expect((await stat(result.privateEnvironmentFile)).mode & 0o777).toBe(0o600);
|
|
75
77
|
expect(result.privateClaimLinkFile).toBe(join(dir, ".freeholder-launch", "claim-link.txt"));
|
|
76
78
|
expect((await readFile(result.privateClaimLinkFile, "utf8")).trim()).toBe(`https://shop.example.com/setup#claim=${values.BOOTSTRAP_SECRET}`);
|
|
77
79
|
|
|
80
|
+
const s3 = await prepareLaunch({ directory: dir, target: "docker-selfhost", url: "https://shop.example.com", environment: { FREEHOLDER_STORAGE: "s3" } });
|
|
81
|
+
expect(s3.missing).toEqual(["S3_ENDPOINT", "S3_REGION", "S3_BUCKET", "S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY"]);
|
|
78
82
|
const ready = await prepareLaunch({ directory: dir, target: "docker-selfhost", url: "https://shop.example.com", environment: { S3_ENDPOINT: "https://s3.example.test", S3_REGION: "r", S3_BUCKET: "b", S3_ACCESS_KEY_ID: "a", S3_SECRET_ACCESS_KEY: "s" } });
|
|
79
83
|
expect(ready.configurationReady).toBe(true);
|
|
80
84
|
const again = parseEnv(await readFile(ready.privateEnvironmentFile, "utf8"));
|
|
85
|
+
expect(again.FREEHOLDER_STORAGE).toBe("s3");
|
|
81
86
|
for (const name of secrets) expect(again[name]).toBe(values[name]);
|
|
82
87
|
});
|
|
83
88
|
|
|
@@ -127,7 +127,9 @@ it('concurrent loyalty redemptions cannot spend the same points twice', async ()
|
|
|
127
127
|
|
|
128
128
|
it('self-host compose honors the image pin used by rollback', () => {
|
|
129
129
|
const compose = parse(readFileSync('deploy/docker-selfhost/infra/compose.yml', 'utf8')) as { services: { app: { image: string } } };
|
|
130
|
-
|
|
130
|
+
// C3.44: the default is the checkout's release, never `edge`.
|
|
131
|
+
const { version } = JSON.parse(readFileSync('package.json', 'utf8')) as { version: string };
|
|
132
|
+
expect(compose.services.app.image).toBe(`\${FREEHOLDER_IMAGE:-ghcr.io/campdenman/freeholder:${version}}`);
|
|
131
133
|
});
|
|
132
134
|
|
|
133
135
|
it('cannot claim a fingerprint is a recoverable snapshot', async () => {
|
|
@@ -66,12 +66,16 @@ describe("the compose stack does not contradict the storage mandate", () => {
|
|
|
66
66
|
compose = undefined;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
it.runIf(compose !== undefined)(`${recipe}:
|
|
70
|
-
// §18: media
|
|
71
|
-
//
|
|
72
|
-
//
|
|
69
|
+
it.runIf(compose !== undefined)(`${recipe}: media is never inside the replaceable app`, () => {
|
|
70
|
+
// §18: media must not live where a rebuild throws it away. A mount
|
|
71
|
+
// under /app would mix uploads into the release; the only supported
|
|
72
|
+
// local-disk location is the docker-selfhost volume at
|
|
73
|
+
// /var/lib/freeholder/media (C3.44), declared with LOCAL_STORAGE_ROOT.
|
|
73
74
|
expect(compose!).not.toMatch(/media.*:\s*\/app\/(public\/)?media/i);
|
|
74
75
|
expect(compose!).not.toMatch(/uploads:/i);
|
|
76
|
+
if (recipe !== "docker-selfhost") {
|
|
77
|
+
expect(compose!).not.toMatch(/LOCAL_STORAGE_ROOT|\/var\/lib\/freeholder\/media/);
|
|
78
|
+
}
|
|
75
79
|
});
|
|
76
80
|
|
|
77
81
|
it.runIf(compose !== undefined)(
|
|
@@ -210,6 +214,52 @@ describe("a trusted client address only where a proxy overwrites it (C11.10)", (
|
|
|
210
214
|
});
|
|
211
215
|
});
|
|
212
216
|
|
|
217
|
+
describe("docker-selfhost keeps media on a volume that is backed up (C3.44)", () => {
|
|
218
|
+
type Service = { image?: string; volumes?: string[]; environment?: Record<string, string>; command?: string[] };
|
|
219
|
+
for (const file of ["compose.yml", "compose.https.yml"]) {
|
|
220
|
+
it(`${file}: app media volume, LOCAL_STORAGE_ROOT and a backup service that reads it`, () => {
|
|
221
|
+
const compose = parse(readFileSync(join(DEPLOY, "docker-selfhost/infra", file), "utf8")) as { services: Record<string, Service>; volumes: Record<string, unknown> };
|
|
222
|
+
const { app, backup } = compose.services;
|
|
223
|
+
expect(app!.volumes).toContain("media:/var/lib/freeholder/media");
|
|
224
|
+
expect(app!.environment!.LOCAL_STORAGE_ROOT).toBe("/var/lib/freeholder/media");
|
|
225
|
+
// FREEHOLDER_STORAGE comes from .env: an `environment:` value would
|
|
226
|
+
// override the owner's choice of S3.
|
|
227
|
+
expect(app!.environment!.FREEHOLDER_STORAGE).toBeUndefined();
|
|
228
|
+
expect(backup!.image).toBe("postgres:16-alpine");
|
|
229
|
+
expect(backup!.volumes).toEqual(expect.arrayContaining(["./backup.sh:/usr/local/bin/freeholder-backup:ro", "media:/srv/media", "backups:/backups"]));
|
|
230
|
+
expect(backup!.command).toEqual(["sh", "/usr/local/bin/freeholder-backup", "schedule"]);
|
|
231
|
+
expect(Object.keys(compose.volumes)).toEqual(expect.arrayContaining(["pgdata", "media", "backups"]));
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
it("the image creates the mount point owned by the app user, so a new volume is writable", () => {
|
|
236
|
+
const dockerfile = readFileSync("Dockerfile", "utf8");
|
|
237
|
+
const runtime = dockerfile.slice(dockerfile.lastIndexOf("AS runtime"));
|
|
238
|
+
expect(runtime).toMatch(/mkdir -p \/var\/lib\/freeholder\/media && chown -R freeholder:freeholder \/var\/lib\/freeholder/);
|
|
239
|
+
expect(runtime.indexOf("/var/lib/freeholder/media")).toBeLessThan(runtime.indexOf("USER freeholder"));
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("the backup is a custom-format dump plus media with checksums, restored into a scratch database", () => {
|
|
243
|
+
const script = readFileSync(join(DEPLOY, "docker-selfhost/infra/backup.sh"), "utf8");
|
|
244
|
+
expect(script).toContain("pg_dump --format=custom --no-owner --no-privileges");
|
|
245
|
+
expect(script).toContain("media.tar.gz");
|
|
246
|
+
expect(script).toContain("sha256sum ./* > SHA256SUMS");
|
|
247
|
+
expect(script).toMatch(/pg_restore [^\n]*-d freeholder_restore/);
|
|
248
|
+
expect(script).not.toMatch(/^\s*[^#\r\n]*--clean/m);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("prepare needs only openssl, and pins the release image rather than edge", () => {
|
|
252
|
+
const selfhost = readFileSync(join(DEPLOY, "docker-selfhost/selfhost.sh"), "utf8");
|
|
253
|
+
expect(selfhost).toContain("openssl rand -hex 32");
|
|
254
|
+
const commands = selfhost.split("\n").filter((line) => !line.trim().startsWith("#"));
|
|
255
|
+
expect(commands.filter((line) => /\b(pnpm|npm|npx|node)\s/.test(line))).toEqual([]);
|
|
256
|
+
expect(selfhost).toContain('FREEHOLDER_IMAGE "ghcr.io/campdenman/freeholder:$(release_version)"');
|
|
257
|
+
for (const file of ["compose.yml", "compose.https.yml"]) {
|
|
258
|
+
expect(readFileSync(join(DEPLOY, "docker-selfhost/infra", file), "utf8")).not.toContain(":edge}");
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
213
263
|
describe("the droplet backup is a verifiable restore artifact", () => {
|
|
214
264
|
const backup = readFileSync(
|
|
215
265
|
join(DEPLOY, "digitalocean-droplet", "infra", "backup.sh"),
|