@olivervea/pipelines 2.0.0-beta.1 → 2.0.0-beta.11
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 +122 -62
- package/manifest.schema.json +161 -11
- package/package.json +2 -2
- package/src/build/build.ts +19 -17
- package/src/build/cli.ts +1 -1
- package/src/build/hashes.ts +32 -3
- package/src/build/project.ts +33 -5
- package/src/builder/pipeline.ts +92 -10
- package/src/core/brands.ts +2 -0
- package/src/core/config-refs.ts +77 -0
- package/src/core/config.ts +147 -0
- package/src/core/handlers.ts +16 -10
- package/src/core/origin.ts +20 -0
- package/src/core/steps.ts +53 -22
- package/src/core/webhooks.ts +30 -0
- package/src/ctx/index.ts +3 -0
- package/src/ctx/sh.ts +2 -1
- package/src/ctx/types.ts +4 -1
- package/src/describe/describe.ts +213 -27
- package/src/describe/manifest-schema.ts +53 -5
- package/src/dev/cli.ts +16 -9
- package/src/harness/execute.ts +7 -4
- package/src/harness/index.ts +1 -1
- package/src/harness/main.ts +68 -17
- package/src/harness/validate.ts +19 -1
- package/src/index.ts +7 -3
- package/src/library/checks.ts +23 -0
- package/src/library/compose-deploy.ts +96 -0
- package/src/library/github-source.ts +61 -38
- package/src/library/helm-deploy-ssh.ts +306 -99
- package/src/library/helm-deploy.ts +271 -0
- package/src/library/image-build.ts +350 -66
- package/src/library/index.ts +11 -7
- package/src/library/models.ts +17 -1
- package/src/library/ssh.ts +50 -0
- package/src/testing/index.ts +11 -15
- package/src/util/handler-hash.ts +4 -4
- package/src/util/tar.ts +13 -0
- package/src/library/script.ts +0 -85
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
// steps.helmDeployOverSsh —
|
|
2
|
-
//
|
|
1
|
+
// steps.helmDeployOverSsh — get built images onto a k3s host and helm-upgrade a release there, over
|
|
2
|
+
// SSH; optionally verify an HTTP health endpoint afterwards.
|
|
3
3
|
//
|
|
4
4
|
// Ported from v1's olve-lib.sh (olve_ssh_host, olve_image_import, olve_helm_deploy) and
|
|
5
5
|
// deploy-beta.sh (rollout wait + health loop); the footguns are kept as comments below.
|
|
6
|
-
import {
|
|
6
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import type { Ctx } from "../ctx/types.ts";
|
|
9
9
|
import type { FileRef } from "../core/models.ts";
|
|
10
10
|
import type { Secret } from "../core/secrets.ts";
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import type { Configurable } from "../core/config.ts";
|
|
12
|
+
import { resolveConfigRefs } from "../core/config-refs.ts";
|
|
13
|
+
import { implement, type Implementation } from "../core/handlers.ts";
|
|
14
|
+
import { step, type LiteralName, type Step } from "../core/steps.ts";
|
|
15
|
+
import type { Simplify } from "../core/types.ts";
|
|
16
|
+
import { httpHealthCheck, type HttpHealthCheckOptions } from "./http-health.ts";
|
|
17
|
+
import { BuiltImage, HelmRelease, PushedImage, Source } from "./models.ts";
|
|
18
|
+
import { shq, sshSession } from "./ssh.ts";
|
|
19
|
+
import { helmDeployOverSshTarget, type HelmDeploySshTargetDef, type HelmTargetDeployInput } from "./helm-deploy.ts";
|
|
14
20
|
|
|
15
21
|
/** Alpine: `apk add openssh-client` at run time gives ssh/scp (the health check runs in the harness). */
|
|
16
22
|
export const HELM_DEPLOY_IMAGE = "alpine:3.22";
|
|
@@ -20,132 +26,333 @@ export const HELM_DEPLOY_IMAGE = "alpine:3.22";
|
|
|
20
26
|
* the k3s instance's `k8s.io` namespace (otherwise pods fail with ErrImageNeverPull).
|
|
21
27
|
*/
|
|
22
28
|
export const K3S_IMAGE_IMPORT = "sudo nerdctl --address /run/k3s/containerd/containerd.sock --namespace k8s.io load";
|
|
29
|
+
/** Registry images are pulled the same way before the rollout, so the rollout doesn't wait on the pull. */
|
|
30
|
+
export const K3S_IMAGE_PULL = "sudo nerdctl --address /run/k3s/containerd/containerd.sock --namespace k8s.io pull -q";
|
|
23
31
|
|
|
24
|
-
const
|
|
32
|
+
export const DEFAULT_ROLLOUT_TIMEOUT_SECONDS = 120;
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
type DefaultImages = { readonly image: "image" };
|
|
35
|
+
type ImageModel<R extends boolean> = R extends true ? typeof PushedImage : typeof BuiltImage;
|
|
36
|
+
export type HelmDeployOverSshInput<
|
|
37
|
+
Im extends Record<string, string> = DefaultImages,
|
|
38
|
+
R extends boolean = false,
|
|
39
|
+
Rf extends Record<string, string> = {},
|
|
40
|
+
> = Simplify<
|
|
41
|
+
{ readonly source: typeof Source } & { readonly [K in keyof Im]: ImageModel<R> } & { readonly [K in keyof Rf]: typeof PushedImage }
|
|
42
|
+
>;
|
|
28
43
|
|
|
29
|
-
export interface HelmDeployOverSshDef<
|
|
44
|
+
export interface HelmDeployOverSshDef<
|
|
45
|
+
N extends string,
|
|
46
|
+
K extends string,
|
|
47
|
+
Im extends Record<string, string> = DefaultImages,
|
|
48
|
+
R extends boolean = false,
|
|
49
|
+
Rf extends Record<string, string> = {},
|
|
50
|
+
> {
|
|
30
51
|
name: LiteralName<N>;
|
|
31
52
|
/** What the step does, shown in the UI. Required; may be empty. */
|
|
32
53
|
description: string;
|
|
33
54
|
/** SSH target, `user@host`. The user needs passwordless sudo for nerdctl, and helm/kubectl with a kubeconfig. */
|
|
34
|
-
host: string
|
|
55
|
+
host: Configurable<string>;
|
|
35
56
|
/** Private key for `host`. */
|
|
36
57
|
sshKey: Secret<K>;
|
|
37
|
-
/** Helm release name
|
|
38
|
-
release: string
|
|
39
|
-
namespace: string
|
|
58
|
+
/** Helm release name. */
|
|
59
|
+
release: Configurable<string>;
|
|
60
|
+
namespace: Configurable<string>;
|
|
40
61
|
/** Chart directory inside the source tree, e.g. `helm`. */
|
|
41
62
|
chart: string;
|
|
42
63
|
/** Values files, relative to the chart directory (`-f`, in order). */
|
|
43
|
-
values?: readonly string[]
|
|
64
|
+
values?: Configurable<readonly string[]>;
|
|
44
65
|
/**
|
|
45
|
-
* Chart-specific `--set` flags (e.g. `{ "
|
|
46
|
-
* the step and always win:
|
|
66
|
+
* Chart-specific `--set` flags (e.g. `{ "ingress.enabled": "false" }`). The image flags are added by
|
|
67
|
+
* the step and always win: `<prefix>.repository`, `<prefix>.tag`, `<prefix>.pullPolicy`.
|
|
47
68
|
*/
|
|
48
|
-
set?: Readonly<Record<string, string
|
|
49
|
-
/**
|
|
50
|
-
|
|
69
|
+
set?: Configurable<Readonly<Record<string, string>>>;
|
|
70
|
+
/**
|
|
71
|
+
* The images to deploy: step input key → the chart's values prefix for that image. Each input is a
|
|
72
|
+
* `BuiltImage` (or `PushedImage` with `fromRegistry`). Default `{ image: "image" }`; several images
|
|
73
|
+
* need a mapper, e.g. `{ server: "image", web: "web.image" }`. `{}` deploys the chart alone.
|
|
74
|
+
*/
|
|
75
|
+
images?: Im & { readonly source?: never };
|
|
76
|
+
/**
|
|
77
|
+
* The images are `PushedImage`s from a registry (`imageBuild` with `push`): pulled on the host
|
|
78
|
+
* first, then `pullPolicy=IfNotPresent`. Default: `BuiltImage` tarballs, imported on the host, then
|
|
79
|
+
* `pullPolicy=Never`.
|
|
80
|
+
*/
|
|
81
|
+
fromRegistry?: R & (boolean extends R ? "❌ fromRegistry must be a literal true or false (use `as const` on a shared config object)" : unknown);
|
|
82
|
+
/**
|
|
83
|
+
* Registry images the chart only references (not run by the release's own pods, e.g. an image the
|
|
84
|
+
* app starts Jobs with): step input key → values prefix. Each input is a `PushedImage`; the step sets
|
|
85
|
+
* `<prefix>.repository`, `<prefix>.tag` and `<prefix>.digest` and does not pull it on the host. Works
|
|
86
|
+
* next to tarball `images`.
|
|
87
|
+
*/
|
|
88
|
+
imageRefs?: Rf & { readonly source?: never };
|
|
89
|
+
/** Rollouts to wait for, in order: `deploy/<name>` for a bare name. Default: the release name, or none without images or with helm's wait. */
|
|
90
|
+
deployments?: readonly string[];
|
|
91
|
+
/** Per rollout (`kubectl rollout status --timeout`), or for helm's own wait. Default 120. */
|
|
92
|
+
rolloutTimeoutSeconds?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Pull the dependencies `Chart.yaml` lists (`charts/` is usually not committed) into the chart on the
|
|
95
|
+
* host before installing: `helm pull <name> --repo <repository> --version <version>`, or the `oci://`
|
|
96
|
+
* reference. Default false.
|
|
97
|
+
*/
|
|
98
|
+
dependencies?: boolean;
|
|
99
|
+
/** `helm upgrade --wait`: helm waits for all of the release's resources to be ready. Default false. */
|
|
100
|
+
helmWait?: boolean;
|
|
101
|
+
/** `helm upgrade --atomic`: wait like `helmWait`, and roll back when the upgrade fails. Default false. */
|
|
102
|
+
atomic?: boolean;
|
|
103
|
+
/** After the rollouts, GET this URL until it returns 2xx (`httpHealthCheck`: 5 × 5 s unless given), or fail the step. */
|
|
104
|
+
healthUrl?: Configurable<string> | ({ url: Configurable<string> } & Pick<HttpHealthCheckOptions, "attempts" | "delaySeconds">);
|
|
51
105
|
timeoutSeconds?: number;
|
|
52
106
|
}
|
|
53
107
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
108
|
+
export interface HelmImageFlags {
|
|
109
|
+
prefix: string;
|
|
110
|
+
repository: string;
|
|
111
|
+
tag: string;
|
|
112
|
+
pullPolicy: "Never" | "IfNotPresent";
|
|
113
|
+
/** Pins the image: `<prefix>.digest` (the chart renders `repository:tag@digest`). */
|
|
114
|
+
digest?: string;
|
|
58
115
|
}
|
|
59
116
|
|
|
60
|
-
/**
|
|
61
|
-
export
|
|
62
|
-
|
|
63
|
-
release: string;
|
|
64
|
-
namespace: string;
|
|
65
|
-
values: readonly string[];
|
|
66
|
-
set: Readonly<Record<string, string>>;
|
|
117
|
+
/** A registry image the chart only references (`imageRefs`). */
|
|
118
|
+
export interface HelmImageRefFlags {
|
|
119
|
+
prefix: string;
|
|
67
120
|
repository: string;
|
|
68
121
|
tag: string;
|
|
69
|
-
|
|
122
|
+
digest: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface HelmFlagOptions {
|
|
126
|
+
values: readonly string[];
|
|
127
|
+
set: Readonly<Record<string, string>>;
|
|
128
|
+
images: readonly HelmImageFlags[];
|
|
129
|
+
imageRefs?: readonly HelmImageRefFlags[];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** `helm upgrade` flags: values files, `--set`, then the image flags (which win). */
|
|
133
|
+
export function helmFlags(o: HelmFlagOptions): string[] {
|
|
70
134
|
// Chart-relative values paths (`-f values-beta.yaml`) resolve because helm runs from inside the
|
|
71
|
-
// copied chart dir. Extra flags come before the image flags, so the image overrides win.
|
|
72
|
-
//
|
|
135
|
+
// copied chart dir. Extra flags come before the image flags, so the image overrides win.
|
|
136
|
+
// --set-string: a tag like `2026.10` or `1e5` would otherwise be parsed as a number.
|
|
73
137
|
const flags = [
|
|
74
138
|
...o.values.flatMap((v) => ["-f", v]),
|
|
75
139
|
...Object.entries(o.set).flatMap(([k, v]) => ["--set", `${k}=${v}`]),
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
140
|
+
...o.images.flatMap((i) => [
|
|
141
|
+
"--set", `${i.prefix}.repository=${i.repository}`,
|
|
142
|
+
"--set", `${i.prefix}.tag=${i.tag}`,
|
|
143
|
+
"--set", `${i.prefix}.pullPolicy=${i.pullPolicy}`,
|
|
144
|
+
...(i.digest ? ["--set-string", `${i.prefix}.digest=${i.digest}`] : []),
|
|
145
|
+
]),
|
|
146
|
+
...(o.imageRefs ?? []).flatMap((i) => [
|
|
147
|
+
"--set-string", `${i.prefix}.repository=${i.repository}`,
|
|
148
|
+
"--set-string", `${i.prefix}.tag=${i.tag}`,
|
|
149
|
+
"--set-string", `${i.prefix}.digest=${i.digest}`,
|
|
150
|
+
]),
|
|
79
151
|
];
|
|
152
|
+
return flags;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Remote `helm upgrade --install`, run from inside the copied chart directory. */
|
|
156
|
+
export function helmUpgradeCommand(o: HelmFlagOptions & { remoteChart: string; release: string; namespace: string; wait?: HelmWait }): string {
|
|
157
|
+
const flags = helmFlags(o);
|
|
158
|
+
const wait = o.wait ? [o.wait.atomic ? "--atomic" : "--wait", `--timeout=${o.wait.timeoutSeconds}s`] : [];
|
|
80
159
|
return [
|
|
81
160
|
`cd ${shq(o.remoteChart)}`,
|
|
82
|
-
["helm", "upgrade", "--install", o.release, ".", "-n", o.namespace, ...flags].map(shq).join(" "),
|
|
161
|
+
["helm", "upgrade", "--install", o.release, ".", "-n", o.namespace, ...flags, ...wait].map(shq).join(" "),
|
|
83
162
|
`cd / && rm -rf ${shq(o.remoteChart)}`,
|
|
84
163
|
].join(" && ");
|
|
85
164
|
}
|
|
86
165
|
|
|
166
|
+
/** helm's own wait (`--wait`, or `--atomic` to roll back on failure). */
|
|
167
|
+
export interface HelmWait {
|
|
168
|
+
atomic: boolean;
|
|
169
|
+
timeoutSeconds: number;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** A dependency from `Chart.yaml`. */
|
|
173
|
+
export interface ChartDependency {
|
|
174
|
+
name: string;
|
|
175
|
+
version: string;
|
|
176
|
+
repository: string;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The dependencies `<chartDir>/Chart.yaml` lists, checked to be pullable (an http(s) or oci repository). */
|
|
180
|
+
export function chartDependencies(chartDir: string): ChartDependency[] {
|
|
181
|
+
const chart = Bun.YAML.parse(readFileSync(join(chartDir, "Chart.yaml"), "utf8")) as { dependencies?: Partial<ChartDependency>[] } | null;
|
|
182
|
+
return (chart?.dependencies ?? []).map((d) => {
|
|
183
|
+
if (!d.name || !d.version || !d.repository || !/^(https?|oci):\/\//.test(d.repository))
|
|
184
|
+
throw new Error(`chart dependency ${JSON.stringify(d)}: needs a name, a version and an http(s) or oci repository`);
|
|
185
|
+
return { name: d.name, version: d.version, repository: d.repository };
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The remote `helm pull` of a dependency into `<remoteChart>/charts`. */
|
|
190
|
+
export function helmPullCommand(dep: ChartDependency, remoteChart: string): string {
|
|
191
|
+
const ref = dep.repository.startsWith("oci://") ? [`${dep.repository.replace(/\/+$/, "")}/${dep.name}`] : [dep.name, "--repo", dep.repository];
|
|
192
|
+
return ["helm", "pull", ...ref, "--version", dep.version, "--destination", `${remoteChart}/charts`].map(shq).join(" ");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** One image to get onto the host before the upgrade. */
|
|
196
|
+
export interface HostImage {
|
|
197
|
+
repository: string;
|
|
198
|
+
tag: string;
|
|
199
|
+
digest?: string;
|
|
200
|
+
/** An image tarball to stream in; without one the image is pulled from its registry. */
|
|
201
|
+
tar?: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
87
204
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* wait for `deploy/<release>` to roll out, then (with `healthUrl`) poll the health endpoint.
|
|
205
|
+
* Over SSH: get each image into the host's k3s containerd, copy the chart (with any generated values
|
|
206
|
+
* files in it), `helm upgrade --install`, then wait for each rollout.
|
|
91
207
|
*/
|
|
92
|
-
export function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
208
|
+
export async function deployOverSsh(
|
|
209
|
+
ctx: Ctx,
|
|
210
|
+
o: {
|
|
211
|
+
host: string;
|
|
212
|
+
key: string;
|
|
213
|
+
chartDir: string;
|
|
214
|
+
release: string;
|
|
215
|
+
namespace: string;
|
|
216
|
+
hostImages: readonly HostImage[];
|
|
217
|
+
flags: HelmFlagOptions;
|
|
218
|
+
deployments: readonly string[];
|
|
219
|
+
rolloutTimeoutSeconds: number;
|
|
220
|
+
dependencies?: readonly ChartDependency[];
|
|
221
|
+
wait?: HelmWait;
|
|
222
|
+
},
|
|
223
|
+
): Promise<void> {
|
|
224
|
+
const ssh = await sshSession(ctx, { host: o.host, key: o.key });
|
|
225
|
+
for (const image of o.hostImages) {
|
|
226
|
+
if (image.tar) {
|
|
227
|
+
ctx.log("importing image", { image: `${image.repository}:${image.tag}`, host: o.host });
|
|
228
|
+
// Streamed over ssh's stdin (ctx.exec has none, hence the shell redirect).
|
|
229
|
+
await ctx.sh(`${ssh.shell(K3S_IMAGE_IMPORT)} < ${shq(image.tar)}`);
|
|
230
|
+
} else {
|
|
231
|
+
const ref = image.digest ? `${image.repository}@${image.digest}` : `${image.repository}:${image.tag}`;
|
|
232
|
+
ctx.log("pulling image", { image: ref, host: o.host });
|
|
233
|
+
await ssh.run(`${K3S_IMAGE_PULL} ${shq(ref)}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const remoteChart = `/tmp/${o.release}-helm-${o.namespace}`;
|
|
237
|
+
ctx.log("helm upgrade", { release: o.release, namespace: o.namespace, host: o.host });
|
|
238
|
+
await ssh.run(`rm -rf ${shq(remoteChart)}`);
|
|
239
|
+
await ssh.copy(o.chartDir, remoteChart);
|
|
240
|
+
if (o.dependencies?.length) await ssh.run(`mkdir -p ${shq(`${remoteChart}/charts`)}`);
|
|
241
|
+
for (const dep of o.dependencies ?? []) {
|
|
242
|
+
ctx.log("pulling chart dependency", { chart: `${dep.name}@${dep.version}`, repository: dep.repository });
|
|
243
|
+
await ssh.run(helmPullCommand(dep, remoteChart));
|
|
244
|
+
}
|
|
245
|
+
await ssh.run(helmUpgradeCommand({ ...o.flags, remoteChart, release: o.release, namespace: o.namespace, ...(o.wait ? { wait: o.wait } : {}) }));
|
|
246
|
+
for (const d of o.deployments) {
|
|
247
|
+
const target = d.includes("/") ? d : `deploy/${d}`;
|
|
248
|
+
ctx.log("waiting for rollout", { deployment: target });
|
|
249
|
+
await ssh.run(`kubectl -n ${shq(o.namespace)} rollout status ${shq(target)} --timeout=${o.rolloutTimeoutSeconds}s`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** The chart directory inside a fetched source tree, or an error naming it. */
|
|
254
|
+
export function chartDirectory(tree: string, chart: string): string {
|
|
255
|
+
const dir = join(tree, chart);
|
|
256
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory()) throw new Error(`chart directory '${chart}' not found in the source tree`);
|
|
257
|
+
return dir;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Deploys images with the Helm chart at `<source>/<chart>` on a k3s host over SSH: get each image
|
|
262
|
+
* into the host's k3s containerd (stream a tarball in, or pull from the registry), copy the chart,
|
|
263
|
+
* `helm upgrade --install`, wait for each rollout, then (with `healthUrl`) poll the health endpoint.
|
|
264
|
+
*/
|
|
265
|
+
export function helmDeployOverSsh<
|
|
266
|
+
const N extends string,
|
|
267
|
+
const K extends string,
|
|
268
|
+
const Im extends Record<string, string> = DefaultImages,
|
|
269
|
+
const Rf extends Record<string, string> = {},
|
|
270
|
+
>(def: HelmDeploySshTargetDef<N, K, Im, Rf>): Implementation<Step<N, HelmTargetDeployInput<Im, Rf>, typeof HelmRelease, K>>;
|
|
271
|
+
export function helmDeployOverSsh<
|
|
272
|
+
const N extends string,
|
|
273
|
+
const K extends string,
|
|
274
|
+
const Im extends Record<string, string> = DefaultImages,
|
|
275
|
+
const R extends boolean = false,
|
|
276
|
+
const Rf extends Record<string, string> = {},
|
|
277
|
+
>(def: HelmDeployOverSshDef<N, K, Im, R, Rf>): Implementation<Step<N, HelmDeployOverSshInput<Im, R, Rf>, typeof HelmRelease, K>>;
|
|
278
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
279
|
+
export function helmDeployOverSsh(def: any): any {
|
|
280
|
+
return "target" in def ? helmDeployOverSshTarget(def) : helmDeployOverSshLiteral(def);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
284
|
+
function helmDeployOverSshLiteral(def: HelmDeployOverSshDef<string, string, any, boolean, any>): Implementation {
|
|
285
|
+
const images: Record<string, string> = def.images ?? { image: "image" };
|
|
286
|
+
const imageEntries = Object.entries(images);
|
|
287
|
+
const fromRegistry = def.fromRegistry === true;
|
|
288
|
+
const rolloutTimeout = def.rolloutTimeoutSeconds ?? DEFAULT_ROLLOUT_TIMEOUT_SECONDS;
|
|
289
|
+
const wait: HelmWait | undefined = def.atomic || def.helmWait ? { atomic: def.atomic === true, timeoutSeconds: rolloutTimeout } : undefined;
|
|
290
|
+
if ("source" in images) throw new Error(`helmDeployOverSsh '${def.name}': 'source' can't be an image input`);
|
|
291
|
+
if (def.deployments?.length === 0) throw new Error(`helmDeployOverSsh '${def.name}': deployments must not be empty`);
|
|
292
|
+
const imageRefs: Record<string, string> = def.imageRefs ?? {};
|
|
293
|
+
const refEntries = Object.entries(imageRefs);
|
|
294
|
+
if ("source" in imageRefs) throw new Error(`helmDeployOverSsh '${def.name}': 'source' can't be an image input`);
|
|
295
|
+
for (const [key] of refEntries) if (key in images) throw new Error(`helmDeployOverSsh '${def.name}': '${key}' is both in images and imageRefs`);
|
|
296
|
+
const imageModel = fromRegistry ? PushedImage : BuiltImage;
|
|
297
|
+
const input = {
|
|
298
|
+
source: Source,
|
|
299
|
+
...Object.fromEntries(imageEntries.map(([key]) => [key, imageModel])),
|
|
300
|
+
...Object.fromEntries(refEntries.map(([key]) => [key, PushedImage])),
|
|
301
|
+
};
|
|
302
|
+
const isDefaultImages = imageEntries.length === 1 && images.image === "image";
|
|
303
|
+
const configurable = { host: def.host, release: def.release, namespace: def.namespace, values: def.values ?? [], set: def.set ?? {}, healthUrl: def.healthUrl };
|
|
304
|
+
|
|
305
|
+
const contract = step({
|
|
306
|
+
name: def.name,
|
|
307
|
+
description: def.description,
|
|
308
|
+
kind: "helmDeployOverSsh",
|
|
309
|
+
image: HELM_DEPLOY_IMAGE,
|
|
310
|
+
input,
|
|
311
|
+
output: HelmRelease,
|
|
312
|
+
secrets: [def.sshKey],
|
|
313
|
+
timeoutSeconds: def.timeoutSeconds,
|
|
314
|
+
settings: {
|
|
315
|
+
host: def.host,
|
|
316
|
+
sshKey: def.sshKey.name,
|
|
317
|
+
release: def.release,
|
|
318
|
+
namespace: def.namespace,
|
|
319
|
+
chart: def.chart,
|
|
320
|
+
values: configurable.values,
|
|
321
|
+
set: configurable.set,
|
|
322
|
+
...(isDefaultImages ? {} : { images: { ...images } }),
|
|
323
|
+
...(fromRegistry ? { fromRegistry: true } : {}),
|
|
324
|
+
...(refEntries.length > 0 ? { imageRefs: { ...imageRefs } } : {}),
|
|
325
|
+
...(def.deployments ? { deployments: [...def.deployments] } : {}),
|
|
326
|
+
...(def.rolloutTimeoutSeconds !== undefined ? { rolloutTimeoutSeconds: def.rolloutTimeoutSeconds } : {}),
|
|
327
|
+
...(def.dependencies ? { dependencies: true } : {}),
|
|
328
|
+
...(def.atomic ? { atomic: true } : def.helmWait ? { helmWait: true } : {}),
|
|
329
|
+
...(def.healthUrl !== undefined ? { healthUrl: def.healthUrl } : {}),
|
|
149
330
|
},
|
|
150
|
-
)
|
|
331
|
+
});
|
|
332
|
+
return implement(contract, async (stepInput, ctx: Ctx) => {
|
|
333
|
+
const input = stepInput as unknown as Record<string, { repository: string; tag: string; digest: string; tar?: FileRef }> & { source: { tree: FileRef } };
|
|
334
|
+
const d = resolveConfigRefs(configurable, ctx.config ?? {}) as {
|
|
335
|
+
host: string; release: string; namespace: string; values: string[]; set: Record<string, string>;
|
|
336
|
+
healthUrl?: string | ({ url: string } & Pick<HttpHealthCheckOptions, "attempts" | "delaySeconds">);
|
|
337
|
+
};
|
|
338
|
+
const chartDir = chartDirectory(await ctx.files.fetch(input.source.tree), def.chart);
|
|
339
|
+
const hostImages: HostImage[] = [];
|
|
340
|
+
const flags: HelmImageFlags[] = [];
|
|
341
|
+
for (const [key, prefix] of imageEntries) {
|
|
342
|
+
const image = input[key]!;
|
|
343
|
+
hostImages.push({ repository: image.repository, tag: image.tag, ...(fromRegistry ? {} : { tar: await ctx.files.fetch(image.tar!) }) });
|
|
344
|
+
flags.push({ prefix, repository: image.repository, tag: image.tag, pullPolicy: fromRegistry ? "IfNotPresent" : "Never" });
|
|
345
|
+
}
|
|
346
|
+
const refs: HelmImageRefFlags[] = refEntries.map(([key, prefix]) => ({ prefix, repository: input[key]!.repository, tag: input[key]!.tag, digest: input[key]!.digest }));
|
|
347
|
+
await deployOverSsh(ctx, {
|
|
348
|
+
host: d.host, key: ctx.secrets[def.sshKey.name]!, chartDir, release: d.release, namespace: d.namespace, hostImages,
|
|
349
|
+
flags: { values: d.values, set: d.set, images: flags, imageRefs: refs },
|
|
350
|
+
deployments: def.deployments ?? (imageEntries.length && !wait ? [d.release] : []), rolloutTimeoutSeconds: rolloutTimeout,
|
|
351
|
+
...(def.dependencies ? { dependencies: chartDependencies(chartDir) } : {}),
|
|
352
|
+
...(wait ? { wait } : {}),
|
|
353
|
+
});
|
|
354
|
+
const health = typeof d.healthUrl === "string" ? { url: d.healthUrl } : d.healthUrl;
|
|
355
|
+
if (health) await httpHealthCheck(ctx, health.url, { attempts: health.attempts, delaySeconds: health.delaySeconds });
|
|
356
|
+
return { release: d.release, namespace: d.namespace, ...(flags[0] ? { image: `${flags[0].repository}:${flags[0].tag}` } : {}) };
|
|
357
|
+
}) as never;
|
|
151
358
|
}
|