@intentius/chant 0.124.84 → 0.124.86
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/bundle-check.d.ts +102 -0
- package/dist/bundle-check.d.ts.map +1 -0
- package/dist/bundle-check.js +310 -0
- package/dist/chant-install.d.ts +100 -0
- package/dist/chant-install.d.ts.map +1 -0
- package/dist/chant-install.js +158 -0
- package/dist/ci-commit.d.ts +19 -6
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +23 -4
- package/dist/ci-evidence-jobs.d.ts +54 -0
- package/dist/ci-evidence-jobs.d.ts.map +1 -0
- package/dist/ci-evidence-jobs.js +55 -0
- package/dist/ci-image.d.ts +274 -0
- package/dist/ci-image.d.ts.map +1 -0
- package/dist/ci-image.js +635 -0
- package/dist/ci-login.d.ts +150 -0
- package/dist/ci-login.d.ts.map +1 -0
- package/dist/ci-login.js +240 -0
- package/dist/ci-product.d.ts +16 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +17 -0
- package/dist/cli/commands/import-index.js +2 -2
- package/dist/cli/handlers/build.d.ts +8 -0
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +22 -4
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +57 -2
- package/dist/cli/handlers/ci-evidence.d.ts +3 -0
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -0
- package/dist/cli/handlers/ci-evidence.js +171 -0
- package/dist/cli/handlers/components.js +3 -3
- package/dist/cli/handlers/dead-guards.d.ts +3 -0
- package/dist/cli/handlers/dead-guards.d.ts.map +1 -0
- package/dist/cli/handlers/dead-guards.js +35 -0
- package/dist/cli/handlers/graph.js +4 -4
- package/dist/cli/handlers/lifecycle.d.ts +2 -1
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.js +5 -4
- package/dist/cli/handlers/local-chant.d.ts +16 -0
- package/dist/cli/handlers/local-chant.d.ts.map +1 -0
- package/dist/cli/handlers/local-chant.js +109 -0
- package/dist/cli/handlers/operator.js +2 -2
- package/dist/cli/handlers/search.js +5 -5
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +38 -0
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +28 -0
- package/dist/cli/registry.d.ts +16 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/check-hooks.d.ts +49 -0
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-hooks.js +64 -4
- package/dist/components/check-steps.d.ts +17 -0
- package/dist/components/check-steps.d.ts.map +1 -1
- package/dist/components/check-steps.js +37 -5
- package/dist/components/product-pipeline.d.ts +23 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +6 -2
- package/dist/components/product-plan.d.ts +137 -0
- package/dist/components/product-plan.d.ts.map +1 -0
- package/dist/components/product-plan.js +143 -0
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +2 -2
- package/dist/config.d.ts +39 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -3
- package/dist/dead-guards.d.ts +82 -0
- package/dist/dead-guards.d.ts.map +1 -0
- package/dist/dead-guards.js +436 -0
- package/dist/discovery/files.d.ts +3 -1
- package/dist/discovery/files.d.ts.map +1 -1
- package/dist/discovery/files.js +5 -3
- package/dist/drift-issue.d.ts +152 -0
- package/dist/drift-issue.d.ts.map +1 -0
- package/dist/drift-issue.js +167 -0
- package/dist/floor-table.d.ts +30 -0
- package/dist/floor-table.d.ts.map +1 -0
- package/dist/floor-table.data.d.ts +3 -0
- package/dist/floor-table.data.d.ts.map +1 -0
- package/dist/floor-table.data.js +178 -0
- package/dist/floor-table.js +56 -0
- package/dist/forge-flags.d.ts +90 -0
- package/dist/forge-flags.d.ts.map +1 -0
- package/dist/forge-flags.js +184 -0
- package/dist/lexicon.d.ts +69 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gated-op.d.ts +7 -1
- package/dist/lifecycle/gated-op.d.ts.map +1 -1
- package/dist/lifecycle/gated-op.js +7 -4
- package/dist/local-chant.d.ts +98 -0
- package/dist/local-chant.d.ts.map +1 -0
- package/dist/local-chant.js +307 -0
- package/dist/op/activities/predict-behaviour.js +2 -2
- package/dist/op/op-waves-evidence-spec.d.ts +13 -0
- package/dist/op/op-waves-evidence-spec.d.ts.map +1 -0
- package/dist/op/op-waves-evidence-spec.js +21 -0
- package/dist/op/op-waves-evidence.d.ts +38 -0
- package/dist/op/op-waves-evidence.d.ts.map +1 -0
- package/dist/op/op-waves-evidence.js +57 -0
- package/dist/op/op-waves-run.d.ts +4 -0
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +24 -1
- package/dist/op/op-waves.d.ts +17 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +23 -0
- package/dist/op/schedule-overdue.d.ts +41 -9
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +154 -25
- package/dist/plan-summary.d.ts +25 -0
- package/dist/plan-summary.d.ts.map +1 -1
- package/dist/plan-summary.js +31 -0
- package/dist/pr-plan-note.d.ts +35 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +10 -0
- package/dist/pr-post.d.ts +23 -0
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +125 -3
- package/dist/release-floors.d.ts +31 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +31 -1
- package/dist/state-migration.d.ts +24 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +100 -5
- package/dist/wave-runtime.mjs +305 -298
- package/dist/workspace/lexicon-outputs.d.ts.map +1 -1
- package/dist/workspace/lexicon-outputs.js +21 -7
- package/dist/workspace/reason-codes.d.ts +3 -0
- package/dist/workspace/reason-codes.d.ts.map +1 -1
- package/dist/workspace/reason-codes.js +4 -0
- package/dist/workspace/ref-gate.schema.json +85 -0
- package/dist/workspace/search-contract.d.ts +1 -1
- package/dist/workspace/search-contract.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.d.ts +51 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence-report.js +102 -0
- package/dist/workspace/trust/check-evidence.d.ts +126 -0
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence.js +237 -0
- package/dist/workspace/trust/local-evidence.d.ts +120 -0
- package/dist/workspace/trust/local-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/local-evidence.js +259 -0
- package/dist/workspace/trust/policy.d.ts +84 -0
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +94 -1
- package/dist/workspace/trust/ref-gate-cli.d.ts +33 -0
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate-cli.js +234 -0
- package/dist/workspace/trust/ref-gate-fixture.d.ts +38 -0
- package/dist/workspace/trust/ref-gate-fixture.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate-fixture.js +97 -0
- package/dist/workspace/trust/ref-gate.d.ts +187 -0
- package/dist/workspace/trust/ref-gate.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate.js +430 -0
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +18 -1
- package/package.json +1 -1
- package/src/bundle-check.test.ts +140 -0
- package/src/bundle-check.ts +352 -0
- package/src/chant-install.test.ts +112 -0
- package/src/chant-install.ts +179 -0
- package/src/ci-commit.test.ts +45 -0
- package/src/ci-commit.ts +38 -4
- package/src/ci-evidence-jobs.ts +67 -0
- package/src/ci-image.test.ts +506 -0
- package/src/ci-image.ts +822 -0
- package/src/ci-login.test.ts +235 -0
- package/src/ci-login.ts +307 -0
- package/src/ci-product.ts +18 -0
- package/src/cli/commands/__fixtures__/source-dir-include/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-include/infra.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-include/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-root/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/infra.test.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/infra.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/app.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/infra/net.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/import-index.ts +2 -2
- package/src/cli/handlers/build-source-dir.test.ts +64 -0
- package/src/cli/handlers/build.ts +21 -4
- package/src/cli/handlers/ci-check.ts +56 -3
- package/src/cli/handlers/ci-evidence.ts +162 -0
- package/src/cli/handlers/components.ts +3 -3
- package/src/cli/handlers/dead-guards.ts +37 -0
- package/src/cli/handlers/graph.ts +4 -4
- package/src/cli/handlers/lifecycle.ts +5 -4
- package/src/cli/handlers/local-chant.ts +106 -0
- package/src/cli/handlers/operator.ts +2 -2
- package/src/cli/handlers/search.ts +5 -5
- package/src/cli/main.test.ts +7 -0
- package/src/cli/main.ts +38 -0
- package/src/cli/parse-args.ts +21 -0
- package/src/cli/registry.ts +16 -0
- package/src/components/check-evidence-stage.test.ts +80 -0
- package/src/components/check-hooks.ts +84 -4
- package/src/components/check-local-evidence-stage.test.ts +141 -0
- package/src/components/check-steps.ts +56 -6
- package/src/components/product-pipeline.ts +28 -3
- package/src/components/product-plan.test.ts +87 -0
- package/src/components/product-plan.ts +226 -0
- package/src/components/release-compile.ts +2 -2
- package/src/config.ts +44 -3
- package/src/dead-guards.test.ts +206 -0
- package/src/dead-guards.ts +446 -0
- package/src/discovery/files.ts +5 -3
- package/src/drift-issue-bundle.test.ts +31 -0
- package/src/drift-issue.test.ts +206 -0
- package/src/drift-issue.ts +274 -0
- package/src/fit-note.test.ts +44 -0
- package/src/floor-table.data.ts +180 -0
- package/src/floor-table.ts +77 -0
- package/src/forge-flags.test.ts +110 -0
- package/src/forge-flags.ts +208 -0
- package/src/gate-decision-bundle.test.ts +1 -0
- package/src/lexicon.ts +68 -0
- package/src/lifecycle/gated-op.ts +10 -5
- package/src/local-chant.e2e.test.ts +94 -0
- package/src/local-chant.test.ts +162 -0
- package/src/local-chant.ts +341 -0
- package/src/op/activities/predict-behaviour.ts +2 -2
- package/src/op/op-waves-evidence-spec.ts +24 -0
- package/src/op/op-waves-evidence.test.ts +130 -0
- package/src/op/op-waves-evidence.ts +57 -0
- package/src/op/op-waves-run.ts +25 -1
- package/src/op/op-waves.ts +31 -1
- package/src/op/schedule-overdue.test.ts +85 -0
- package/src/op/schedule-overdue.ts +162 -26
- package/src/plan-summary.ts +40 -0
- package/src/pr-plan-note.ts +34 -0
- package/src/pr-post-plan-note.test.ts +146 -0
- package/src/pr-post.ts +127 -3
- package/src/release-floors.ts +44 -1
- package/src/stage-hooks-bundle.test.ts +1 -0
- package/src/state-migration.test.ts +52 -1
- package/src/state-migration.ts +107 -5
- package/src/workspace/lexicon-outputs.ts +23 -6
- package/src/workspace/reason-codes.test.ts +3 -0
- package/src/workspace/reason-codes.ts +4 -0
- package/src/workspace/ref-gate.schema.json +85 -0
- package/src/workspace/trust/check-evidence-report.ts +106 -0
- package/src/workspace/trust/check-evidence.test.ts +133 -0
- package/src/workspace/trust/check-evidence.ts +257 -0
- package/src/workspace/trust/local-evidence.test.ts +127 -0
- package/src/workspace/trust/local-evidence.ts +266 -0
- package/src/workspace/trust/policy.ts +134 -1
- package/src/workspace/trust/ref-gate-cli.ts +244 -0
- package/src/workspace/trust/ref-gate-fixture.ts +125 -0
- package/src/workspace/trust/ref-gate.e2e.test.ts +76 -0
- package/src/workspace/trust/ref-gate.test.ts +247 -0
- package/src/workspace/trust/ref-gate.ts +538 -0
- package/src/workspace/trust/trust-files.test.ts +16 -0
- package/src/workspace/trust/trust-files.ts +41 -1
package/dist/ci-image.js
ADDED
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CI images and engine installs for a CI product (#4784).
|
|
3
|
+
*
|
|
4
|
+
* terragucci, plywood and SQL Yodeler each built their CI image the same way:
|
|
5
|
+
* `node:22-bookworm-slim` by digest, git and CA certificates,
|
|
6
|
+
* `safe.directory '*'`, the product's bundle and the OCI labels, with each
|
|
7
|
+
* engine fetched in a separate stage and checked there. Each also installed
|
|
8
|
+
* engines in a job, and terragucci at run time from Node. This module is the
|
|
9
|
+
* one copy:
|
|
10
|
+
*
|
|
11
|
+
* - {@link ciToolRelease} names every engine release a product installs
|
|
12
|
+
* (tofu, terraform, terragrunt, choudoufu, infracost, cosign, atmos,
|
|
13
|
+
* terramate, pulumi, plunge, the AWS CLI, just, act) for Linux on amd64
|
|
14
|
+
* and arm64.
|
|
15
|
+
* - {@link CI_TOOL_SHA256} records the sha256 chant knows for a release. A
|
|
16
|
+
* product records others in its own config and passes them as `sha256`.
|
|
17
|
+
* - {@link ciToolFetchScript} is the shell that downloads one release and
|
|
18
|
+
* checks it, for an image's fetch stage; {@link ciToolInstallLine} is the
|
|
19
|
+
* job line that runs it unless the binary is there; {@link installCiTool}
|
|
20
|
+
* does the same from Node, for a product that installs a pinned release
|
|
21
|
+
* at run time.
|
|
22
|
+
* - {@link productImageStages} is a product's image as stages a Dockerfile
|
|
23
|
+
* takes (the docker lexicon's `new Dockerfile({ stages })`), and
|
|
24
|
+
* {@link productImageDockerfile} is the same as text. The product passes
|
|
25
|
+
* its name, its bundle, its words and its engines.
|
|
26
|
+
* - {@link derivedImageDockerfile} is an image a user builds FROM the
|
|
27
|
+
* product's, such as a provider mirror or preinstalled plugins.
|
|
28
|
+
*
|
|
29
|
+
* Every check follows one rule, in the shell and in Node. A release whose
|
|
30
|
+
* project publishes a checksums file is checked against that file's line
|
|
31
|
+
* for the archive, and against the recorded sha256 when there is one, so a
|
|
32
|
+
* tampered checksums file fails as a tampered archive does. A release with
|
|
33
|
+
* no checksums file (the AWS CLI, just, act) needs a recorded sha256. An
|
|
34
|
+
* image always needs a recorded sha256 for both architectures, and a caller
|
|
35
|
+
* passes `requirePin` to ask the same of a job line or a run-time install.
|
|
36
|
+
*
|
|
37
|
+
* Like `./policy-engine.ts` this module imports only node built-ins and
|
|
38
|
+
* chant's release floors, so a product can bundle it or import it from a
|
|
39
|
+
* plain Node script.
|
|
40
|
+
*/
|
|
41
|
+
import { spawnSync } from "node:child_process";
|
|
42
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
43
|
+
import { chmodSync, existsSync, mkdirSync, renameSync, writeFileSync } from "node:fs";
|
|
44
|
+
import { tmpdir } from "node:os";
|
|
45
|
+
import { join } from "node:path";
|
|
46
|
+
import { gunzipSync, inflateRawSync } from "node:zlib";
|
|
47
|
+
import { tarEntry } from "./policy-engine.js";
|
|
48
|
+
import { CI_IMAGE_FLOOR } from "./release-floors.js";
|
|
49
|
+
export { CI_IMAGE_FLOOR };
|
|
50
|
+
export const CI_TOOL_ARCHES = ["amd64", "arm64"];
|
|
51
|
+
const STD = { amd64: "amd64", arm64: "arm64" };
|
|
52
|
+
const GNU = { amd64: "x86_64", arm64: "aarch64" };
|
|
53
|
+
const NODE_WORDS = { amd64: "x64", arm64: "arm64" };
|
|
54
|
+
const TOOLS = {
|
|
55
|
+
tofu: {
|
|
56
|
+
bin: "tofu",
|
|
57
|
+
words: STD,
|
|
58
|
+
base: (v) => `https://github.com/opentofu/opentofu/releases/download/v${v}`,
|
|
59
|
+
asset: (v, w) => `tofu_${v}_linux_${w}.tar.gz`,
|
|
60
|
+
checksums: (v) => `tofu_${v}_SHA256SUMS`,
|
|
61
|
+
layout: "tar.gz",
|
|
62
|
+
},
|
|
63
|
+
terraform: {
|
|
64
|
+
bin: "terraform",
|
|
65
|
+
words: STD,
|
|
66
|
+
base: (v) => `https://releases.hashicorp.com/terraform/${v}`,
|
|
67
|
+
asset: (v, w) => `terraform_${v}_linux_${w}.zip`,
|
|
68
|
+
checksums: (v) => `terraform_${v}_SHA256SUMS`,
|
|
69
|
+
layout: "zip",
|
|
70
|
+
},
|
|
71
|
+
terragrunt: {
|
|
72
|
+
bin: "terragrunt",
|
|
73
|
+
words: STD,
|
|
74
|
+
base: (v) => `https://github.com/gruntwork-io/terragrunt/releases/download/v${v}`,
|
|
75
|
+
asset: (_v, w) => `terragrunt_linux_${w}`,
|
|
76
|
+
checksums: () => "SHA256SUMS",
|
|
77
|
+
layout: "binary",
|
|
78
|
+
},
|
|
79
|
+
choudoufu: {
|
|
80
|
+
bin: "choudoufu",
|
|
81
|
+
words: STD,
|
|
82
|
+
base: (v) => `https://github.com/INTENTIUS/choudoufu/releases/download/v${v}`,
|
|
83
|
+
asset: (v, w) => `choudoufu_v${v}_linux_${w}.tar.gz`,
|
|
84
|
+
checksums: () => "SHA256SUMS",
|
|
85
|
+
layout: "tar.gz",
|
|
86
|
+
},
|
|
87
|
+
infracost: {
|
|
88
|
+
bin: "infracost",
|
|
89
|
+
words: STD,
|
|
90
|
+
base: (v) => `https://github.com/infracost/infracost/releases/download/v${v}`,
|
|
91
|
+
asset: (_v, w) => `infracost-linux-${w}.tar.gz`,
|
|
92
|
+
// Each file has its own checksum file, in SHA256SUMS form.
|
|
93
|
+
checksums: (_v, asset) => `${asset}.sha256`,
|
|
94
|
+
layout: "tar.gz",
|
|
95
|
+
member: (w) => `infracost-linux-${w}`,
|
|
96
|
+
},
|
|
97
|
+
cosign: {
|
|
98
|
+
bin: "cosign",
|
|
99
|
+
words: STD,
|
|
100
|
+
base: (v) => `https://github.com/sigstore/cosign/releases/download/v${v}`,
|
|
101
|
+
asset: (_v, w) => `cosign-linux-${w}`,
|
|
102
|
+
checksums: () => "cosign_checksums.txt",
|
|
103
|
+
layout: "binary",
|
|
104
|
+
},
|
|
105
|
+
atmos: {
|
|
106
|
+
bin: "atmos",
|
|
107
|
+
words: STD,
|
|
108
|
+
base: (v) => `https://github.com/cloudposse/atmos/releases/download/v${v}`,
|
|
109
|
+
asset: (v, w) => `atmos_${v}_linux_${w}`,
|
|
110
|
+
checksums: (v) => `atmos_${v}_SHA256SUMS`,
|
|
111
|
+
layout: "binary",
|
|
112
|
+
},
|
|
113
|
+
terramate: {
|
|
114
|
+
bin: "terramate",
|
|
115
|
+
words: { amd64: "x86_64", arm64: "arm64" },
|
|
116
|
+
base: (v) => `https://github.com/terramate-io/terramate/releases/download/v${v}`,
|
|
117
|
+
asset: (v, w) => `terramate_${v}_linux_${w}.tar.gz`,
|
|
118
|
+
checksums: () => "checksums.txt",
|
|
119
|
+
layout: "tar.gz",
|
|
120
|
+
},
|
|
121
|
+
pulumi: {
|
|
122
|
+
bin: "pulumi",
|
|
123
|
+
words: NODE_WORDS,
|
|
124
|
+
base: (v) => `https://github.com/pulumi/pulumi/releases/download/v${v}`,
|
|
125
|
+
asset: (v, w) => `pulumi-v${v}-linux-${w}.tar.gz`,
|
|
126
|
+
checksums: (v) => `pulumi-${v}-checksums.txt`,
|
|
127
|
+
layout: "tree",
|
|
128
|
+
},
|
|
129
|
+
plunge: {
|
|
130
|
+
bin: "plunge",
|
|
131
|
+
words: NODE_WORDS,
|
|
132
|
+
base: (v) => `https://github.com/INTENTIUS/plunge/releases/download/plunge-v${v}`,
|
|
133
|
+
asset: (v, w) => `plunge-v${v}-linux-${w}.tar.gz`,
|
|
134
|
+
checksums: (v) => `plunge-v${v}-checksums.txt`,
|
|
135
|
+
layout: "tree",
|
|
136
|
+
},
|
|
137
|
+
"aws-cli": {
|
|
138
|
+
bin: "aws",
|
|
139
|
+
words: GNU,
|
|
140
|
+
base: () => "https://awscli.amazonaws.com",
|
|
141
|
+
asset: (v, w) => `awscli-exe-linux-${w}-${v}.zip`,
|
|
142
|
+
layout: "aws-cli",
|
|
143
|
+
path: "v2/current/bin/aws",
|
|
144
|
+
},
|
|
145
|
+
just: {
|
|
146
|
+
bin: "just",
|
|
147
|
+
words: GNU,
|
|
148
|
+
base: (v) => `https://github.com/casey/just/releases/download/${v}`,
|
|
149
|
+
asset: (v, w) => `just-${v}-${w}-unknown-linux-musl.tar.gz`,
|
|
150
|
+
layout: "tar.gz",
|
|
151
|
+
},
|
|
152
|
+
act: {
|
|
153
|
+
bin: "act",
|
|
154
|
+
words: { amd64: "x86_64", arm64: "arm64" },
|
|
155
|
+
base: (v) => `https://github.com/nektos/act/releases/download/v${v}`,
|
|
156
|
+
asset: (_v, w) => `act_Linux_${w}.tar.gz`,
|
|
157
|
+
layout: "tar.gz",
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
export const CI_TOOLS = Object.keys(TOOLS);
|
|
161
|
+
/**
|
|
162
|
+
* The sha256 of each release file chant records, as
|
|
163
|
+
* `<tool>-<version>-linux-<arch>`, copied from the release's checksums file
|
|
164
|
+
* (the AWS CLI's from the archives, as plywood and terragucci recorded them).
|
|
165
|
+
* A checksums file that lists another sum for one of these fails the
|
|
166
|
+
* install. Add a release's two lines when a product moves to it, or record
|
|
167
|
+
* them in the product's config and pass `sha256`.
|
|
168
|
+
*/
|
|
169
|
+
export const CI_TOOL_SHA256 = {
|
|
170
|
+
"tofu-1.13.1-linux-amd64": "378ada19d4bc70c43732004e8159be771b23b9a5afdf059e5f8a2b3fa2c70a69",
|
|
171
|
+
"tofu-1.13.1-linux-arm64": "9c1ef375aa1852db0b2888aa921b640c71f8140d4682aa4fec99378a64fa7dc3",
|
|
172
|
+
"choudoufu-0.31.0-linux-amd64": "1f38e5840b2e8c82e13a90652a9ffd75d5fbdff691f3f1a0ecee33fb8e4fae5b",
|
|
173
|
+
"choudoufu-0.31.0-linux-arm64": "00c9dc5c0a4260bae577bce081bc7fb7f2cc9f56757de2da4b3bdb4afaff3586",
|
|
174
|
+
"pulumi-3.272.0-linux-amd64": "58d545f2b98761051922008ebd381ecef95484d7f7a5ff7faa15d7a780ea84f6",
|
|
175
|
+
"pulumi-3.272.0-linux-arm64": "4f0741901b8982c4326b702dabf483c63d2cf77c88ac42dd752b72541284a534",
|
|
176
|
+
"plunge-0.1.0-linux-amd64": "22b89da39ab7dc11268c7b625fec3d99c0793c9c47bf8d031fa94e6967ee8187",
|
|
177
|
+
"plunge-0.1.0-linux-arm64": "6855611b8cf8381d73f5ddf0b5c0a0d83bdc2a5bd8c50d415e52bb05a4574f83",
|
|
178
|
+
"plunge-0.2.0-linux-amd64": "c9c73d05cca9ad214b7f44230a6162cdcb6ad64bbfc725bc94688b997b191495",
|
|
179
|
+
"plunge-0.2.0-linux-arm64": "c176a82f038164085aa19c8ad6530d6022e560e124050e535dbe364ae0473357",
|
|
180
|
+
"aws-cli-2.22.0-linux-amd64": "f315aa564190a12ae05a05bd8ab7b0645dd4a1ad71ce9e47dae4ff3dfeee8ceb",
|
|
181
|
+
"aws-cli-2.22.0-linux-arm64": "c932ac00901ea3c430f3829140b8dc00fa6e9b8b99d6891929a4795947de7f3e",
|
|
182
|
+
};
|
|
183
|
+
const VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?$/;
|
|
184
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
185
|
+
const DIR = /^\/[A-Za-z0-9._/-]*$/;
|
|
186
|
+
function spec(tool) {
|
|
187
|
+
const s = TOOLS[tool];
|
|
188
|
+
if (!s)
|
|
189
|
+
throw new Error(`chant installs ${CI_TOOLS.join(", ")}, not ${JSON.stringify(tool)}`);
|
|
190
|
+
return s;
|
|
191
|
+
}
|
|
192
|
+
function checkVersion(tool, version) {
|
|
193
|
+
if (!VERSION.test(version))
|
|
194
|
+
throw new Error(`${tool} version ${JSON.stringify(version)} is not a release version such as 1.2.3`);
|
|
195
|
+
}
|
|
196
|
+
/** The release file of `tool` at `version` for `arch`. A version is a plain semver, so it is safe on a shell line. */
|
|
197
|
+
export function ciToolRelease(tool, version, arch) {
|
|
198
|
+
const s = spec(tool);
|
|
199
|
+
checkVersion(tool, version);
|
|
200
|
+
const word = s.words[arch];
|
|
201
|
+
if (!word)
|
|
202
|
+
throw new Error(`chant fetches ${tool} for ${CI_TOOL_ARCHES.join(" and ")}, not ${JSON.stringify(arch)}`);
|
|
203
|
+
const base = s.base(version);
|
|
204
|
+
const asset = s.asset(version, word);
|
|
205
|
+
const checksums = s.checksums?.(version, asset);
|
|
206
|
+
return {
|
|
207
|
+
tool,
|
|
208
|
+
version,
|
|
209
|
+
arch,
|
|
210
|
+
bin: s.bin,
|
|
211
|
+
asset,
|
|
212
|
+
url: `${base}/${asset}`,
|
|
213
|
+
...(checksums ? { checksums, checksumsUrl: `${base}/${checksums}` } : {}),
|
|
214
|
+
layout: s.layout,
|
|
215
|
+
member: s.member?.(word) ?? s.bin,
|
|
216
|
+
path: s.path ?? s.bin,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/** The recorded sha256 of `tool` at `version` by architecture: the caller's, else {@link CI_TOOL_SHA256}'s. */
|
|
220
|
+
export function ciToolSha256(tool, version, given) {
|
|
221
|
+
spec(tool);
|
|
222
|
+
checkVersion(tool, version);
|
|
223
|
+
const out = {};
|
|
224
|
+
for (const arch of CI_TOOL_ARCHES) {
|
|
225
|
+
const sum = given ? given[arch] : CI_TOOL_SHA256[`${tool}-${version}-linux-${arch}`];
|
|
226
|
+
if (sum === undefined)
|
|
227
|
+
continue;
|
|
228
|
+
if (!SHA256.test(sum))
|
|
229
|
+
throw new Error(`the recorded sha256 for ${tool} ${version} on ${arch} is not 64 lower-case hex digits`);
|
|
230
|
+
out[arch] = sum;
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
/** Where a tool lives once installed: `<root>/<tool>-<version>`. */
|
|
235
|
+
export function ciToolDir(tool, version, root) {
|
|
236
|
+
checkVersion(tool, version);
|
|
237
|
+
if (!DIR.test(root))
|
|
238
|
+
throw new Error(`a tool root is an absolute path of letters, digits and ._/-, not ${JSON.stringify(root)}`);
|
|
239
|
+
return `${root.replace(/\/+$/, "")}/${tool}-${version}`;
|
|
240
|
+
}
|
|
241
|
+
/** The binary's path once installed under `root`. */
|
|
242
|
+
export function ciToolBin(tool, version, root) {
|
|
243
|
+
const s = spec(tool);
|
|
244
|
+
return `${ciToolDir(tool, version, root)}/${s.path ?? s.bin}`;
|
|
245
|
+
}
|
|
246
|
+
// ---------------------------------------------------------------------------
|
|
247
|
+
// The shell check, for an image's fetch stage and a job line
|
|
248
|
+
/** A shell expression giving the job's architecture as amd64 or arm64. */
|
|
249
|
+
export const CI_TOOL_JOB_ARCH = `"$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')"`;
|
|
250
|
+
/** A Docker build's target architecture (`ARG TARGETARCH`), amd64 or arm64. */
|
|
251
|
+
export const CI_TOOL_DOCKER_ARCH = `"$TARGETARCH"`;
|
|
252
|
+
function needPins(tool, version, sums, requirePin) {
|
|
253
|
+
const hasSums = spec(tool).checksums !== undefined;
|
|
254
|
+
const missing = CI_TOOL_ARCHES.filter((a) => !sums[a]);
|
|
255
|
+
if (missing.length && (requirePin || !hasSums)) {
|
|
256
|
+
const why = hasSums ? "" : `; ${tool}'s release publishes no checksums file, so chant needs one`;
|
|
257
|
+
throw new Error(`no recorded sha256 for ${tool} ${version} on ${missing.join(" and ")}${why}: record it from the release's checksums in the product's config and pass sha256`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Shell that downloads one release into `dir` and checks it (#4784). Run it
|
|
262
|
+
* under `set -e`. `arch` and `checksumsUrl` go onto the line as they are, so
|
|
263
|
+
* they are the caller's shell, never a value from outside. Throws when the
|
|
264
|
+
* release needs a recorded sha256 it lacks.
|
|
265
|
+
*/
|
|
266
|
+
export function ciToolFetchScript(tool, version, options) {
|
|
267
|
+
if (!DIR.test(options.dir))
|
|
268
|
+
throw new Error(`a fetch directory is an absolute path of letters, digits and ._/-, not ${JSON.stringify(options.dir)}`);
|
|
269
|
+
const s = spec(tool);
|
|
270
|
+
const sums = ciToolSha256(tool, version, options.sha256);
|
|
271
|
+
needPins(tool, version, sums, options.requirePin === true);
|
|
272
|
+
const name = `${tool} ${version}`;
|
|
273
|
+
const base = s.base(version);
|
|
274
|
+
const file = s.asset(version, "$w");
|
|
275
|
+
const dir = options.dir;
|
|
276
|
+
const lines = [
|
|
277
|
+
`a=${options.arch ?? CI_TOOL_JOB_ARCH}`,
|
|
278
|
+
`case "$a" in ${CI_TOOL_ARCHES.map((a) => `(${a}) w=${s.words[a]} ;;`).join(" ")} (*) echo "${name}: chant fetches it for ${CI_TOOL_ARCHES.join(" and ")}, not $a" >&2; exit 1 ;; esac`,
|
|
279
|
+
`f="${file}"`,
|
|
280
|
+
`t="$(mktemp -d)"`,
|
|
281
|
+
`curl -fsSLo "$t/$f" "${base}/$f"`,
|
|
282
|
+
`case "$a" in ${CI_TOOL_ARCHES.filter((a) => sums[a]).map((a) => `(${a}) want=${sums[a]} ;;`).join(" ")} (*) want= ;; esac`,
|
|
283
|
+
];
|
|
284
|
+
const checksums = s.checksums?.(version, file);
|
|
285
|
+
if (checksums) {
|
|
286
|
+
lines.push(`curl -fsSLo "$t/sums" ${options.checksumsUrl ?? `"${base}/${checksums}"`}`,
|
|
287
|
+
// The archive's line, with any ./ or * before the name taken off.
|
|
288
|
+
`line="$(sed -n "s#^\\([0-9a-f]\\{64\\}\\) *[*.]*/*$f\\$#\\1#p" "$t/sums")"`, `{ [ -n "$line" ] || { echo "${name}: $f is not in ${checksums}" >&2; exit 1; }; }`, `{ [ -z "$want" ] || [ "$line" = "$want" ] || { echo "${name}: ${checksums} lists $line for $f; chant records $want" >&2; exit 1; }; }`, `want="$line"`);
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
lines.push(`{ [ -n "$want" ] || { echo "${name}: no sha256 is recorded for $f" >&2; exit 1; }; }`);
|
|
292
|
+
}
|
|
293
|
+
lines.push(`echo "$want $t/$f" | sha256sum -c - >/dev/null`, `mkdir -p "${dir}"`);
|
|
294
|
+
const member = s.member?.("$w") ?? s.bin;
|
|
295
|
+
switch (s.layout) {
|
|
296
|
+
case "binary":
|
|
297
|
+
lines.push(`install -m 0755 "$t/$f" "${dir}/${s.bin}"`);
|
|
298
|
+
break;
|
|
299
|
+
case "tar.gz":
|
|
300
|
+
lines.push(`tar -xzf "$t/$f" -C "$t" "${member}"`, `install -m 0755 "$t/${member}" "${dir}/${s.bin}"`);
|
|
301
|
+
break;
|
|
302
|
+
case "zip":
|
|
303
|
+
lines.push(`unzip -q -o "$t/$f" "${member}" -d "$t"`, `install -m 0755 "$t/${member}" "${dir}/${s.bin}"`);
|
|
304
|
+
break;
|
|
305
|
+
case "tree":
|
|
306
|
+
lines.push(`tar -xzf "$t/$f" -C "${dir}" --strip-components=1`);
|
|
307
|
+
break;
|
|
308
|
+
case "aws-cli":
|
|
309
|
+
lines.push(`unzip -q "$t/$f" -d "$t"`, `"$t/aws/install" -i "${dir}" -b "${dir}/bin"`);
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
return lines.join(" && ");
|
|
313
|
+
}
|
|
314
|
+
/** Where a job line installs each release by default. */
|
|
315
|
+
export const CI_TOOL_ROOT = "/opt/chant";
|
|
316
|
+
/**
|
|
317
|
+
* The job line that installs `tool` at `version` under
|
|
318
|
+
* `<root>/<tool>-<version>/`, checked as {@link ciToolFetchScript} checks
|
|
319
|
+
* it. It skips the download when that directory holds the binary, as in an
|
|
320
|
+
* image that carries the release, and links the binary into /usr/local/bin
|
|
321
|
+
* unless `link` is false.
|
|
322
|
+
*/
|
|
323
|
+
export function ciToolInstallLine(tool, version, options = {}) {
|
|
324
|
+
const root = options.root ?? CI_TOOL_ROOT;
|
|
325
|
+
const dir = ciToolDir(tool, version, root);
|
|
326
|
+
const bin = ciToolBin(tool, version, root);
|
|
327
|
+
const s = spec(tool);
|
|
328
|
+
const install = `(set -e; ${ciToolFetchScript(tool, version, { dir, sha256: options.sha256, requirePin: options.requirePin })})`;
|
|
329
|
+
const inDir = `[ -x "${bin}" ]`;
|
|
330
|
+
const line = options.link === false ? `${inDir} || ${install}` : `{ ${inDir} || ${install}; } && ln -sf "${bin}" /usr/local/bin/${s.bin}`;
|
|
331
|
+
return options.onPath ? `command -v ${s.bin} >/dev/null 2>&1 || { ${line}; }` : line;
|
|
332
|
+
}
|
|
333
|
+
// ---------------------------------------------------------------------------
|
|
334
|
+
// The run-time install, from Node
|
|
335
|
+
/** The expected digest for `file` in a checksums file's text, or undefined when it lists none. A name may carry `*` or `./` before it. */
|
|
336
|
+
export function checksumFor(sums, file) {
|
|
337
|
+
for (const line of sums.split("\n")) {
|
|
338
|
+
const m = /^([0-9a-fA-F]{64})\s+\*?(?:\.\/)?(\S+)\s*$/.exec(line.trim());
|
|
339
|
+
if (m && m[2] === file)
|
|
340
|
+
return m[1].toLowerCase();
|
|
341
|
+
}
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
/** One file out of a zip archive, by name. Stored and deflated entries only, which is what releases use. */
|
|
345
|
+
export function unzipEntry(zip, name) {
|
|
346
|
+
const buf = Buffer.from(zip.buffer, zip.byteOffset, zip.byteLength);
|
|
347
|
+
let eocd = -1;
|
|
348
|
+
// The end-of-central-directory record is in the last 64 KiB plus 22 bytes.
|
|
349
|
+
for (let i = buf.length - 22; i >= Math.max(0, buf.length - 65557); i--) {
|
|
350
|
+
if (buf.readUInt32LE(i) === 0x06054b50) {
|
|
351
|
+
eocd = i;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (eocd < 0)
|
|
356
|
+
throw new Error("not a zip archive");
|
|
357
|
+
const count = buf.readUInt16LE(eocd + 10);
|
|
358
|
+
let p = buf.readUInt32LE(eocd + 16);
|
|
359
|
+
for (let n = 0; n < count; n++) {
|
|
360
|
+
if (buf.readUInt32LE(p) !== 0x02014b50)
|
|
361
|
+
throw new Error("corrupt zip central directory");
|
|
362
|
+
const method = buf.readUInt16LE(p + 10);
|
|
363
|
+
const size = buf.readUInt32LE(p + 20);
|
|
364
|
+
const nameLen = buf.readUInt16LE(p + 28);
|
|
365
|
+
const extraLen = buf.readUInt16LE(p + 30);
|
|
366
|
+
const commentLen = buf.readUInt16LE(p + 32);
|
|
367
|
+
const local = buf.readUInt32LE(p + 42);
|
|
368
|
+
if (buf.toString("utf-8", p + 46, p + 46 + nameLen) === name) {
|
|
369
|
+
const start = local + 30 + buf.readUInt16LE(local + 26) + buf.readUInt16LE(local + 28);
|
|
370
|
+
const data = buf.subarray(start, start + size);
|
|
371
|
+
if (method === 0)
|
|
372
|
+
return new Uint8Array(data);
|
|
373
|
+
if (method === 8)
|
|
374
|
+
return new Uint8Array(inflateRawSync(data));
|
|
375
|
+
throw new Error(`zip entry ${name} uses compression method ${method}`);
|
|
376
|
+
}
|
|
377
|
+
p += 46 + nameLen + extraLen + commentLen;
|
|
378
|
+
}
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
/** This process's architecture as chant fetches it. Throws on one chant has no builds for. */
|
|
382
|
+
export function ciToolArch(arch = process.arch) {
|
|
383
|
+
if (arch === "x64" || arch === "x86_64" || arch === "amd64")
|
|
384
|
+
return "amd64";
|
|
385
|
+
if (arch === "arm64" || arch === "aarch64")
|
|
386
|
+
return "arm64";
|
|
387
|
+
throw new Error(`chant fetches tools for ${CI_TOOL_ARCHES.join(" and ")}, not ${arch}`);
|
|
388
|
+
}
|
|
389
|
+
async function fetchBytes(url) {
|
|
390
|
+
const res = await fetch(url);
|
|
391
|
+
if (!res.ok)
|
|
392
|
+
throw new Error(`${url}: HTTP ${res.status}`);
|
|
393
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Install `tool` at `version` under `<root>/<tool>-<version>/` and return
|
|
397
|
+
* the directory and the binary, checked by the same rule as the shell
|
|
398
|
+
* (#4784). A binary already there is returned without a download. A
|
|
399
|
+
* download that does not match is never written.
|
|
400
|
+
*/
|
|
401
|
+
export async function installCiTool(tool, version, options = {}) {
|
|
402
|
+
const platform = options.platform ?? process.platform;
|
|
403
|
+
if (platform !== "linux")
|
|
404
|
+
throw new Error(`chant installs Linux builds of ${tool} for a CI job, and this machine is ${platform}; install it with your package manager`);
|
|
405
|
+
const arch = options.arch ?? ciToolArch();
|
|
406
|
+
const r = ciToolRelease(tool, version, arch);
|
|
407
|
+
if (r.layout === "aws-cli")
|
|
408
|
+
throw new Error("the AWS CLI installs with its own installer; use ciToolInstallLine in a job or the image's fetch stage");
|
|
409
|
+
const root = options.root ?? (process.env.CHANT_TOOL_CACHE || join(tmpdir(), "chant-tools"));
|
|
410
|
+
const dir = join(root, `${tool}-${version}`);
|
|
411
|
+
const bin = join(dir, r.path);
|
|
412
|
+
if (existsSync(bin))
|
|
413
|
+
return { dir, bin };
|
|
414
|
+
const pinned = ciToolSha256(tool, version, options.sha256)[arch];
|
|
415
|
+
if (!pinned && (options.requirePin || !r.checksumsUrl)) {
|
|
416
|
+
throw new Error(`no recorded sha256 for ${tool} ${version} on ${arch} (${r.asset}): record it from the release's checksums in the product's config and pass sha256`);
|
|
417
|
+
}
|
|
418
|
+
const download = options.download ?? fetchBytes;
|
|
419
|
+
const [body, sums] = await Promise.all([download(r.url), r.checksumsUrl ? download(r.checksumsUrl) : Promise.resolve(undefined)]);
|
|
420
|
+
let want = pinned;
|
|
421
|
+
if (sums !== undefined) {
|
|
422
|
+
const line = checksumFor(Buffer.from(sums).toString("utf-8"), r.asset);
|
|
423
|
+
if (!line)
|
|
424
|
+
throw new Error(`${tool} ${version}: ${r.asset} is not in ${r.checksums}`);
|
|
425
|
+
if (pinned && line !== pinned)
|
|
426
|
+
throw new Error(`${tool} ${version}: ${r.checksums} lists ${line} for ${r.asset}; chant records ${pinned}`);
|
|
427
|
+
want = line;
|
|
428
|
+
}
|
|
429
|
+
const sum = createHash("sha256").update(body).digest("hex");
|
|
430
|
+
if (sum !== want)
|
|
431
|
+
throw new Error(`${tool} ${version} from ${r.url} has sha256 ${sum}, not ${want}; not installing it`);
|
|
432
|
+
const nonce = randomBytes(6).toString("hex");
|
|
433
|
+
if (r.layout === "tree") {
|
|
434
|
+
// Unpacked beside the directory and renamed into place, so the binary is there only when the whole tree is.
|
|
435
|
+
if (existsSync(dir))
|
|
436
|
+
throw new Error(`${dir} is there without ${r.path}; remove it and run the install again`);
|
|
437
|
+
mkdirSync(root, { recursive: true });
|
|
438
|
+
const staging = join(root, `.${tool}-${version}.${nonce}`);
|
|
439
|
+
mkdirSync(staging);
|
|
440
|
+
const out = spawnSync("tar", ["-xz", "-C", staging, "--strip-components=1"], { input: body });
|
|
441
|
+
if (out.status !== 0)
|
|
442
|
+
throw new Error(`${r.asset} did not unpack: ${out.stderr?.toString().trim() || out.error?.message}`);
|
|
443
|
+
if (!existsSync(join(staging, r.path)))
|
|
444
|
+
throw new Error(`${r.asset} holds no ${r.path}`);
|
|
445
|
+
renameSync(staging, dir);
|
|
446
|
+
return { dir, bin };
|
|
447
|
+
}
|
|
448
|
+
mkdirSync(dir, { recursive: true });
|
|
449
|
+
// Written beside its final name and renamed, so a job that stops halfway leaves no binary behind.
|
|
450
|
+
const part = join(dir, `.${r.bin}.${nonce}`);
|
|
451
|
+
const binary = r.layout === "binary" ? body : r.layout === "zip" ? unzipEntry(body, r.member) : tarEntry(gunzipSync(body), r.member);
|
|
452
|
+
if (!binary)
|
|
453
|
+
throw new Error(`${r.asset} holds no ${r.member}`);
|
|
454
|
+
writeFileSync(part, binary);
|
|
455
|
+
chmodSync(part, 0o755);
|
|
456
|
+
renameSync(part, bin);
|
|
457
|
+
return { dir, bin };
|
|
458
|
+
}
|
|
459
|
+
// ---------------------------------------------------------------------------
|
|
460
|
+
// The product image
|
|
461
|
+
/**
|
|
462
|
+
* Base images by index digest, so a rebuild cannot change underneath a tag:
|
|
463
|
+
* the ones all three products pinned. `node` carries Node 22.23.3.
|
|
464
|
+
*/
|
|
465
|
+
export const CI_BASE_IMAGES = {
|
|
466
|
+
node: "node:22-bookworm-slim@sha256:c3de60bf2f9dd0ac6370e6117950ff62d6e339527e7472301c9c78a017978392",
|
|
467
|
+
debian: "debian:bookworm-slim@sha256:3783cc01769c7b2b1b83a5c5ad96c815348e28ed7da68e2e3687004faa906251",
|
|
468
|
+
};
|
|
469
|
+
/** The build argument a release passes its label in (chant's release.version). */
|
|
470
|
+
export const CI_IMAGE_LABEL_ARG = "CHANT_RELEASE_LABEL";
|
|
471
|
+
const NAME = /^[a-z0-9][a-z0-9._-]*$/;
|
|
472
|
+
const PKG = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*@\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
473
|
+
const ARG = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
474
|
+
function label(field, value) {
|
|
475
|
+
if (/["\n\\]/.test(value))
|
|
476
|
+
throw new Error(`the image's ${field} cannot hold a double quote, a backslash or a newline`);
|
|
477
|
+
return value;
|
|
478
|
+
}
|
|
479
|
+
/** apt's and dpkg's logs and ldconfig's cache carry the time of the build, so they go with the lists (#4657). */
|
|
480
|
+
function aptLine(packages) {
|
|
481
|
+
return `apt-get update && apt-get install -y --no-install-recommends ${packages.join(" ")} && rm -rf /var/lib/apt/lists/* /var/log/apt/* /var/log/dpkg.log /var/cache/ldconfig/aux-cache`;
|
|
482
|
+
}
|
|
483
|
+
/** The fetch stage's steps for `tools`, each into its directory under `root`. */
|
|
484
|
+
function fetchStage(tools, root) {
|
|
485
|
+
const steps = [{ arg: "TARGETARCH" }];
|
|
486
|
+
for (const t of tools) {
|
|
487
|
+
if (t.checksumsArg === undefined)
|
|
488
|
+
continue;
|
|
489
|
+
if (!ARG.test(t.checksumsArg))
|
|
490
|
+
throw new Error(`${t.tool}: checksumsArg ${JSON.stringify(t.checksumsArg)} is not a build argument name`);
|
|
491
|
+
const any = ciToolRelease(t.tool, t.version, "amd64");
|
|
492
|
+
if (!any.checksumsUrl)
|
|
493
|
+
throw new Error(`${t.tool}: its release publishes no checksums file, so checksumsArg has nothing to name`);
|
|
494
|
+
steps.push({ arg: `${t.checksumsArg}=${any.checksumsUrl}` });
|
|
495
|
+
}
|
|
496
|
+
steps.push({ run: "apt-get update && apt-get install -y --no-install-recommends ca-certificates curl unzip && rm -rf /var/lib/apt/lists/*" });
|
|
497
|
+
for (const t of tools) {
|
|
498
|
+
const script = ciToolFetchScript(t.tool, t.version, {
|
|
499
|
+
dir: ciToolDir(t.tool, t.version, root),
|
|
500
|
+
arch: CI_TOOL_DOCKER_ARCH,
|
|
501
|
+
sha256: t.sha256,
|
|
502
|
+
requirePin: true,
|
|
503
|
+
...(t.checksumsArg ? { checksumsUrl: `"$${t.checksumsArg}"` } : {}),
|
|
504
|
+
});
|
|
505
|
+
steps.push({ run: `set -e; ${script}` });
|
|
506
|
+
}
|
|
507
|
+
return { from: CI_BASE_IMAGES.debian, as: "fetch", steps };
|
|
508
|
+
}
|
|
509
|
+
function bundleSteps(b) {
|
|
510
|
+
if ("file" in b) {
|
|
511
|
+
if (!NAME.test(b.bin))
|
|
512
|
+
throw new Error(`bundle.bin ${JSON.stringify(b.bin)} is not a command name`);
|
|
513
|
+
return [{ copy: `--chmod=0755 ${b.file} /usr/local/bin/${b.bin}` }];
|
|
514
|
+
}
|
|
515
|
+
if ("tarball" in b) {
|
|
516
|
+
const base = b.tarball.split("/").pop();
|
|
517
|
+
return [
|
|
518
|
+
{ copy: `${b.tarball} /tmp/${base}` },
|
|
519
|
+
{ run: [`npm install -g --omit=dev --no-audit --no-fund /tmp/${base}`, `rm -f /tmp/${base}`, "npm cache clean --force", ...(b.check ? [b.check] : [])].join(" && ") },
|
|
520
|
+
];
|
|
521
|
+
}
|
|
522
|
+
if (!DIR.test(b.prefix))
|
|
523
|
+
throw new Error(`bundle.prefix ${JSON.stringify(b.prefix)} is not an absolute path`);
|
|
524
|
+
for (const a of b.require ?? [])
|
|
525
|
+
if (!ARG.test(a))
|
|
526
|
+
throw new Error(`bundle.require ${JSON.stringify(a)} is not a build argument name`);
|
|
527
|
+
const install = [
|
|
528
|
+
...(b.require ?? []).map((a) => `test -n "$${a}"`),
|
|
529
|
+
`mkdir -p ${b.prefix}`,
|
|
530
|
+
`cd ${b.prefix}`,
|
|
531
|
+
`echo '{"name":"ci-image","private":true}' > package.json`,
|
|
532
|
+
`{ ok=; for try in 1 2 3; do if npm install --omit=dev --no-audit --no-fund ${b.npm} 2>/tmp/npm.err; then ok=1; break; fi; cat /tmp/npm.err >&2; grep -qE "E404|ETARGET" /tmp/npm.err || break; [ "$try" = 3 ] || sleep 45; done; test -n "$ok"; }`,
|
|
533
|
+
"npm cache clean --force",
|
|
534
|
+
`ln -s ${b.prefix}/node_modules /node_modules`,
|
|
535
|
+
...(b.check ?? []),
|
|
536
|
+
].join(" && ");
|
|
537
|
+
return [{ run: b.mountContext ? `--mount=type=bind,target=/ctx ${install}` : install }];
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* A product's CI image as stages (#4784): a fetch stage that downloads each
|
|
541
|
+
* engine and checks it against a recorded sha256, then the pinned Node base
|
|
542
|
+
* with git and CA certificates, `safe.directory '*'`, the engines, the
|
|
543
|
+
* product's steps, its bundle and the OCI labels. Pass the stages to the
|
|
544
|
+
* docker lexicon's `new Dockerfile({ stages })`, or write
|
|
545
|
+
* {@link productImageDockerfile}'s text.
|
|
546
|
+
*/
|
|
547
|
+
export function productImageStages(spec) {
|
|
548
|
+
if (!NAME.test(spec.name))
|
|
549
|
+
throw new Error(`image name ${JSON.stringify(spec.name)} is not lower-case letters, digits and ._-`);
|
|
550
|
+
if (!NAME.test(spec.product))
|
|
551
|
+
throw new Error(`product ${JSON.stringify(spec.product)} is not lower-case letters, digits and ._-`);
|
|
552
|
+
const versionArg = spec.versionArg ?? CI_IMAGE_LABEL_ARG;
|
|
553
|
+
for (const a of [versionArg, ...(spec.args ?? [])])
|
|
554
|
+
if (!ARG.test(a))
|
|
555
|
+
throw new Error(`build argument ${JSON.stringify(a)} is not a name`);
|
|
556
|
+
for (const p of spec.packages ?? [])
|
|
557
|
+
if (!/^[a-z0-9][a-z0-9.+-]*$/.test(p))
|
|
558
|
+
throw new Error(`apt package ${JSON.stringify(p)} is not a package name`);
|
|
559
|
+
for (const p of spec.npm ?? [])
|
|
560
|
+
if (!PKG.test(p))
|
|
561
|
+
throw new Error(`npm package ${JSON.stringify(p)} is not a name at an exact version`);
|
|
562
|
+
if (spec.chant !== undefined && !VERSION.test(spec.chant))
|
|
563
|
+
throw new Error(`chant ${JSON.stringify(spec.chant)} is not a release version`);
|
|
564
|
+
const root = spec.toolRoot ?? `/opt/${spec.product}`;
|
|
565
|
+
const tools = spec.tools ?? [];
|
|
566
|
+
const seen = new Set();
|
|
567
|
+
for (const t of tools) {
|
|
568
|
+
if (seen.has(t.tool))
|
|
569
|
+
throw new Error(`${spec.name}: ${t.tool} is listed twice`);
|
|
570
|
+
seen.add(t.tool);
|
|
571
|
+
}
|
|
572
|
+
const steps = [];
|
|
573
|
+
for (const a of [versionArg, ...(spec.args ?? [])])
|
|
574
|
+
steps.push({ arg: a });
|
|
575
|
+
// A forge may run the job as a uid with no /etc/passwd entry, and Go then reads $USER and $HOME. A release builds each
|
|
576
|
+
// image twice and the two archives must match (#4657), so Node's compile cache and npm's debug logs are not written.
|
|
577
|
+
const env = [`USER=${spec.product}`, "HOME=/tmp", "NODE_DISABLE_COMPILE_CACHE=1", "npm_config_logs_max=0", ...(spec.env ?? [])];
|
|
578
|
+
if ("npm" in spec.bundle)
|
|
579
|
+
env.push(`PATH=${spec.bundle.prefix}/node_modules/.bin:$PATH`);
|
|
580
|
+
for (const e of env)
|
|
581
|
+
steps.push({ env: e });
|
|
582
|
+
steps.push({ run: aptLine(["git", "ca-certificates", ...(spec.packages ?? [])]) });
|
|
583
|
+
// A job often runs as another user than the one who owns its checkout, and git then refuses it ("dubious
|
|
584
|
+
// ownership"). Debian's git 2.39 matches no path prefix, so it is every directory (#4768).
|
|
585
|
+
steps.push({ run: "git config --system --add safe.directory '*'" });
|
|
586
|
+
if (spec.npm?.length) {
|
|
587
|
+
steps.push({ run: `npm install --prefix /usr/local --no-save --omit=dev --no-audit --no-fund ${spec.npm.join(" ")} && npm cache clean --force && rm -rf /tmp/.npm` });
|
|
588
|
+
}
|
|
589
|
+
if (spec.chant) {
|
|
590
|
+
// chant's one-file wave runtime from the release (npm checks the tarball's integrity), with a `chant` on PATH that runs it.
|
|
591
|
+
steps.push({
|
|
592
|
+
run: [
|
|
593
|
+
`cd /tmp && npm pack --silent @intentius/chant@${spec.chant}`,
|
|
594
|
+
`tar -xzf intentius-chant-${spec.chant}.tgz package/dist/wave-runtime.mjs`,
|
|
595
|
+
"install -D -m 0644 package/dist/wave-runtime.mjs /opt/chant/wave-runtime.mjs",
|
|
596
|
+
`printf '#!/bin/sh\\nexec node /opt/chant/wave-runtime.mjs "$@"\\n' > /usr/local/bin/chant && chmod 0755 /usr/local/bin/chant`,
|
|
597
|
+
"rm -rf /tmp/package /tmp/intentius-chant-*.tgz && npm cache clean --force && rm -rf /tmp/.npm",
|
|
598
|
+
].join(" && "),
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
if (tools.length) {
|
|
602
|
+
steps.push({ copy: `--from=fetch ${root}/ ${root}/` });
|
|
603
|
+
const links = tools.filter((t) => t.link !== false).map((t) => `ln -sf ${ciToolBin(t.tool, t.version, root)} /usr/local/bin/${TOOLS[t.tool].bin}`);
|
|
604
|
+
if (links.length)
|
|
605
|
+
steps.push({ run: links.join(" && ") });
|
|
606
|
+
}
|
|
607
|
+
steps.push(...(spec.steps ?? []));
|
|
608
|
+
steps.push(...bundleSteps(spec.bundle));
|
|
609
|
+
steps.push({ label: `org.opencontainers.image.title="${spec.name}"` }, { label: `org.opencontainers.image.description="${label("description", spec.description)}"` }, { label: `org.opencontainers.image.version="\${${versionArg}}"` }, { label: `org.opencontainers.image.source="${label("source", spec.source)}"` }, { label: `org.opencontainers.image.licenses="${label("licenses", spec.licenses ?? "Apache-2.0")}"` }, { cmd: spec.cmd ?? '["bash"]' });
|
|
610
|
+
return [...(tools.length ? [fetchStage(tools, root)] : []), { from: CI_BASE_IMAGES.node, steps }];
|
|
611
|
+
}
|
|
612
|
+
/** Stages as Dockerfile text, as the docker lexicon writes them, with `header` as comment lines on top. */
|
|
613
|
+
export function dockerfileText(stages, header = []) {
|
|
614
|
+
const lines = header.map((h) => (h ? `# ${h}` : "#"));
|
|
615
|
+
for (const s of stages) {
|
|
616
|
+
lines.push(`FROM ${s.from}${s.as ? ` AS ${s.as}` : ""}`);
|
|
617
|
+
for (const step of s.steps) {
|
|
618
|
+
const keys = Object.keys(step).filter((k) => step[k] !== undefined);
|
|
619
|
+
if (keys.length !== 1)
|
|
620
|
+
throw new Error(`a step names exactly one instruction, found ${keys.join(", ") || "none"}`);
|
|
621
|
+
lines.push(`${keys[0].toUpperCase()} ${step[keys[0]]}`);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return lines.join("\n") + "\n";
|
|
625
|
+
}
|
|
626
|
+
/** A product's CI image as Dockerfile text, with `header` as comment lines on top. */
|
|
627
|
+
export function productImageDockerfile(spec, header = []) {
|
|
628
|
+
return dockerfileText(productImageStages(spec), header);
|
|
629
|
+
}
|
|
630
|
+
/** A derived image's Dockerfile (#4784): FROM the product's image, the user's steps, nothing pushed. */
|
|
631
|
+
export function derivedImageDockerfile(spec) {
|
|
632
|
+
if (!spec.from || /\s/.test(spec.from))
|
|
633
|
+
throw new Error(`the derived image's from ${JSON.stringify(spec.from)} is not an image reference`);
|
|
634
|
+
return dockerfileText([{ from: spec.from, steps: spec.steps }], spec.header ?? []);
|
|
635
|
+
}
|