@olivervea/pipelines 2.0.0-beta.2 → 2.0.0-beta.20
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/README.md +125 -62
- package/manifest.schema.json +208 -11
- package/package.json +6 -4
- package/src/assets.d.ts +2 -2
- package/src/build/build.ts +121 -51
- package/src/build/cli.ts +29 -22
- package/src/build/elf.ts +8 -7
- package/src/build/hashes.ts +82 -20
- package/src/build/project.ts +95 -28
- package/src/builder/pipeline.ts +344 -88
- package/src/builder/refs.ts +15 -5
- package/src/core/brands.ts +7 -5
- package/src/core/config-refs.ts +103 -0
- package/src/core/config.ts +224 -0
- package/src/core/external.ts +86 -0
- package/src/core/handlers.ts +61 -15
- package/src/core/models.ts +32 -15
- package/src/core/origin.ts +23 -0
- package/src/core/secrets.ts +2 -2
- package/src/core/steps.ts +89 -38
- package/src/core/types.ts +5 -1
- package/src/core/webhooks.ts +21 -7
- package/src/ctx/files.ts +111 -40
- package/src/ctx/index.ts +84 -31
- package/src/ctx/sh.ts +105 -44
- package/src/ctx/types.ts +12 -4
- package/src/describe/describe.ts +701 -133
- package/src/describe/manifest-schema.ts +258 -61
- package/src/describe/mapper-source.ts +249 -104
- package/src/describe/record.ts +67 -37
- package/src/dev/cli.ts +72 -35
- package/src/harness/env.ts +45 -25
- package/src/harness/execute.ts +58 -29
- package/src/harness/index.ts +22 -9
- package/src/harness/main.ts +239 -78
- package/src/harness/result.ts +38 -22
- package/src/harness/validate.ts +77 -15
- package/src/index.ts +124 -11
- package/src/library/checks.ts +28 -0
- package/src/library/compose-deploy.ts +113 -0
- package/src/library/github-source.ts +100 -47
- package/src/library/helm-deploy-ssh.ts +452 -108
- package/src/library/helm-deploy.ts +449 -0
- package/src/library/http-health.ts +7 -5
- package/src/library/image-build.ts +499 -105
- package/src/library/index.ts +48 -12
- package/src/library/models.ts +33 -9
- package/src/library/ssh.ts +67 -0
- package/src/testing/index.ts +74 -36
- package/src/util/canonical.ts +7 -4
- package/src/util/handler-hash.ts +17 -7
- package/src/util/hash.ts +5 -5
- package/src/util/tar.ts +86 -36
- package/src/library/script.ts +0 -85
package/src/library/script.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import type { Ctx, RunInfo } from "../ctx/types.ts";
|
|
4
|
-
import type { AnyModel } from "../core/models.ts";
|
|
5
|
-
import type { Secret } from "../core/secrets.ts";
|
|
6
|
-
import { makeStep, type InputSpec, type LibraryStep, type Step, type StepDef, type StepInput } from "../core/steps.ts";
|
|
7
|
-
import { sha256Hex } from "../util/hash.ts";
|
|
8
|
-
|
|
9
|
-
/** A config value that may depend on the run: a constant or a function of the step's inputs and run info. */
|
|
10
|
-
export type RunValue<I, T = string> = T | ((input: StepInput<I>, run: RunInfo) => T);
|
|
11
|
-
|
|
12
|
-
export interface ScriptDef<N extends string, I extends InputSpec, O extends AnyModel | null, Sec extends readonly Secret[]>
|
|
13
|
-
extends StepDef<N, I, O, Sec> {
|
|
14
|
-
/** An embedded script: `import s from "./scripts/x.sh" with { type: "file" }`. */
|
|
15
|
-
script: string;
|
|
16
|
-
/** Extra environment; values may be functions of the inputs (evaluated in the step, not at describe). */
|
|
17
|
-
env?: Record<string, RunValue<I>>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** `deployTo` → `INPUT_DEPLOY_TO`. */
|
|
21
|
-
export function inputEnvName(key: string): string {
|
|
22
|
-
return "INPUT_" + key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^A-Za-z0-9]+/g, "_").toUpperCase();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Runs a shell script (the zero-TypeScript path). Contract for the script:
|
|
27
|
-
* - `$OLVE_INPUT`: path of the validated input as JSON; each input key is also `INPUT_<KEY>`
|
|
28
|
-
* (strings raw, everything else JSON).
|
|
29
|
-
* - `$OLVE_OUTPUT`: if the step has an output model, write the output JSON there. Objects of the
|
|
30
|
-
* form `{"$file": "<path>"}` / `{"$dir": "<path>"}` are turned into file references.
|
|
31
|
-
* - Declared secrets are in the environment under their names.
|
|
32
|
-
*/
|
|
33
|
-
export function script<
|
|
34
|
-
const N extends string,
|
|
35
|
-
const I extends InputSpec = {},
|
|
36
|
-
O extends AnyModel | null = null,
|
|
37
|
-
const Sec extends readonly Secret[] = [],
|
|
38
|
-
>(def: ScriptDef<N, I, O, Sec>): Step<N, I, O, Sec[number]["name"]> & LibraryStep {
|
|
39
|
-
const env = def.env ?? {};
|
|
40
|
-
return makeStep("script", def as never, {
|
|
41
|
-
manifestConfig: () => ({
|
|
42
|
-
scriptSha256: "sha256:" + sha256Hex(readFileSync(def.script)),
|
|
43
|
-
env: Object.fromEntries(Object.entries(env).filter(([, v]) => typeof v === "string")),
|
|
44
|
-
computedEnv: Object.keys(env).filter((k) => typeof env[k] === "function").sort(),
|
|
45
|
-
}),
|
|
46
|
-
async run(input: Record<string, unknown>, ctx: Ctx) {
|
|
47
|
-
mkdirSync(ctx.tmpDir, { recursive: true });
|
|
48
|
-
const dir = mkdtempSync(join(ctx.tmpDir, "script-"));
|
|
49
|
-
const inputPath = join(dir, "input.json");
|
|
50
|
-
const outputPath = join(dir, "output.json");
|
|
51
|
-
writeFileSync(inputPath, JSON.stringify(input));
|
|
52
|
-
const vars: Record<string, string> = { OLVE_INPUT: inputPath };
|
|
53
|
-
for (const [k, v] of Object.entries(input)) {
|
|
54
|
-
if (v !== undefined) vars[inputEnvName(k)] = typeof v === "string" ? v : JSON.stringify(v);
|
|
55
|
-
}
|
|
56
|
-
for (const [k, v] of Object.entries(env)) {
|
|
57
|
-
vars[k] = typeof v === "function" ? (v as (i: unknown, r: RunInfo) => string)(input, ctx.run) : v;
|
|
58
|
-
}
|
|
59
|
-
if (def.output) vars.OLVE_OUTPUT = outputPath;
|
|
60
|
-
await ctx.sh({ script: def.script }, { env: vars });
|
|
61
|
-
if (!def.output) return undefined;
|
|
62
|
-
let raw: unknown;
|
|
63
|
-
try {
|
|
64
|
-
raw = JSON.parse(readFileSync(outputPath, "utf8"));
|
|
65
|
-
} catch (e) {
|
|
66
|
-
throw new Error(`script did not write valid JSON to $OLVE_OUTPUT: ${(e as Error).message}`);
|
|
67
|
-
}
|
|
68
|
-
return resolveFilePlaceholders(raw, ctx);
|
|
69
|
-
},
|
|
70
|
-
}) as never;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async function resolveFilePlaceholders(v: unknown, ctx: Ctx): Promise<unknown> {
|
|
74
|
-
if (Array.isArray(v)) return Promise.all(v.map((x) => resolveFilePlaceholders(x, ctx)));
|
|
75
|
-
if (typeof v === "object" && v !== null) {
|
|
76
|
-
const o = v as Record<string, unknown>;
|
|
77
|
-
const keys = Object.keys(o);
|
|
78
|
-
if (keys.length === 1 && typeof o.$file === "string") return ctx.output.file(o.$file);
|
|
79
|
-
if (keys.length === 1 && typeof o.$dir === "string") return ctx.output.dir(o.$dir);
|
|
80
|
-
const out: Record<string, unknown> = {};
|
|
81
|
-
for (const k of keys) out[k] = await resolveFilePlaceholders(o[k], ctx);
|
|
82
|
-
return out;
|
|
83
|
-
}
|
|
84
|
-
return v;
|
|
85
|
-
}
|