@highstate/k8s 0.9.3 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-DQSCJM5S.js +183 -0
- package/dist/chunk-DQSCJM5S.js.map +1 -0
- package/dist/chunk-FKNHHKOL.js +260 -0
- package/dist/chunk-FKNHHKOL.js.map +1 -0
- package/dist/chunk-HW3NS3MC.js +347 -0
- package/dist/chunk-HW3NS3MC.js.map +1 -0
- package/dist/chunk-OQ7UXASD.js +193 -0
- package/dist/chunk-OQ7UXASD.js.map +1 -0
- package/dist/chunk-QGHMLKTW.js +1123 -0
- package/dist/chunk-QGHMLKTW.js.map +1 -0
- package/dist/chunk-UNVSWG6D.js +214 -0
- package/dist/chunk-UNVSWG6D.js.map +1 -0
- package/dist/deployment-ZP3ASKPT.js +10 -0
- package/dist/deployment-ZP3ASKPT.js.map +1 -0
- package/dist/highstate.manifest.json +8 -6
- package/dist/index.js +291 -954
- package/dist/index.js.map +1 -1
- package/dist/stateful-set-2AH7RAF7.js +10 -0
- package/dist/stateful-set-2AH7RAF7.js.map +1 -0
- package/dist/units/access-point/index.js +6 -1
- package/dist/units/access-point/index.js.map +1 -1
- package/dist/units/cert-manager/index.js +19 -24
- package/dist/units/cert-manager/index.js.map +1 -1
- package/dist/units/cluster-dns/index.js +36 -0
- package/dist/units/cluster-dns/index.js.map +1 -0
- package/dist/units/cluster-patch/index.js +34 -0
- package/dist/units/cluster-patch/index.js.map +1 -0
- package/dist/units/dns01-issuer/index.js +2 -2
- package/dist/units/dns01-issuer/index.js.map +1 -1
- package/dist/units/existing-cluster/index.js +23 -15
- package/dist/units/existing-cluster/index.js.map +1 -1
- package/dist/units/gateway-api/index.js +1 -1
- package/package.json +12 -10
- package/src/access-point.ts +44 -39
- package/src/container.ts +54 -5
- package/src/cron-job.ts +14 -30
- package/src/deployment.ts +170 -127
- package/src/gateway/http-route.ts +7 -5
- package/src/helm.ts +57 -8
- package/src/index.ts +11 -4
- package/src/job.ts +14 -32
- package/src/namespace.ts +241 -0
- package/src/network-policy.ts +371 -87
- package/src/network.ts +41 -0
- package/src/pvc.ts +43 -25
- package/src/scripting/bundle.ts +125 -22
- package/src/scripting/container.ts +16 -11
- package/src/scripting/environment.ts +56 -6
- package/src/secret.ts +195 -0
- package/src/service.ts +209 -89
- package/src/shared.ts +42 -51
- package/src/stateful-set.ts +193 -88
- package/src/units/access-point/index.ts +8 -1
- package/src/units/cert-manager/index.ts +15 -20
- package/src/units/cluster-dns/index.ts +37 -0
- package/src/units/cluster-patch/index.ts +35 -0
- package/src/units/dns01-issuer/index.ts +1 -1
- package/src/units/existing-cluster/index.ts +26 -15
- package/src/workload.ts +342 -44
- package/dist/chunk-K4WKJ4L5.js +0 -455
- package/dist/chunk-K4WKJ4L5.js.map +0 -1
- package/dist/chunk-T5Z2M4JE.js +0 -103
- package/dist/chunk-T5Z2M4JE.js.map +0 -1
package/src/pvc.ts
CHANGED
@@ -13,9 +13,9 @@ import { deepmerge } from "deepmerge-ts"
|
|
13
13
|
import { omit } from "remeda"
|
14
14
|
import {
|
15
15
|
commonExtraArgs,
|
16
|
+
getProvider,
|
16
17
|
mapMetadata,
|
17
18
|
resourceIdToString,
|
18
|
-
verifyProvider,
|
19
19
|
type CommonArgs,
|
20
20
|
type ResourceId,
|
21
21
|
} from "./shared"
|
@@ -28,14 +28,13 @@ export type PersistentVolumeClaimArgs = CommonArgs &
|
|
28
28
|
* By default, the size is set to "100Mi".
|
29
29
|
*/
|
30
30
|
size?: string
|
31
|
-
|
32
|
-
/**
|
33
|
-
* The cluster to create the resource in.
|
34
|
-
*/
|
35
|
-
cluster: Input<k8s.Cluster>
|
36
31
|
}
|
37
32
|
|
38
|
-
|
33
|
+
export type CreateOrGetPersistentVolumeClaimArgs = PersistentVolumeClaimArgs & {
|
34
|
+
existing: Input<k8s.PersistentVolumeClaim> | undefined
|
35
|
+
}
|
36
|
+
|
37
|
+
const extraPersistentVolumeClaimArgs = [...commonExtraArgs, "size"] as const
|
39
38
|
|
40
39
|
export abstract class PersistentVolumeClaim extends ComponentResource {
|
41
40
|
protected constructor(
|
@@ -45,22 +44,22 @@ export abstract class PersistentVolumeClaim extends ComponentResource {
|
|
45
44
|
opts: ComponentResourceOptions,
|
46
45
|
|
47
46
|
/**
|
48
|
-
* The cluster
|
47
|
+
* The cluster where the PVC is created.
|
49
48
|
*/
|
50
|
-
readonly
|
49
|
+
readonly cluster: Output<k8s.Cluster>,
|
51
50
|
|
52
51
|
/**
|
53
|
-
* The metadata of the underlying Kubernetes
|
52
|
+
* The metadata of the underlying Kubernetes PVC.
|
54
53
|
*/
|
55
54
|
readonly metadata: Output<types.output.meta.v1.ObjectMeta>,
|
56
55
|
|
57
56
|
/**
|
58
|
-
* The spec of the underlying Kubernetes
|
57
|
+
* The spec of the underlying Kubernetes PVC.
|
59
58
|
*/
|
60
59
|
readonly spec: Output<types.output.core.v1.PersistentVolumeClaimSpec>,
|
61
60
|
|
62
61
|
/**
|
63
|
-
* The status of the underlying Kubernetes
|
62
|
+
* The status of the underlying Kubernetes PVC.
|
64
63
|
*/
|
65
64
|
readonly status: Output<types.output.core.v1.PersistentVolumeClaimStatus>,
|
66
65
|
) {
|
@@ -68,12 +67,12 @@ export abstract class PersistentVolumeClaim extends ComponentResource {
|
|
68
67
|
}
|
69
68
|
|
70
69
|
/**
|
71
|
-
* The Highstate
|
70
|
+
* The Highstate PVC entity.
|
72
71
|
*/
|
73
72
|
get entity(): Output<k8s.PersistentVolumeClaim> {
|
74
73
|
return output({
|
75
74
|
type: "k8s.persistent-volume-claim",
|
76
|
-
|
75
|
+
clusterId: this.cluster.id,
|
77
76
|
metadata: this.metadata,
|
78
77
|
})
|
79
78
|
}
|
@@ -89,12 +88,25 @@ export abstract class PersistentVolumeClaim extends ComponentResource {
|
|
89
88
|
static of(
|
90
89
|
name: string,
|
91
90
|
entity: Input<k8s.PersistentVolumeClaim>,
|
91
|
+
cluster: Input<k8s.Cluster>,
|
92
|
+
opts: ComponentResourceOptions,
|
93
|
+
): PersistentVolumeClaim {
|
94
|
+
return new ExternalPersistentVolumeClaim(name, output(entity).metadata, cluster, opts)
|
95
|
+
}
|
96
|
+
|
97
|
+
static createOrGet(
|
98
|
+
name: string,
|
99
|
+
args: CreateOrGetPersistentVolumeClaimArgs,
|
92
100
|
opts: ComponentResourceOptions,
|
93
101
|
): PersistentVolumeClaim {
|
102
|
+
if (!args.existing) {
|
103
|
+
return new CreatedPersistentVolumeClaim(name, args, opts)
|
104
|
+
}
|
105
|
+
|
94
106
|
return new ExternalPersistentVolumeClaim(
|
95
107
|
name,
|
96
|
-
output(
|
97
|
-
|
108
|
+
output(args.existing).metadata,
|
109
|
+
args.cluster,
|
98
110
|
opts,
|
99
111
|
)
|
100
112
|
}
|
@@ -102,7 +114,7 @@ export abstract class PersistentVolumeClaim extends ComponentResource {
|
|
102
114
|
|
103
115
|
export class CreatedPersistentVolumeClaim extends PersistentVolumeClaim {
|
104
116
|
constructor(name: string, args: PersistentVolumeClaimArgs, opts: CustomResourceOptions) {
|
105
|
-
const pvc = output(args).apply(args => {
|
117
|
+
const pvc = output(args).apply(async args => {
|
106
118
|
return new core.v1.PersistentVolumeClaim(
|
107
119
|
name,
|
108
120
|
{
|
@@ -119,7 +131,11 @@ export class CreatedPersistentVolumeClaim extends PersistentVolumeClaim {
|
|
119
131
|
omit(args, extraPersistentVolumeClaimArgs),
|
120
132
|
),
|
121
133
|
},
|
122
|
-
|
134
|
+
{
|
135
|
+
...opts,
|
136
|
+
parent: this,
|
137
|
+
provider: await getProvider(args.cluster),
|
138
|
+
},
|
123
139
|
)
|
124
140
|
})
|
125
141
|
|
@@ -129,7 +145,7 @@ export class CreatedPersistentVolumeClaim extends PersistentVolumeClaim {
|
|
129
145
|
args,
|
130
146
|
opts,
|
131
147
|
|
132
|
-
output(args.cluster)
|
148
|
+
output(args.cluster),
|
133
149
|
pvc.metadata,
|
134
150
|
pvc.spec,
|
135
151
|
pvc.status,
|
@@ -141,27 +157,29 @@ export class ExternalPersistentVolumeClaim extends PersistentVolumeClaim {
|
|
141
157
|
constructor(
|
142
158
|
name: string,
|
143
159
|
id: Input<ResourceId>,
|
144
|
-
|
160
|
+
cluster: Input<k8s.Cluster>,
|
145
161
|
opts: ComponentResourceOptions,
|
146
162
|
) {
|
147
163
|
const pvc = output(id).apply(async id => {
|
148
|
-
await verifyProvider(opts.provider, this.clusterInfo)
|
149
|
-
|
150
164
|
return core.v1.PersistentVolumeClaim.get(
|
151
165
|
//
|
152
166
|
name,
|
153
167
|
resourceIdToString(id),
|
154
|
-
{
|
168
|
+
{
|
169
|
+
...opts,
|
170
|
+
parent: this,
|
171
|
+
provider: await getProvider(cluster),
|
172
|
+
},
|
155
173
|
)
|
156
174
|
})
|
157
175
|
|
158
176
|
super(
|
159
177
|
"highstate:k8s:ExternalPersistentVolumeClaim",
|
160
178
|
name,
|
161
|
-
{ id,
|
179
|
+
{ id, cluster },
|
162
180
|
opts,
|
163
181
|
|
164
|
-
output(
|
182
|
+
output(cluster),
|
165
183
|
pvc.metadata,
|
166
184
|
pvc.spec,
|
167
185
|
pvc.status,
|
package/src/scripting/bundle.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { ContainerEnvironment, ContainerVolumeMount, WorkloadVolume } from "../container"
|
2
|
+
import type { network } from "@highstate/library"
|
2
3
|
import { core } from "@pulumi/kubernetes"
|
3
4
|
import { apply, normalize, type InputArray } from "@highstate/pulumi"
|
4
5
|
import {
|
@@ -9,12 +10,16 @@ import {
|
|
9
10
|
type Output,
|
10
11
|
type Unwrap,
|
11
12
|
} from "@pulumi/pulumi"
|
12
|
-
import { pipe } from "remeda"
|
13
|
+
import { mapValues, omitBy, pipe } from "remeda"
|
13
14
|
import { deepmerge } from "deepmerge-ts"
|
15
|
+
import { readPackageJSON } from "pkg-types"
|
14
16
|
import { text, trimIndentation } from "@highstate/contract"
|
17
|
+
import { parseL34Endpoint } from "@highstate/common"
|
18
|
+
import { serializeFunction } from "@pulumi/pulumi/runtime/index.js"
|
15
19
|
import { mapMetadata, type CommonArgs } from "../shared"
|
16
20
|
import {
|
17
21
|
emptyScriptEnvironment,
|
22
|
+
functionScriptImages,
|
18
23
|
type ResolvedScriptEnvironment,
|
19
24
|
type ScriptDistribution,
|
20
25
|
type ScriptEnvironment,
|
@@ -58,11 +63,21 @@ export class ScriptBundle extends ComponentResource {
|
|
58
63
|
*/
|
59
64
|
readonly environment: Output<ContainerEnvironment>
|
60
65
|
|
66
|
+
/**
|
67
|
+
* The image to use for the scripts.
|
68
|
+
*/
|
69
|
+
readonly image: Output<string>
|
70
|
+
|
61
71
|
/**
|
62
72
|
* The distribution to use for the scripts.
|
63
73
|
*/
|
64
74
|
readonly distribution: ScriptDistribution
|
65
75
|
|
76
|
+
/**
|
77
|
+
* The list of endpoints that the script is allowed to access.
|
78
|
+
*/
|
79
|
+
readonly allowedEndpoints: Output<network.L34Endpoint[]>
|
80
|
+
|
66
81
|
constructor(name: string, args: ScriptBundleArgs, opts?: ComponentResourceOptions) {
|
67
82
|
super("highstate:k8s:ScriptBundle", name, args, opts)
|
68
83
|
|
@@ -72,9 +87,36 @@ export class ScriptBundle extends ComponentResource {
|
|
72
87
|
apply(args => deepmerge(emptyScriptEnvironment, ...args)),
|
73
88
|
) as Output<Unwrap<ResolvedScriptEnvironment>>
|
74
89
|
|
90
|
+
const hasFunctionScripts = scriptEnvironment.apply(scriptEnvironment => {
|
91
|
+
return Object.values(scriptEnvironment.files).some(file => typeof file === "function")
|
92
|
+
})
|
93
|
+
|
75
94
|
this.distribution = args.distribution
|
76
95
|
this.environment = scriptEnvironment.environment
|
77
96
|
|
97
|
+
this.image = hasFunctionScripts.apply(hasFunctionScripts =>
|
98
|
+
output(
|
99
|
+
hasFunctionScripts
|
100
|
+
? functionScriptImages[args.distribution]
|
101
|
+
: scriptEnvironment[args.distribution].image,
|
102
|
+
),
|
103
|
+
)
|
104
|
+
|
105
|
+
this.allowedEndpoints = output({ scriptEnvironment, hasFunctionScripts }).apply(
|
106
|
+
({ scriptEnvironment, hasFunctionScripts }) => {
|
107
|
+
const allowedEndpoints = [
|
108
|
+
...scriptEnvironment.allowedEndpoints,
|
109
|
+
...scriptEnvironment[args.distribution].allowedEndpoints,
|
110
|
+
]
|
111
|
+
|
112
|
+
if (hasFunctionScripts) {
|
113
|
+
allowedEndpoints.push("tcp://registry.npmjs.org:443")
|
114
|
+
}
|
115
|
+
|
116
|
+
return allowedEndpoints.map(parseL34Endpoint)
|
117
|
+
},
|
118
|
+
)
|
119
|
+
|
78
120
|
this.configMap = output({ scriptEnvironment, args }).apply(({ scriptEnvironment, args }) => {
|
79
121
|
return new core.v1.ConfigMap(
|
80
122
|
name,
|
@@ -86,27 +128,36 @@ export class ScriptBundle extends ComponentResource {
|
|
86
128
|
)
|
87
129
|
})
|
88
130
|
|
89
|
-
this.volumes = scriptEnvironment.volumes.apply(
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
configMap: {
|
131
|
+
this.volumes = output({ hasFunctionScripts, volumes: scriptEnvironment.volumes }).apply(
|
132
|
+
({ hasFunctionScripts, volumes }) => {
|
133
|
+
return [
|
134
|
+
...volumes,
|
135
|
+
{
|
96
136
|
name: this.configMap.metadata.name,
|
97
|
-
|
137
|
+
|
138
|
+
configMap: {
|
139
|
+
name: this.configMap.metadata.name,
|
140
|
+
defaultMode: 0o550, // read and execute permissions
|
141
|
+
},
|
98
142
|
},
|
99
|
-
|
100
|
-
|
101
|
-
|
143
|
+
...(hasFunctionScripts ? [{ name: "node-modules", emptyDir: {} }] : []),
|
144
|
+
]
|
145
|
+
},
|
146
|
+
)
|
102
147
|
|
103
|
-
this.volumeMounts =
|
148
|
+
this.volumeMounts = output({
|
149
|
+
hasFunctionScripts,
|
150
|
+
volumeMounts: scriptEnvironment.volumeMounts,
|
151
|
+
}).apply(({ hasFunctionScripts, volumeMounts }) => {
|
104
152
|
return [
|
105
153
|
...volumeMounts,
|
106
154
|
{
|
107
155
|
volume: this.configMap,
|
108
156
|
mountPath: "/scripts",
|
109
157
|
},
|
158
|
+
...(hasFunctionScripts
|
159
|
+
? [{ name: "node-modules", mountPath: "/scripts/node_modules" }]
|
160
|
+
: []),
|
110
161
|
]
|
111
162
|
})
|
112
163
|
|
@@ -115,18 +166,74 @@ export class ScriptBundle extends ComponentResource {
|
|
115
166
|
volumes: this.volumes,
|
116
167
|
volumeMounts: this.volumeMounts,
|
117
168
|
environment: this.environment,
|
169
|
+
distribution: this.distribution,
|
170
|
+
allowedEndpoints: this.allowedEndpoints,
|
171
|
+
image: this.image,
|
118
172
|
})
|
119
173
|
}
|
120
174
|
}
|
121
175
|
|
122
|
-
function
|
176
|
+
function stripWorkspacePrefix(value: string): string {
|
177
|
+
if (value.startsWith("workspace:")) {
|
178
|
+
return value.replace("workspace:", "")
|
179
|
+
}
|
180
|
+
|
181
|
+
return value
|
182
|
+
}
|
183
|
+
|
184
|
+
async function createScriptData(
|
123
185
|
distribution: ScriptDistribution,
|
124
186
|
environment: Unwrap<ResolvedScriptEnvironment>,
|
125
|
-
): Record<string, string
|
187
|
+
): Promise<Record<string, string>> {
|
126
188
|
const scriptData: Record<string, string> = {}
|
127
189
|
const actions: string[] = []
|
128
190
|
|
129
191
|
const distributionEnvironment = environment[distribution]
|
192
|
+
const setupScripts = { ...environment.setupScripts }
|
193
|
+
|
194
|
+
let hasFunctionScripts = false
|
195
|
+
|
196
|
+
for (const key in environment.files) {
|
197
|
+
if (typeof environment.files[key] === "function") {
|
198
|
+
const serialized = await serializeFunction(environment.files[key])
|
199
|
+
|
200
|
+
scriptData[key] = text`
|
201
|
+
#!/usr/local/bin/bun
|
202
|
+
|
203
|
+
${serialized.text}
|
204
|
+
|
205
|
+
exports.${serialized.exportName}()
|
206
|
+
`
|
207
|
+
|
208
|
+
hasFunctionScripts = true
|
209
|
+
} else {
|
210
|
+
scriptData[key] = environment.files[key]
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
if (hasFunctionScripts) {
|
215
|
+
const packageJson = await readPackageJSON()
|
216
|
+
|
217
|
+
packageJson.dependencies = omitBy(
|
218
|
+
mapValues(packageJson.dependencies ?? {}, stripWorkspacePrefix),
|
219
|
+
(_, key) => key.startsWith("@highstate/"),
|
220
|
+
)
|
221
|
+
|
222
|
+
packageJson.devDependencies = omitBy(
|
223
|
+
mapValues(packageJson.devDependencies ?? {}, stripWorkspacePrefix),
|
224
|
+
(_, key) => key.startsWith("@highstate/"),
|
225
|
+
)
|
226
|
+
|
227
|
+
scriptData["package.json"] = JSON.stringify(packageJson, null, 2)
|
228
|
+
|
229
|
+
setupScripts["resolve-dependencies.sh"] = text`
|
230
|
+
#!/usr/local/bin/bun
|
231
|
+
set -e
|
232
|
+
|
233
|
+
cd /scripts
|
234
|
+
bun install --production
|
235
|
+
`
|
236
|
+
}
|
130
237
|
|
131
238
|
if (distributionEnvironment.preInstallPackages.length > 0) {
|
132
239
|
scriptData["pre-install-packages.sh"] = getInstallPackagesScript(
|
@@ -166,9 +273,9 @@ function createScriptData(
|
|
166
273
|
`)
|
167
274
|
}
|
168
275
|
|
169
|
-
if (Object.keys(
|
170
|
-
for (const key in
|
171
|
-
scriptData[`setup-${key}`] =
|
276
|
+
if (Object.keys(setupScripts).length > 0) {
|
277
|
+
for (const key in setupScripts) {
|
278
|
+
scriptData[`setup-${key}`] = setupScripts[key]
|
172
279
|
|
173
280
|
actions.push(`
|
174
281
|
echo "+ Running setup script '${key}'..."
|
@@ -201,10 +308,6 @@ function createScriptData(
|
|
201
308
|
`)
|
202
309
|
}
|
203
310
|
|
204
|
-
for (const key in environment.scripts) {
|
205
|
-
scriptData[key] = environment.scripts[key]
|
206
|
-
}
|
207
|
-
|
208
311
|
scriptData["entrypoint.sh"] = trimIndentation(`
|
209
312
|
#!/bin/sh
|
210
313
|
set -e
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { Container } from "../container"
|
2
2
|
import type { ScriptBundle } from "./bundle"
|
3
|
-
import { Output, output, type Input } from "@pulumi/pulumi"
|
4
3
|
import { merge } from "remeda"
|
4
|
+
import { Output, output, type Input } from "@pulumi/pulumi"
|
5
5
|
|
6
|
-
export
|
6
|
+
export type ScriptContainer = Container & {
|
7
7
|
/**
|
8
8
|
* The script bundle to use.
|
9
9
|
*/
|
@@ -24,21 +24,26 @@ export interface ScriptContainer extends Container {
|
|
24
24
|
* @returns The container spec.
|
25
25
|
*/
|
26
26
|
export function createScriptContainer(options: ScriptContainer): Output<Container> {
|
27
|
-
|
28
|
-
const image =
|
29
|
-
options.bundle.distribution === "alpine"
|
30
|
-
? "alpine@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c"
|
31
|
-
: "ubuntu@sha256:72297848456d5d37d1262630108ab308d3e9ec7ed1c3286a32fe09856619a782"
|
27
|
+
const bundle = output(options.bundle)
|
32
28
|
|
29
|
+
return output({
|
30
|
+
options,
|
31
|
+
image: bundle.image,
|
32
|
+
volumeMounts: bundle.volumeMounts,
|
33
|
+
volumes: bundle.volumes,
|
34
|
+
environment: bundle.environment,
|
35
|
+
allowedEndpoints: bundle.allowedEndpoints,
|
36
|
+
}).apply(({ options, image, volumeMounts, volumes, environment, allowedEndpoints }) => {
|
33
37
|
return {
|
34
38
|
image,
|
35
39
|
command: ["/scripts/entrypoint.sh", `/scripts/${options.main}`],
|
36
40
|
|
37
41
|
...options,
|
38
42
|
|
39
|
-
volumeMounts:
|
40
|
-
volumes:
|
41
|
-
environment: merge(
|
42
|
-
|
43
|
+
volumeMounts: [...volumeMounts, ...(options.volumeMounts ?? [])],
|
44
|
+
volumes: [...volumes, ...(options.volumes ?? [])],
|
45
|
+
environment: merge(environment, options.environment),
|
46
|
+
allowedEndpoints: [...allowedEndpoints, ...(options.allowedEndpoints ?? [])],
|
47
|
+
} as Container
|
43
48
|
})
|
44
49
|
}
|
@@ -1,9 +1,15 @@
|
|
1
1
|
import type { Input, InputArray, InputMap } from "@highstate/pulumi"
|
2
2
|
import type { ContainerEnvironment, ContainerVolumeMount, WorkloadVolume } from "../container"
|
3
|
+
import type { InputL34Endpoint } from "@highstate/common"
|
3
4
|
|
4
5
|
export type ScriptDistribution = "alpine" | "ubuntu"
|
5
6
|
|
6
7
|
export type DistributionEnvironment = {
|
8
|
+
/**
|
9
|
+
* The image that should be used for the distribution.
|
10
|
+
*/
|
11
|
+
image?: Input<string>
|
12
|
+
|
7
13
|
/**
|
8
14
|
* The utility packages that should be installed before running "preInstallScripts".
|
9
15
|
*
|
@@ -21,8 +27,19 @@ export type DistributionEnvironment = {
|
|
21
27
|
* The packages that are available in the environment.
|
22
28
|
*/
|
23
29
|
packages?: InputArray<string>
|
30
|
+
|
31
|
+
/**
|
32
|
+
* The endpoint which the script is allowed to access scoped to the distribution.
|
33
|
+
*
|
34
|
+
* Typically, this is used to allow access to the package manager.
|
35
|
+
*
|
36
|
+
* Will be used to generate a network policy.
|
37
|
+
*/
|
38
|
+
allowedEndpoints?: InputArray<InputL34Endpoint>
|
24
39
|
}
|
25
40
|
|
41
|
+
export type ScriptProgram = () => unknown
|
42
|
+
|
26
43
|
export type ScriptEnvironment = {
|
27
44
|
[distribution in ScriptDistribution]?: DistributionEnvironment
|
28
45
|
} & {
|
@@ -37,9 +54,9 @@ export type ScriptEnvironment = {
|
|
37
54
|
cleanupScripts?: InputMap<string>
|
38
55
|
|
39
56
|
/**
|
40
|
-
* The arbitrary
|
57
|
+
* The arbitrary files available in the environment including scripts.
|
41
58
|
*/
|
42
|
-
|
59
|
+
files?: InputMap<string | ScriptProgram>
|
43
60
|
|
44
61
|
/**
|
45
62
|
* The volumes that should be defined in the environment.
|
@@ -55,25 +72,58 @@ export type ScriptEnvironment = {
|
|
55
72
|
* The environment variables that should be defined in the environment.
|
56
73
|
*/
|
57
74
|
environment?: Input<ContainerEnvironment>
|
75
|
+
|
76
|
+
/**
|
77
|
+
* The endpoint which the script is allowed to access.
|
78
|
+
*
|
79
|
+
* Will be used to generate a network policy.
|
80
|
+
*/
|
81
|
+
allowedEndpoints?: InputArray<InputL34Endpoint>
|
58
82
|
}
|
59
83
|
|
60
84
|
export type ResolvedScriptEnvironment = Omit<Required<ScriptEnvironment>, ScriptDistribution> & {
|
61
85
|
[distribution in ScriptDistribution]: Required<DistributionEnvironment>
|
62
86
|
}
|
63
87
|
|
64
|
-
const emptyDistributionEnvironment
|
88
|
+
const emptyDistributionEnvironment = {
|
65
89
|
preInstallPackages: [],
|
66
90
|
preInstallScripts: {},
|
67
91
|
packages: [],
|
68
92
|
}
|
69
93
|
|
70
94
|
export const emptyScriptEnvironment: ResolvedScriptEnvironment = {
|
71
|
-
alpine:
|
72
|
-
|
95
|
+
alpine: {
|
96
|
+
...emptyDistributionEnvironment,
|
97
|
+
image: "alpine@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c",
|
98
|
+
allowedEndpoints: [
|
99
|
+
//
|
100
|
+
"tcp://dl-cdn.alpinelinux.org:443",
|
101
|
+
"tcp://dl-cdn.alpinelinux.org:80",
|
102
|
+
],
|
103
|
+
},
|
104
|
+
|
105
|
+
ubuntu: {
|
106
|
+
...emptyDistributionEnvironment,
|
107
|
+
image: "ubuntu@sha256:72297848456d5d37d1262630108ab308d3e9ec7ed1c3286a32fe09856619a782",
|
108
|
+
allowedEndpoints: [
|
109
|
+
//
|
110
|
+
"tcp://archive.ubuntu.com:80",
|
111
|
+
"tcp://archive.ubuntu.com:443",
|
112
|
+
"tcp://security.ubuntu.com:80",
|
113
|
+
"tcp://security.ubuntu.com:443",
|
114
|
+
],
|
115
|
+
},
|
116
|
+
|
73
117
|
setupScripts: {},
|
74
118
|
cleanupScripts: {},
|
75
|
-
|
119
|
+
files: {},
|
76
120
|
volumes: [],
|
77
121
|
volumeMounts: [],
|
78
122
|
environment: {},
|
123
|
+
allowedEndpoints: [],
|
124
|
+
}
|
125
|
+
|
126
|
+
export const functionScriptImages: Record<ScriptDistribution, string> = {
|
127
|
+
alpine: "oven/bun@sha256:6b14922b0885c3890cdb0b396090af1da486ba941df5ee94391eef64f7113c61",
|
128
|
+
ubuntu: "oven/bun@sha256:66b431441dc4c36d7e8164bfc61e6348ec1d7ce2862fc3a29f5dc9856e8205e4",
|
79
129
|
}
|