@johnhenry/sitefile 0.0.6 → 0.0.8
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/CHANGELOG.md +98 -1
- package/README.md +5 -0
- package/lib/src/attest.d.ts +12 -3
- package/lib/src/attest.js +15 -10
- package/lib/src/bake.js +2 -1
- package/lib/src/base-image.d.ts +2 -0
- package/lib/src/base-image.js +8 -0
- package/lib/src/cli/build-image.js +4 -2
- package/lib/src/cli/images.js +8 -5
- package/lib/src/cli/servers.js +59 -21
- package/lib/src/cli/watch.d.ts +2 -0
- package/lib/src/cli/watch.js +2 -1
- package/lib/src/cli.js +6 -3
- package/lib/src/dictionary.d.ts +1 -7
- package/lib/src/dictionary.js +1 -35
- package/lib/src/executor.d.ts +16 -5
- package/lib/src/executor.js +127 -58
- package/lib/src/index.d.ts +2 -0
- package/lib/src/index.js +2 -0
- package/lib/src/mime-type.d.ts +6 -0
- package/lib/src/mime-type.js +20 -0
- package/lib/src/nfc.d.ts +6 -0
- package/lib/src/nfc.js +10 -0
- package/lib/src/oci.d.ts +65 -1
- package/lib/src/oci.js +104 -10
- package/lib/src/paths.d.ts +2 -6
- package/lib/src/paths.js +2 -8
- package/lib/src/plugins/env.d.ts +20 -0
- package/lib/src/plugins/env.js +37 -0
- package/lib/src/plugins/exec.d.ts +1 -1
- package/lib/src/plugins/exec.js +3 -2
- package/lib/src/plugins/host.js +3 -2
- package/lib/src/precompress.d.ts +6 -0
- package/lib/src/precompress.js +6 -0
- package/lib/src/recipe.d.ts +37 -0
- package/lib/src/recipe.js +96 -0
- package/lib/src/registry-ops.d.ts +5 -1
- package/lib/src/registry-ops.js +69 -45
- package/lib/src/request-path.d.ts +10 -0
- package/lib/src/request-path.js +42 -0
- package/lib/src/serve-dictionary.d.ts +11 -0
- package/lib/src/serve-dictionary.js +45 -0
- package/lib/src/serve-rules.js +1 -1
- package/lib/src/server.d.ts +16 -229
- package/lib/src/server.js +135 -795
- package/lib/src/servers.d.ts +15 -0
- package/lib/src/servers.js +42 -2
- package/lib/src/site-core.d.ts +368 -0
- package/lib/src/site-core.js +1065 -0
- package/lib/src/site-handler.d.ts +14 -0
- package/lib/src/site-handler.js +32 -0
- package/lib/src/store.d.ts +31 -2
- package/lib/src/store.js +140 -21
- package/lib/src/wbn.d.ts +1 -6
- package/lib/src/wbn.js +2 -18
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,103 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.0.8 (2026-12-01)
|
|
4
|
+
|
|
5
|
+
- Fix: on Windows, a plugin or tool that starts Node exited with code 134 (`Assertion failed: ncrypto::CSPRNG(nullptr, 0)`) on Node 26.14.0, because the scrubbed environment had no `SystemRoot`. On Windows only, the environment of a JavaScript plugin's Node process (and its `--version` check) and of a `TOOL` now also holds `SystemRoot`, copied from the build's environment (nothing is added if it has none); on other platforms the environment is unchanged, and no other variable is passed on. Both implementations (`src/plugins/env.ts`, `rust/src/plugins/env.rs`), with unit tests that run the Windows case on any system (johnhenry/sitefile#350).
|
|
6
|
+
|
|
7
|
+
- **`IMPORT … AS sitefile` and the language server use the recipe name list** (johnhenry/sitefile#334): a
|
|
8
|
+
Sitefile imported from a local directory, a Git repository or a directory nested in either is the first
|
|
9
|
+
existing name of the configured list (`SITEFILE_RECIPE_NAMES`, `BuildOptions.recipeNames` / `recipe_names`,
|
|
10
|
+
`setRecipeNames` / `set_recipe_names`) instead of a literal `Sitefile`, in build, `vendor`, `outdated`,
|
|
11
|
+
`why` and `inspect`; messages and origins of the imported recipe use the name read. The error for a
|
|
12
|
+
directory with none of them names every file tried; with the default list it is unchanged. The language
|
|
13
|
+
server's go to definition on `name+stage` uses the list too. The TypeScript side of the list was already
|
|
14
|
+
in place (PR #333); there is nothing left under Known differences. Both implementations, with conformance
|
|
15
|
+
cases `recipe-names-import`, `recipe-names-import-inspect`, `err-recipe-names-import-missing` and
|
|
16
|
+
`net-recipe-names-import-git`.
|
|
17
|
+
|
|
18
|
+
- Fix: `serve -d` reported a worker that failed at once (for example `port N on 127.0.0.1 is already in use`) as `the server process exited before it was ready`, losing the reason. The worker writes its `error` to its record and then exits; the starter read the record first and asked whether the process had exited second, so it could see the old record and the exit. It now asks about the exit first and reads the record after, in both implementations (`awaitReady` in `src/servers.ts`, `await_ready` in `rust/src/servers.rs`). Regression tests model the interleaving exactly (#331, PR #348).
|
|
19
|
+
|
|
20
|
+
- Design note, no code: docs/design/attachments.md decides serve-time attachments against the gateway pattern (johnhenry/sitefile#341) and sketches the ABI, limits, ordering with `_redirects`, `_headers` and the 404 page, and how an image suggests attachments.
|
|
21
|
+
|
|
22
|
+
- **`createSiteHandler`: what `serve` answers, as a `(Request) => Response`** (johnhenry/sitefile#339, PR #347): the rules that
|
|
23
|
+
decide what a path answers (clean URLs, `404.html`, `_redirects`, `_headers`, ETags and `304`, byte ranges,
|
|
24
|
+
precompressed sidecars, `.dcz` deltas, `--compress`, `--spa`, `--base`, `--rewrite-base`, host profiles, CORS,
|
|
25
|
+
`--isolate`, cache previews, proxy rules) moved out of the Node listener into `src/site-core.ts` (with `src/site-handler.ts` as its public face), which import no
|
|
26
|
+
`node:` module and do not use `Buffer`. `createSiteHandler(tree, options)` is exported from the package and from
|
|
27
|
+
`@johnhenry/sitefile/site-handler`; `createSiteResponder` is the same on request parts, which `serve` uses. The tree
|
|
28
|
+
is any `SiteTree` (`get`, `isFile`, `isDirectory`, `entries`); a large file and a byte range are a stream of views of
|
|
29
|
+
the tree's bytes. `src/server.ts` keeps what needs a socket or Node: listener, `Host` allow-list, IP rules, basic
|
|
30
|
+
auth, connection limits, throttling, early hints, the access log and the live-reload endpoints. Proxying goes through
|
|
31
|
+
a `fetch` the host supplies (the server's enforces the fetch policy). Rust: `server::handle_site_request` /
|
|
32
|
+
`respond_site` are the same function with no I/O (`handle_request` and `respond` add `check_request`: Host and auth),
|
|
33
|
+
and `Response::body` is a `Body` whose whole files and ranges are windows onto the tree's bytes, not copies. Output
|
|
34
|
+
over a port does not change by one byte (the serve tests and conformance are unchanged); the conformance runner now
|
|
35
|
+
also answers every serve case's requests with the handler alone (`serve --respond-stdin`, a hidden flag) and requires
|
|
36
|
+
the same bytes, in both implementations. The handler is a library entry point, so it does not rely on the CLI having
|
|
37
|
+
checked anything: `base` and `rewriteBase` are normalized by the handler and it throws at construction for a value it
|
|
38
|
+
cannot normalize (never "serve everything at `/`"); a proxy target must be https and public by its literal host
|
|
39
|
+
(`proxy.allow` widens that) before the injected `fetch` is called, which gets `redirect: 'manual'` and no cookie,
|
|
40
|
+
authorization or host, and a failed or refused proxy request is a `502` whose body never says why; the `Host` header is
|
|
41
|
+
used, and checked, only with `allowedHosts` (otherwise the origin written by `--rewrite-base` is the request URL's).
|
|
42
|
+
`@johnhenry/sitefile/site-handler` exports `createSiteHandler`, `createSiteResponder` and their types, and nothing else.
|
|
43
|
+
`serve --respond-stdin` is refused with `-d`, `--watch`, `-p`, TLS and auth flags; `--throttle` streams a large file in
|
|
44
|
+
slices instead of reading it whole. Over a port the bytes are unchanged. docs/CLI.md, "The site handler".
|
|
45
|
+
|
|
46
|
+
- **Multi-platform images** (johnhenry/sitefile#342): `--platform` takes a list (`--platform linux/amd64,linux/arm64`).
|
|
47
|
+
With two or more platforms the build writes one OCI image index over one manifest per platform. The site layer is one
|
|
48
|
+
blob shared by every manifest; with `BASE` each platform's manifest uses that platform's base layers (the base is
|
|
49
|
+
resolved per platform; `Sitefile.lock` records its tag once). The index lists the platforms sorted by `os/arch`, so the
|
|
50
|
+
order given never changes the image, and both implementations write the same index bytes. The image ID is the index
|
|
51
|
+
digest; `-t`, `images` (one row, a `PLATFORMS` column that appears only when such an image is stored),
|
|
52
|
+
`image inspect`, `save --format oci` / `build -o x.oci.tar` (the index, every manifest, the layers once), `serve`,
|
|
53
|
+
`rmi`, `image prune` and the cache size limit treat it as one image, `push` sends the index (each manifest by digest,
|
|
54
|
+
shared and base layers once or mounted), and `--provenance` / `--sbom` attest the index (the provenance and the SBOM
|
|
55
|
+
record each platform's base, as `base:linux/amd64`, `base:linux/arm64`, ...; a single-platform build keeps its one
|
|
56
|
+
`base` entry, byte for byte). `pull --platform` narrows an
|
|
57
|
+
index as before. A build with no `--platform`, one platform, or a list naming one platform produces exactly the bytes
|
|
58
|
+
and image ID it did. Both implementations, with conformance cases `example/blog:oci-platforms-*`, `net-oci-platforms`, `net-oci-platforms-single` and
|
|
59
|
+
`err-platform-list`. docs/CLI.md, "Multi-platform images". Not done: running the result on real amd64 and arm64
|
|
60
|
+
engines needs a container engine (CI's `engine:` tests); the index is checked against the image-spec structure and
|
|
61
|
+
pushed to and pulled from the in-process test registry. **Open decision, not changed**: for a files-only image with no
|
|
62
|
+
`--platform`, dropping the amd64 claim (or writing an index over the common pair) would change every existing image
|
|
63
|
+
ID, so the default stays `linux/amd64`. `--platform` is still checked only where an image, a `BASE` or an
|
|
64
|
+
attestation needs it: `sitefile build -o dist/ --platform bogus` on a directory export builds as before.
|
|
65
|
+
**Downgrade hazard**: the store has no format version that an older sitefile checks (`oci-layout` is only created,
|
|
66
|
+
never read), so an older sitefile that runs `tag`, `rmi` or `build -t` on a store holding a multi-platform image
|
|
67
|
+
rewrites that entry as a plain image. A newer sitefile then refuses the image with an `E_STORE` that says what
|
|
68
|
+
happened; rebuild it (`build -t <name> --platform ...`) or pull it again. Do not share one `SITEFILE_HOME` between
|
|
69
|
+
versions.
|
|
70
|
+
|
|
71
|
+
- Fix (Windows): concurrent writers could fail with `cannot lock the store … Access is denied (os error 5)` when one created the lock file while another was deleting it. A lock file pending deletion now counts as busy, in both implementations; any other error is unchanged, and a denial that lasts past the 20 s deadline is still reported (#337).
|
|
72
|
+
|
|
73
|
+
- Tests: the Brotli parity check accepts node:zlib Brotli 1.2.1, which newer Node 26 releases bundle: it writes the same bytes as the vendored 1.2.0 (pinned digests and a 130-file corpus). The bytes are checked first, and an unverified version still fails (#335, #336).
|
|
74
|
+
|
|
75
|
+
- **Configurable default recipe file names** (johnhenry/sitefile#332, PR #333): the file read when no
|
|
76
|
+
`-f` is given is the first existing name of an ordered list, `["Sitefile"]` by default, so the CLI is
|
|
77
|
+
unchanged. Embedders set the list with `sitefile::set_recipe_names(&["Stockerfile", "Sitefile"])` in Rust, `setRecipeNames(["Stockerfile", "Sitefile"])` in TypeScript (one
|
|
78
|
+
process-wide default, which also reaches `sitefile::cli::main` and detached `serve` workers) or
|
|
79
|
+
per build with `BuildOptions::recipe_names` / `recipeNames`; a CLI user can opt in with `SITEFILE_RECIPE_NAMES`
|
|
80
|
+
(comma-separated). `recipe::resolve_recipe` / `resolveRecipe` is the one resolver per implementation, used by build, validate, inspect, graph,
|
|
81
|
+
why, hosts, vendor, outdated, bake, attestations, `serve` (project or plain folder) and watch mode (a
|
|
82
|
+
change to the recipe in use rebuilds). When none exists the error names the files tried (`no recipe
|
|
83
|
+
found in 'dir' (tried: Stockerfile, Sitefile)`); with the default list the message is unchanged.
|
|
84
|
+
`Sitefile.lock` and `IMPORT … AS sitefile` keep their names. docs/CLI.md, "Which file is the recipe",
|
|
85
|
+
and docs/RUST.md, "Embedding the crate". New public items only; Rust `BuildOptions` gains a field (use
|
|
86
|
+
`..Default::default()`). Both implementations, with conformance cases `recipe-names` and `err-recipe-names-missing`; `IMPORT … AS sitefile` is the follow-up johnhenry/sitefile#334.
|
|
87
|
+
|
|
88
|
+
## 0.0.7 (2026-11-10)
|
|
89
|
+
|
|
90
|
+
- **Windows build of the Rust binary** (johnhenry/sitefile#318, PR #327): `rust/` now builds for
|
|
91
|
+
`x86_64-pc-windows-msvc`. Unix-only code is behind `cfg(unix)`, with Windows stand-ins in the new
|
|
92
|
+
`rust/src/platform.rs` (on Unix it re-exports the `std::os::unix` items, so nothing changes there):
|
|
93
|
+
hard-link counts and file identity come from `GetFileInformationByHandle` (kernel32, no new crate),
|
|
94
|
+
permission bits are neither applied nor read, and `serve -d` / `server restart` fail with
|
|
95
|
+
`E_UNSUPPORTED`. `serve` shows no network URLs and reads keys line by line there, and the wasm
|
|
96
|
+
module disk cache is off. sha2's `asm` feature is now enabled everywhere but MSVC (sha2-asm does
|
|
97
|
+
not build there). CI gains a `rust-windows` job (build and the tests that can run on Windows; the
|
|
98
|
+
rest are `#[cfg(unix)]`), and release-binaries.yml a `x86_64-pc-windows-msvc` zip with
|
|
99
|
+
`sitefile.exe`, `LICENSE` and `README.md`, included in `SHA256SUMS`. docs/RUST.md, "Windows",
|
|
100
|
+
lists every difference.
|
|
4
101
|
|
|
5
102
|
## 0.0.6 (2026-11-09)
|
|
6
103
|
|
package/README.md
CHANGED
|
@@ -261,6 +261,10 @@ Targets also take `context`, `file`, `target` (a stage), `format`, `tags` and `i
|
|
|
261
261
|
when one fails (then the exit code is 1); outputs that overlap or a tag used twice are refused before anything is
|
|
262
262
|
built. See [docs/CLI.md](docs/CLI.md#variants-sitefile-bake).
|
|
263
263
|
|
|
264
|
+
## Recipe file name
|
|
265
|
+
|
|
266
|
+
Without `-f`, the recipe is the first existing name of `["Sitefile"]`. `SITEFILE_RECIPE_NAMES=Stockerfile,Sitefile` changes the list for a CLI run; programs that embed the library call `setRecipeNames` (TypeScript) or `sitefile::set_recipe_names` (Rust). See [docs/CLI.md](docs/CLI.md#which-file-is-the-recipe).
|
|
267
|
+
|
|
264
268
|
## Watch mode
|
|
265
269
|
|
|
266
270
|
```bash
|
|
@@ -374,6 +378,7 @@ stopgap in VS Code.
|
|
|
374
378
|
- [docs/PLUGINS.md](docs/PLUGINS.md) — writing renderer plugins, and the sandbox
|
|
375
379
|
- [docs/DOCKER.md](docs/DOCKER.md) — sitefile next to Docker: site images Docker runs, Dockerfile stages, shared registries
|
|
376
380
|
- [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) — invariants and module layout
|
|
381
|
+
- [docs/design/attachments.md](docs/design/attachments.md) — design note: serve-time attachments or the gateway pattern (#341)
|
|
377
382
|
- [docs/MILESTONES.md](docs/MILESTONES.md), [docs/TASKS.md](docs/TASKS.md)
|
|
378
383
|
- [AGENTS.md](AGENTS.md) — the verification loop and rules for anyone (human or agent) changing this repo
|
|
379
384
|
|
package/lib/src/attest.d.ts
CHANGED
|
@@ -76,6 +76,12 @@ export interface BuildFacts {
|
|
|
76
76
|
readonly name: string;
|
|
77
77
|
readonly digest: string;
|
|
78
78
|
} | undefined;
|
|
79
|
+
/** With two or more platforms: each platform's BASE (name and manifest digest), in platform order. `base` is the first one's. */
|
|
80
|
+
readonly bases?: ReadonlyArray<{
|
|
81
|
+
readonly platform: string;
|
|
82
|
+
readonly name: string;
|
|
83
|
+
readonly digest: string;
|
|
84
|
+
}> | undefined;
|
|
79
85
|
/** `FROM image` stage bases, in stage order (FROM line, image name, image digest). */
|
|
80
86
|
/** `import`: the qualified name of the imported Sitefile (IMPORT … AS sitefile) whose stage it is. */
|
|
81
87
|
readonly images?: ReadonlyArray<{
|
|
@@ -93,6 +99,8 @@ export interface BuildFacts {
|
|
|
93
99
|
export interface AttestSubject {
|
|
94
100
|
readonly digest: string;
|
|
95
101
|
readonly size: number;
|
|
102
|
+
/** The subject's media type: an image manifest (default) or, for a multi-platform image, an image index. */
|
|
103
|
+
readonly mediaType?: string | undefined;
|
|
96
104
|
/** The site's files (rooted at `/`) and where they sit in the image. */
|
|
97
105
|
readonly files: Tree;
|
|
98
106
|
readonly root: string;
|
|
@@ -102,11 +110,12 @@ export interface AttestSubject {
|
|
|
102
110
|
/** Whether a build-arg name looks like it holds a secret (any `_`-separated word is key, token, password, ...). */
|
|
103
111
|
export declare function isSecretArgName(name: string): boolean;
|
|
104
112
|
/** The Sitefile path the build used, as `build` resolves it. */
|
|
105
|
-
export declare function sitefilePathOf(contextDir: string, sitefile: string | undefined): string;
|
|
113
|
+
export declare function sitefilePathOf(contextDir: string, sitefile: string | undefined, recipeNames?: readonly string[]): string;
|
|
106
114
|
/** Collect the facts for a finished build. Reads the Sitefile again to digest it. */
|
|
107
|
-
export declare function buildFacts(result: Pick<BuildResult, 'resources' | 'base' | 'pins' | 'images'>, options: {
|
|
115
|
+
export declare function buildFacts(result: Pick<BuildResult, 'resources' | 'base' | 'bases' | 'pins' | 'images'>, options: {
|
|
108
116
|
readonly contextDir: string;
|
|
109
117
|
readonly sitefile?: string | undefined;
|
|
118
|
+
readonly recipeNames?: readonly string[] | undefined;
|
|
110
119
|
readonly label?: string | undefined;
|
|
111
120
|
readonly buildArgs?: Readonly<Record<string, string>> | undefined;
|
|
112
121
|
readonly platform?: string | undefined;
|
|
@@ -116,7 +125,7 @@ export declare function provenancePredicate(facts: BuildFacts, epoch: number | u
|
|
|
116
125
|
/** CycloneDX 1.6 SBOM: the image, its BASE and every file of the site layer. */
|
|
117
126
|
export declare function sbomPredicate(subject: AttestSubject, facts: BuildFacts, epoch: number | undefined): Record<string, unknown>;
|
|
118
127
|
/** Wrap a predicate in an in-toto statement about `subject` and an OCI artifact manifest. */
|
|
119
|
-
export declare function attestationReferrer(subject: Pick<AttestSubject, 'digest' | 'size'>, predicateType: string, predicate: unknown): Referrer;
|
|
128
|
+
export declare function attestationReferrer(subject: Pick<AttestSubject, 'digest' | 'size' | 'mediaType'>, predicateType: string, predicate: unknown): Referrer;
|
|
120
129
|
/** The requested attestations for an image, provenance first. */
|
|
121
130
|
export declare function makeAttestations(subject: AttestSubject, facts: BuildFacts, request: AttestRequest, epoch: number | undefined): Referrer[];
|
|
122
131
|
/** An OCI image index listing referrers (the store's referrers file and the registry fallback tag). */
|
package/lib/src/attest.js
CHANGED
|
@@ -2,7 +2,8 @@ import { readFile } from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { sha256 } from './digest.js';
|
|
4
4
|
import { SitefileError } from './errors.js';
|
|
5
|
-
import {
|
|
5
|
+
import { recipePath } from './recipe.js';
|
|
6
|
+
import { canonicalJson, MEDIA, parsePlatforms } from './oci.js';
|
|
6
7
|
import { SITEFILE_VERSION } from './version.js';
|
|
7
8
|
/**
|
|
8
9
|
* Build attestations for OCI site images (`build --provenance` / `--sbom`).
|
|
@@ -48,12 +49,12 @@ export function isSecretArgName(name) {
|
|
|
48
49
|
.some((w) => SECRET_WORDS.has(w));
|
|
49
50
|
}
|
|
50
51
|
/** The Sitefile path the build used, as `build` resolves it. */
|
|
51
|
-
export function sitefilePathOf(contextDir, sitefile) {
|
|
52
|
-
return path.resolve(sitefile ??
|
|
52
|
+
export function sitefilePathOf(contextDir, sitefile, recipeNames) {
|
|
53
|
+
return path.resolve(sitefile ?? recipePath(contextDir, recipeNames));
|
|
53
54
|
}
|
|
54
55
|
/** Collect the facts for a finished build. Reads the Sitefile again to digest it. */
|
|
55
56
|
export async function buildFacts(result, options) {
|
|
56
|
-
const file = sitefilePathOf(options.contextDir, options.sitefile);
|
|
57
|
+
const file = sitefilePathOf(options.contextDir, options.sitefile, options.recipeNames);
|
|
57
58
|
let bytes;
|
|
58
59
|
try {
|
|
59
60
|
bytes = new Uint8Array(await readFile(file));
|
|
@@ -79,9 +80,11 @@ export async function buildFacts(result, options) {
|
|
|
79
80
|
sitefileDigest: sha256(bytes),
|
|
80
81
|
args,
|
|
81
82
|
redactedArgs,
|
|
82
|
-
|
|
83
|
+
// A list is recorded sorted and without repeats, as the image index lists it.
|
|
84
|
+
platform: options.platform === undefined ? 'linux/amd64' : parsePlatforms(options.platform).join(','),
|
|
83
85
|
imports,
|
|
84
86
|
base: result.base ? { name: result.base.name, digest: result.base.manifestDigest } : undefined,
|
|
87
|
+
...(result.bases && result.bases.size > 1 ? { bases: [...result.bases].map(([platform, b]) => ({ platform, name: b.name, digest: b.manifestDigest })) } : {}),
|
|
85
88
|
images: result.images?.map((i) => ({ line: i.line, name: i.name, digest: i.digest, ...(i.import !== undefined ? { import: i.import } : {}) })),
|
|
86
89
|
pins: result.pins,
|
|
87
90
|
label: options.label ?? (path.relative(process.cwd(), file) || path.basename(file)),
|
|
@@ -114,8 +117,9 @@ export function provenancePredicate(facts, epoch) {
|
|
|
114
117
|
const pin = i.import === undefined ? facts.pins?.images?.[i.line] : undefined;
|
|
115
118
|
deps.push({ name: i.import === undefined ? `from:${i.line}` : `from:${i.import}:${i.line}`, uri: i.name, digest: { sha256: hex(i.digest) }, ...(pin ? { annotations: { 'dev.sitefile.pin': pin } } : {}) });
|
|
116
119
|
}
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
// One BASE per platform when there are several (`base:<os>/<arch>`); a single-platform build keeps its one `base`.
|
|
121
|
+
for (const b of facts.bases ?? (facts.base ? [{ platform: undefined, ...facts.base }] : [])) {
|
|
122
|
+
deps.push({ name: b.platform === undefined ? 'base' : `base:${b.platform}`, uri: b.name, digest: { sha256: hex(b.digest) }, ...(facts.pins?.base ? { annotations: { 'dev.sitefile.pin': facts.pins.base } } : {}) });
|
|
119
123
|
}
|
|
120
124
|
const runDetails = { builder: { id: ATTEST.builderId, version: { sitefile: SITEFILE_VERSION } } };
|
|
121
125
|
if (epoch !== undefined)
|
|
@@ -131,8 +135,9 @@ export function sbomPredicate(subject, facts, epoch) {
|
|
|
131
135
|
if (epoch !== undefined)
|
|
132
136
|
metadata.timestamp = isoOf(epoch);
|
|
133
137
|
const components = [];
|
|
134
|
-
|
|
135
|
-
components.push({ type: 'container', 'bom-ref': 'base'
|
|
138
|
+
for (const b of facts.bases ?? (facts.base ? [{ platform: undefined, ...facts.base }] : [])) {
|
|
139
|
+
components.push({ type: 'container', 'bom-ref': b.platform === undefined ? 'base' : `base:${b.platform}`, name: b.name, version: b.digest });
|
|
140
|
+
}
|
|
136
141
|
const prefix = `${facts.label}:`;
|
|
137
142
|
for (const [p, n] of subject.files.entries()) {
|
|
138
143
|
const name = subject.root === '/' ? p : subject.root + p;
|
|
@@ -162,7 +167,7 @@ export function attestationReferrer(subject, predicateType, predicate) {
|
|
|
162
167
|
artifactType: ATTEST.inToto,
|
|
163
168
|
config: { mediaType: ATTEST.emptyConfig, digest: EMPTY_DIGEST, size: EMPTY_JSON.byteLength },
|
|
164
169
|
layers: [{ mediaType: ATTEST.inToto, digest: layerDigest, size: statement.byteLength, annotations }],
|
|
165
|
-
subject: { mediaType: MEDIA.manifest, digest: subject.digest, size: subject.size },
|
|
170
|
+
subject: { mediaType: subject.mediaType ?? MEDIA.manifest, digest: subject.digest, size: subject.size },
|
|
166
171
|
annotations,
|
|
167
172
|
}));
|
|
168
173
|
const digest = sha256(manifest);
|
package/lib/src/bake.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { SitefileError } from './errors.js';
|
|
4
|
+
import { recipePath } from './recipe.js';
|
|
4
5
|
import { collectBuildArgs } from './build-args.js';
|
|
5
6
|
import { planBuild, sitefileCompression } from './executor.js';
|
|
6
7
|
import { defaultOutName } from './export-formats.js';
|
|
@@ -228,7 +229,7 @@ function expand(def, bakeDir) {
|
|
|
228
229
|
list.push({
|
|
229
230
|
name,
|
|
230
231
|
context,
|
|
231
|
-
file: fields.file !== undefined ? joinTo(bakeDir, sub('file', fields.file)) :
|
|
232
|
+
file: fields.file !== undefined ? joinTo(bakeDir, sub('file', fields.file)) : recipePath(context),
|
|
232
233
|
args,
|
|
233
234
|
argFiles: (fields['arg-files'] ?? []).map((f) => joinTo(bakeDir, sub('arg-files', f))),
|
|
234
235
|
target: fields.target !== undefined ? sub('target', fields.target) : null,
|
package/lib/src/base-image.d.ts
CHANGED
|
@@ -74,3 +74,5 @@ export interface FromImage {
|
|
|
74
74
|
export declare function resolveFromImage(input: string, at: string | undefined, local: boolean, o: ResolveBaseOptions): Promise<FromImage>;
|
|
75
75
|
/** Read the blobs of `layers` from the store (verifying each digest), for writing a self-contained layout. */
|
|
76
76
|
export declare function readLayerBlobs(store: Store, layers: readonly Descriptor[]): Promise<Map<string, Uint8Array>>;
|
|
77
|
+
/** {@link readLayerBlobs} for the base layers of several platforms (layers they share are read once). */
|
|
78
|
+
export declare function readBaseBlobs(store: Store, layers: ReadonlyArray<readonly Descriptor[]>): Promise<Map<string, Uint8Array>>;
|
package/lib/src/base-image.js
CHANGED
|
@@ -135,4 +135,12 @@ export async function readLayerBlobs(store, layers) {
|
|
|
135
135
|
out.set(l.digest, await store.readBlob(l.digest, l.size));
|
|
136
136
|
return out;
|
|
137
137
|
}
|
|
138
|
+
/** {@link readLayerBlobs} for the base layers of several platforms (layers they share are read once). */
|
|
139
|
+
export async function readBaseBlobs(store, layers) {
|
|
140
|
+
const out = new Map();
|
|
141
|
+
for (const l of layers)
|
|
142
|
+
for (const [d, b] of await readLayerBlobs(store, l))
|
|
143
|
+
out.set(d, b);
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
138
146
|
//# sourceMappingURL=base-image.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sourceDateEpoch } from '../archive-writers.js';
|
|
2
2
|
import { SitefileError } from '../errors.js';
|
|
3
3
|
import { imageAttestations, sitefileCompression } from '../executor.js';
|
|
4
|
-
import { imageMeta } from '../oci.js';
|
|
4
|
+
import { imageMeta, MEDIA } from '../oci.js';
|
|
5
5
|
import { parseLocalRef } from '../ref.js';
|
|
6
6
|
import { shortId, Store } from '../store.js';
|
|
7
7
|
/** Validate `-t` values before building: local name[:tag] only. Throws E_USAGE / E_UNSUPPORTED. */
|
|
@@ -25,12 +25,14 @@ export async function storeBuildAsImage(result, tags, info) {
|
|
|
25
25
|
platform: info.platform,
|
|
26
26
|
epoch: sourceDateEpoch(),
|
|
27
27
|
base: result.base,
|
|
28
|
+
...(result.bases ? { bases: result.bases } : {}),
|
|
28
29
|
...(await imageMeta(info.contextDir, { git: !!info.gitLabels, ...(info.labels ? { labels: info.labels } : {}) })),
|
|
29
30
|
});
|
|
30
31
|
if (info.attest && (info.attest.provenance || info.attest.sbom)) {
|
|
31
32
|
const manifestBytes = await store.readBlob(id);
|
|
32
33
|
const d = await store.details(id);
|
|
33
|
-
|
|
34
|
+
// A multi-platform image is attested as the index (its image ID); the config is the first platform's.
|
|
35
|
+
const img = { manifestDigest: id, manifestBytes, configBytes: await store.readBlob(d.manifest.config.digest), root: d.root, ...(d.platforms.length > 1 ? { mediaType: MEDIA.index } : {}) };
|
|
34
36
|
const opts = { contextDir: info.contextDir, ...info.build, ...(info.platform !== undefined ? { platform: info.platform } : {}) };
|
|
35
37
|
await store.putReferrers(id, await imageAttestations(result, img, opts, info.attest));
|
|
36
38
|
}
|
package/lib/src/cli/images.js
CHANGED
|
@@ -36,7 +36,7 @@ const images = {
|
|
|
36
36
|
if (v.json) {
|
|
37
37
|
const out = rows.map(({ im, tag }) => {
|
|
38
38
|
const [repository, t] = tag ? split(tag) : [null, null];
|
|
39
|
-
return { repository, tag: t, id: im.id, created: im.created, files: im.files, size: im.size };
|
|
39
|
+
return { repository, tag: t, id: im.id, created: im.created, files: im.files, size: im.size, ...(im.platforms.length > 1 ? { platforms: im.platforms } : {}) };
|
|
40
40
|
});
|
|
41
41
|
process.stdout.write(JSON.stringify(out, null, 2) + '\n');
|
|
42
42
|
return 0;
|
|
@@ -48,10 +48,12 @@ const images = {
|
|
|
48
48
|
(seen.add(im.id), process.stdout.write(`${shortId(im.id)}\n`));
|
|
49
49
|
return 0;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
// A PLATFORMS column shows only when the store holds a multi-platform image: one row, the platforms listed.
|
|
52
|
+
const multi = list.some((im) => im.platforms.length > 1);
|
|
53
|
+
const head = ['REPOSITORY', 'TAG', 'IMAGE ID', ...(v.digests ? ['DIGEST'] : []), ...(multi ? ['PLATFORMS'] : []), 'CREATED', 'FILES', 'SIZE'];
|
|
52
54
|
const body = rows.map(({ im, tag }) => {
|
|
53
55
|
const [repo, t] = tag ? split(tag) : ['<none>', '<none>'];
|
|
54
|
-
return [repo, t, shortId(im.id), ...(v.digests ? [im.id] : []), relativeTime(im.created), String(im.files), humanSize(im.size)];
|
|
56
|
+
return [repo, t, shortId(im.id), ...(v.digests ? [im.id] : []), ...(multi ? [im.platforms.join(',')] : []), relativeTime(im.created), String(im.files), humanSize(im.size)];
|
|
55
57
|
});
|
|
56
58
|
process.stdout.write(table([head, ...body]));
|
|
57
59
|
return 0;
|
|
@@ -61,7 +63,7 @@ const inspect = {
|
|
|
61
63
|
name: 'image inspect',
|
|
62
64
|
summary: 'show an image manifest',
|
|
63
65
|
usage: 'image inspect <ref|id> [--json]',
|
|
64
|
-
description: 'Show an image: its ID, tags, creation time, build metadata (ARG names only) and files.',
|
|
66
|
+
description: 'Show an image: its ID, tags, creation time, build metadata (ARG names only) and files. A multi-platform image (an image index) lists its platforms and shows the first one\'s manifest, config and layers.',
|
|
65
67
|
flags: ['--json machine-readable output'],
|
|
66
68
|
options: { json: { type: 'boolean' } },
|
|
67
69
|
async run(v, pos) {
|
|
@@ -79,6 +81,7 @@ const inspect = {
|
|
|
79
81
|
created: d.created,
|
|
80
82
|
os: d.config.os,
|
|
81
83
|
architecture: d.config.architecture,
|
|
84
|
+
...(d.platforms.length > 1 ? { platforms: d.platforms } : {}),
|
|
82
85
|
root: d.root,
|
|
83
86
|
size: d.size,
|
|
84
87
|
labels: d.config.labels,
|
|
@@ -95,7 +98,7 @@ const inspect = {
|
|
|
95
98
|
`ID: ${id}`,
|
|
96
99
|
`Tags: ${d.tags.join(', ') || '<none>'}`,
|
|
97
100
|
`Stored: ${d.created} (${relativeTime(d.created)})`,
|
|
98
|
-
`Platform: ${d.config.os}/${d.config.architecture}`,
|
|
101
|
+
d.platforms.length > 1 ? `Platforms: ${d.platforms.join(', ')} (an image index; the layers below are the first platform's)` : `Platform: ${d.config.os}/${d.config.architecture}`,
|
|
99
102
|
`Root: ${d.root}`,
|
|
100
103
|
`Layer: ${layer?.digest ?? '-'} (${humanSize(d.layerSize)} ${d.manifest.layers[siteLayerIndex(d.manifest, d.config)]?.mediaType === MEDIA.layerTar ? 'tar' : 'gzip'})`,
|
|
101
104
|
`Diff ID: ${d.config.diffIds[0] ?? '-'}`,
|
package/lib/src/cli/servers.js
CHANGED
|
@@ -5,12 +5,13 @@ import net from 'node:net';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { SitefileError } from '../errors.js';
|
|
8
|
+
import { findRecipeName, isDefaultRecipeNames, recipeNames, RECIPE_NAMES_ENV } from '../recipe.js';
|
|
8
9
|
import { collectBuildArgs } from '../build-args.js';
|
|
9
10
|
import { build } from '../executor.js';
|
|
10
11
|
import { networkOption } from './network.js';
|
|
11
12
|
import { DEFAULT_FETCH_POLICY } from '../resources/types.js';
|
|
12
|
-
import { BUILDING_EVENT, closeServer, createSiteServer, errorEvent, formatUrl, jsonLogLine, listen, logLineAsJson, networkUrls, parseCidr, parseMimeFlag, parseMimeTypes, parseThrottle, startedLogLine, LiveReload, OK_EVENT, parseAllowedHost, reloadEventFor, normalizeBase, safeSegments, normalizeProductionUrl, routingFor, HOST_PROFILES, HTML_HANDLINGS } from '../server.js';
|
|
13
|
-
import { isRunning, loadDirectoryTree, loadServedTree, pidAlive, servedLastModified, ServerRegistry, loadServedSite, checkSiteFiles } from '../servers.js';
|
|
13
|
+
import { BUILDING_EVENT, closeServer, createSiteResponder, createSiteServer, handlerOptionsOf, errorEvent, formatUrl, jsonLogLine, listen, logLineAsJson, networkUrls, parseCidr, parseMimeFlag, parseMimeTypes, parseThrottle, startedLogLine, LiveReload, OK_EVENT, parseAllowedHost, reloadEventFor, normalizeBase, safeSegments, normalizeProductionUrl, routingFor, HOST_PROFILES, HTML_HANDLINGS } from '../server.js';
|
|
14
|
+
import { isRunning, loadDirectoryTree, loadServedTree, pidAlive, servedLastModified, ServerRegistry, loadServedSite, checkSiteFiles, awaitReady } from '../servers.js';
|
|
14
15
|
import { BasicAuth, makeVerifier, parseAuthPair, parseHtpasswd } from '../serve-auth.js';
|
|
15
16
|
import { Store } from '../store.js';
|
|
16
17
|
import { Tree } from '../tree.js';
|
|
@@ -164,27 +165,16 @@ async function startDetached(reg, state) {
|
|
|
164
165
|
const child = spawn(process.execPath, [WORKER, state.id], {
|
|
165
166
|
detached: true,
|
|
166
167
|
stdio: ['ignore', log.fd, log.fd],
|
|
167
|
-
|
|
168
|
+
// The recipe names of this process reach the worker, which is another process.
|
|
169
|
+
env: { ...process.env, SITEFILE_HOME: reg.store.home, ...(isDefaultRecipeNames(recipeNames()) ? {} : { [RECIPE_NAMES_ENV]: recipeNames().join(',') }) },
|
|
168
170
|
});
|
|
169
171
|
await log.close();
|
|
170
172
|
let exited = false;
|
|
171
173
|
child.once('exit', () => (exited = true));
|
|
172
174
|
child.once('error', () => (exited = true));
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (cur?.ready) {
|
|
177
|
-
child.unref();
|
|
178
|
-
return cur;
|
|
179
|
-
}
|
|
180
|
-
if (exited || cur?.error || Date.now() > deadline) {
|
|
181
|
-
if (!exited)
|
|
182
|
-
child.kill('SIGKILL');
|
|
183
|
-
const why = cur?.error ?? (exited ? 'the server process exited before it was ready' : 'timed out waiting for the server to start');
|
|
184
|
-
throw new SitefileError('E_SERVER', why.replace(/^error\[E_SERVER\]: /, ''));
|
|
185
|
-
}
|
|
186
|
-
await sleep(40);
|
|
187
|
-
}
|
|
175
|
+
const up = await awaitReady(() => reg.read(state.id), () => exited, () => child.kill('SIGKILL'));
|
|
176
|
+
child.unref();
|
|
177
|
+
return up;
|
|
188
178
|
}
|
|
189
179
|
const run = {
|
|
190
180
|
name: 'serve',
|
|
@@ -297,6 +287,8 @@ const run = {
|
|
|
297
287
|
'allow-ip': { type: 'string', multiple: true },
|
|
298
288
|
'deny-ip': { type: 'string', multiple: true },
|
|
299
289
|
'stop-after': { type: 'string' },
|
|
290
|
+
// Hidden (conformance): answer the requests on stdin with the site handler and exit.
|
|
291
|
+
'respond-stdin': { type: 'boolean' },
|
|
300
292
|
'tls-cert': { type: 'string' },
|
|
301
293
|
compress: { type: 'boolean' },
|
|
302
294
|
throttle: { type: 'string' },
|
|
@@ -321,6 +313,8 @@ const run = {
|
|
|
321
313
|
sync: { type: 'string' },
|
|
322
314
|
},
|
|
323
315
|
async run(v, pos) {
|
|
316
|
+
if (v['respond-stdin'])
|
|
317
|
+
refuseWithRespondStdin(v);
|
|
324
318
|
if (v.watch && !v.detach)
|
|
325
319
|
return serveWatch(v, pos);
|
|
326
320
|
// `-d --watch`: a plain directory re-read on change, or a build context built and rebuilt on change,
|
|
@@ -375,7 +369,13 @@ const run = {
|
|
|
375
369
|
let current = tree;
|
|
376
370
|
const proxy = proxyOption(v);
|
|
377
371
|
const live = reload !== undefined ? new LiveReload({ reload }) : undefined;
|
|
378
|
-
const
|
|
372
|
+
const siteOptions = { ...(live ? { liveReload: live, warn } : {}), allowedHosts, proxy, cors: !!v.cors, ...(isolate ? { isolate } : {}), ...(cache ? { cache } : {}), ...logging, ...(auth.server ? { auth: auth.server } : {}), ...perIp, ...sharing.server, ...(tls.server ? { tls: tls.server } : {}), compress: !!v.compress, ...(throttle ? { throttle: throttle.limits } : {}), ...(mime ? { mime } : {}), lastModified: () => modified, log: logWriter(logging), ...(content ? { content } : {}), ...(country !== undefined ? { country } : {}), ...spa, ...(base !== undefined ? { base } : {}), ...(rewriteBase !== undefined ? { rewriteBase } : {}), ...(profile ? { profile } : {}), devNotFound: !isWildcard(bind.host) };
|
|
373
|
+
if (v['respond-stdin']) {
|
|
374
|
+
await respondStdin(() => current, siteOptions);
|
|
375
|
+
close();
|
|
376
|
+
return 0;
|
|
377
|
+
}
|
|
378
|
+
const server = createSiteServer(() => current, siteOptions);
|
|
379
379
|
const addr = await listen(server, bind.host, bind.port);
|
|
380
380
|
if (logging.logFormat === 'json')
|
|
381
381
|
process.stdout.write(`${startedLogLine(new Date().toISOString(), label, tree.size, siteUrl(addr.host, addr.port, base, tls.scheme))}\n`);
|
|
@@ -413,6 +413,44 @@ const run = {
|
|
|
413
413
|
return 0;
|
|
414
414
|
},
|
|
415
415
|
};
|
|
416
|
+
/**
|
|
417
|
+
* `--respond-stdin` has no listener, so what belongs to one is a usage error, not something silently ignored (or, for `-d`,
|
|
418
|
+
* a real server): detaching, watching, a bind address, TLS and authentication. The same refusal as the Rust CLI's.
|
|
419
|
+
*/
|
|
420
|
+
function refuseWithRespondStdin(v) {
|
|
421
|
+
for (const [flag, shown] of [['detach', '-d'], ['watch', '--watch'], ['publish', '-p'], ['tls-cert', '--tls-cert'], ['tls-key', '--tls-key'], ['auth', '--auth'], ['auth-file', '--auth-file']]) {
|
|
422
|
+
if (v[flag] !== undefined && v[flag] !== false)
|
|
423
|
+
usage(`--respond-stdin answers without a listener: it takes no ${shown}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* The hidden `serve --respond-stdin` (conformance, see conformance/servers.mjs): read a JSON array of requests
|
|
428
|
+
* (`{ method, target, headers }`) from stdin, answer each with the site handler alone (no listener, no `Host`
|
|
429
|
+
* check, no authentication) and print a JSON array of `{ status, headers: [[name, value]...], body: <base64> }`.
|
|
430
|
+
* The Rust twin is `respond_stdin` in rust/src/cli/servers.rs.
|
|
431
|
+
*/
|
|
432
|
+
async function respondStdin(site, options) {
|
|
433
|
+
let text = '';
|
|
434
|
+
for await (const chunk of process.stdin)
|
|
435
|
+
text += chunk;
|
|
436
|
+
const bad = () => usage('--respond-stdin expects a JSON array of requests ({ method, target, headers }) on stdin');
|
|
437
|
+
let requests;
|
|
438
|
+
try {
|
|
439
|
+
requests = JSON.parse(text);
|
|
440
|
+
}
|
|
441
|
+
catch {
|
|
442
|
+
bad();
|
|
443
|
+
}
|
|
444
|
+
if (!Array.isArray(requests) || requests.some((r) => typeof r !== 'object' || r === null || Array.isArray(r)))
|
|
445
|
+
bad();
|
|
446
|
+
const respond = createSiteResponder(site, handlerOptionsOf(options));
|
|
447
|
+
const answers = [];
|
|
448
|
+
for (const r of requests) {
|
|
449
|
+
const { response } = await respond({ method: r.method ?? 'GET', target: r.target ?? '/', headers: new Headers(r.headers ?? {}) });
|
|
450
|
+
answers.push({ status: response.status, headers: [...response.headers], body: Buffer.from(await response.arrayBuffer()).toString('base64') });
|
|
451
|
+
}
|
|
452
|
+
process.stdout.write(`${JSON.stringify(answers)}\n`);
|
|
453
|
+
}
|
|
416
454
|
/**
|
|
417
455
|
* `serve -d`: check that the source loads, allocate an ID and name, record the server, start its worker and
|
|
418
456
|
* wait until it listens. On failure the record is removed.
|
|
@@ -571,7 +609,7 @@ async function detachedWatchOf(v, source) {
|
|
|
571
609
|
...(v['navigate-to-changed'] ? { navigateToChanged: true } : {}),
|
|
572
610
|
...(v['keep-service-workers'] ? { keepServiceWorkers: true } : {}),
|
|
573
611
|
};
|
|
574
|
-
if (!buildFlags &&
|
|
612
|
+
if (!buildFlags && findRecipeName(dir) === undefined)
|
|
575
613
|
return page;
|
|
576
614
|
if (v['no-rewrite-base'] && v['rewrite-base'] !== undefined)
|
|
577
615
|
usage('--rewrite-base and --no-rewrite-base cannot be combined');
|
|
@@ -859,7 +897,7 @@ async function serveWatch(v, pos) {
|
|
|
859
897
|
const argFlags = strs(v['build-arg']);
|
|
860
898
|
const pollMs = pollOption(!!v.poll, str(v['poll-interval']));
|
|
861
899
|
const buildFlags = !!file || target !== undefined || argFiles.length > 0 || argFlags.length > 0;
|
|
862
|
-
const plain = !buildFlags &&
|
|
900
|
+
const plain = !buildFlags && findRecipeName(context) === undefined;
|
|
863
901
|
const cssInject = !v['no-css-inject'];
|
|
864
902
|
const navigate = !!v['navigate-to-changed'];
|
|
865
903
|
const reloadMode = reloadOf(v) ?? 'morph';
|
package/lib/src/cli/watch.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface WatchLoopOptions {
|
|
|
9
9
|
readonly context: string;
|
|
10
10
|
/** `-f`: the Sitefile path (default `<context>/Sitefile`). */
|
|
11
11
|
readonly sitefile?: string;
|
|
12
|
+
/** The recipe names searched when `sitefile` is not given (default: the process-wide list). */
|
|
13
|
+
readonly recipeNames?: readonly string[];
|
|
12
14
|
/** `--build-arg-file` files; they are re-read on every build. */
|
|
13
15
|
readonly argFiles: readonly string[];
|
|
14
16
|
readonly build: () => Promise<BuildOutcome>;
|
package/lib/src/cli/watch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { SitefileError } from '../errors.js';
|
|
4
|
+
import { recipePath } from '../recipe.js';
|
|
4
5
|
import { resolveStoreHome } from '../store.js';
|
|
5
6
|
import { DEFAULT_POLL_MS, isIgnoredChange, RebuildScheduler, resolveReal, watchPaths } from '../watch.js';
|
|
6
7
|
/**
|
|
@@ -36,7 +37,7 @@ export async function watchLoop(o) {
|
|
|
36
37
|
if (!st?.isDirectory())
|
|
37
38
|
throw new SitefileError('E_NOT_FOUND', `'${o.context}' is not a directory`);
|
|
38
39
|
const root = await fs.realpath(o.context);
|
|
39
|
-
const sitefile = await resolveReal(o.sitefile ??
|
|
40
|
+
const sitefile = await resolveReal(o.sitefile ?? recipePath(o.context, o.recipeNames));
|
|
40
41
|
const argFiles = await Promise.all(o.argFiles.map(resolveReal));
|
|
41
42
|
// The build itself writes the export, Sitefile.lock and (maybe) the store; none of that is input.
|
|
42
43
|
const ignored = new Set([await resolveReal(resolveStoreHome()), path.join(path.dirname(sitefile), 'Sitefile.lock')]);
|
package/lib/src/cli.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { errorJson, SitefileError, isSitefileError } from './errors.js';
|
|
5
|
+
import { findRecipeName, recipeNames } from './recipe.js';
|
|
5
6
|
import { build, buildToDirectory, checkPlanPins, lintBuild, planBuild, sitefileCompression } from './executor.js';
|
|
6
7
|
import { LINT_RULES } from './lint.js';
|
|
7
8
|
import { compressionFromExtension, defaultOutName, formatFromExtension } from './export-formats.js';
|
|
@@ -73,7 +74,9 @@ Options:
|
|
|
73
74
|
--sbom attach an SBOM attestation (CycloneDX: every file with its SHA-256);
|
|
74
75
|
both are OCI 1.1 referrers of the image (its ID does not change),
|
|
75
76
|
written into the oci export and kept with -t images for push
|
|
76
|
-
--platform <os/arch> oci image platform (default linux/amd64); with a BASE, the platform pulled
|
|
77
|
+
--platform <os/arch> oci image platform (default linux/amd64); with a BASE, the platform pulled.
|
|
78
|
+
A list (linux/amd64,linux/arm64) writes one image index over a manifest per
|
|
79
|
+
platform, the site layer shared; its digest is the image ID
|
|
77
80
|
--base <image> build the oci image on <image> (runnable; overrides EXPORT ... AS oci BASE);
|
|
78
81
|
a bare name means Docker Hub. Pin it: nginx:alpine@sha256:...
|
|
79
82
|
--insecure-registry <h> allow plain http to registry host[:port] (repeatable; localhost always may)
|
|
@@ -392,7 +395,7 @@ export async function main(argv, run = {}) {
|
|
|
392
395
|
const options = {
|
|
393
396
|
contextDir: context,
|
|
394
397
|
...(file ? { sitefile: file } : {}),
|
|
395
|
-
...(fetched ? { label: o.file ??
|
|
398
|
+
...(fetched ? { label: o.file ?? findRecipeName(context) ?? recipeNames()[0] } : {}),
|
|
396
399
|
...(o.target !== undefined ? { target: o.target } : {}),
|
|
397
400
|
buildArgs,
|
|
398
401
|
...(secrets.size ? { secrets } : {}),
|
|
@@ -464,7 +467,7 @@ export async function main(argv, run = {}) {
|
|
|
464
467
|
labels,
|
|
465
468
|
gitLabels: !!o['git-labels'],
|
|
466
469
|
attest,
|
|
467
|
-
build: { contextDir: context, ...(file ? { sitefile: file } : {}), ...(fetched ? { label: o.file ??
|
|
470
|
+
build: { contextDir: context, ...(file ? { sitefile: file } : {}), ...(fetched ? { label: o.file ?? findRecipeName(context) ?? recipeNames()[0] } : {}), buildArgs },
|
|
468
471
|
};
|
|
469
472
|
await remoteCache?.load();
|
|
470
473
|
const dictionaryFrom = await previousBuild(o['experimental-dictionary']);
|
package/lib/src/dictionary.d.ts
CHANGED
|
@@ -7,10 +7,4 @@ export interface DictionaryResult {
|
|
|
7
7
|
}
|
|
8
8
|
/** The exported tree with `.dcz` deltas against `previous` and the `Use-As-Dictionary` headers. */
|
|
9
9
|
export declare function addDictionaryDeltas(tree: Tree, previous: Tree): DictionaryResult;
|
|
10
|
-
|
|
11
|
-
export declare function acceptsDcz(acceptEncoding: string | undefined): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* The `dcz` response for `path`: the bytes of `<path>.dcz` when the request accepts `dcz` and its
|
|
14
|
-
* `Available-Dictionary` is the hash the delta was made against; otherwise undefined.
|
|
15
|
-
*/
|
|
16
|
-
export declare function deltaFor(tree: Tree, path: string, availableDictionary: string | undefined, acceptEncoding: string | undefined): Uint8Array | undefined;
|
|
10
|
+
export { acceptsDcz, deltaFor } from './serve-dictionary.js';
|
package/lib/src/dictionary.js
CHANGED
|
@@ -51,39 +51,5 @@ export function addDictionaryDeltas(tree, previous) {
|
|
|
51
51
|
}
|
|
52
52
|
return { tree: tree.withFiles(added, 'overwrite'), deltas };
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
function sfBinary(v) {
|
|
56
|
-
const m = v === undefined ? null : /^\s*:([A-Za-z0-9+/]*={0,2}):\s*$/.exec(v);
|
|
57
|
-
return m ? new Uint8Array(Buffer.from(m[1], 'base64')) : undefined;
|
|
58
|
-
}
|
|
59
|
-
/** True when `Accept-Encoding` lists `dcz` with a non-zero quality. */
|
|
60
|
-
export function acceptsDcz(acceptEncoding) {
|
|
61
|
-
if (acceptEncoding === undefined)
|
|
62
|
-
return false;
|
|
63
|
-
return acceptEncoding.split(',').some((part) => {
|
|
64
|
-
const [token, ...params] = part.split(';').map((s) => s.trim());
|
|
65
|
-
if (token?.toLowerCase() !== 'dcz')
|
|
66
|
-
return false;
|
|
67
|
-
const q = params.find((p) => /^q=/i.test(p));
|
|
68
|
-
return q === undefined || Number(q.slice(2)) > 0;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* The `dcz` response for `path`: the bytes of `<path>.dcz` when the request accepts `dcz` and its
|
|
73
|
-
* `Available-Dictionary` is the hash the delta was made against; otherwise undefined.
|
|
74
|
-
*/
|
|
75
|
-
export function deltaFor(tree, path, availableDictionary, acceptEncoding) {
|
|
76
|
-
if (!acceptsDcz(acceptEncoding))
|
|
77
|
-
return undefined;
|
|
78
|
-
const hash = sfBinary(availableDictionary);
|
|
79
|
-
if (!hash || hash.byteLength !== 32)
|
|
80
|
-
return undefined;
|
|
81
|
-
const sidecar = tree.get(`${path}.dcz`);
|
|
82
|
-
if (!sidecar || sidecar.bytes.byteLength < 40)
|
|
83
|
-
return undefined;
|
|
84
|
-
for (let i = 0; i < 32; i++)
|
|
85
|
-
if (sidecar.bytes[8 + i] !== hash[i])
|
|
86
|
-
return undefined;
|
|
87
|
-
return sidecar.bytes;
|
|
88
|
-
}
|
|
54
|
+
export { acceptsDcz, deltaFor } from './serve-dictionary.js';
|
|
89
55
|
//# sourceMappingURL=dictionary.js.map
|