hammerkit 2.1.0-next.1 → 2.1.0-next.10
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/build.schema.json +126 -28
- package/dist/cli.js +5 -0
- package/dist/dashboard/assets/graph-canvas-BFnEN5i0.js +8 -0
- package/dist/dashboard/assets/{index-DRSwIRXd.js → index-CE5PSB3y.js} +15 -9
- package/dist/dashboard/assets/index-Dt3ITvRO.css +2 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/docker/item-network.js +6 -5
- package/dist/docker/remove-orphaned-containers.js +5 -4
- package/dist/environment/replace-env-variables.js +8 -5
- package/dist/environment/run-source-envs.js +2 -1
- package/dist/executer/check-readiness.js +8 -4
- package/dist/executer/docker-healthcheck.js +73 -0
- package/dist/executer/docker-service.js +21 -15
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +62 -14
- package/dist/network/healthcheck-request.js +38 -0
- package/dist/optimizer/work-task-cache-description.js +5 -3
- package/dist/planner/image-build.js +5 -0
- package/dist/planner/service-definition.js +2 -1
- package/dist/planner/utils/append-work-service.js +12 -4
- package/dist/planner/utils/dependency-outputs.js +7 -6
- package/dist/planner/validate.js +41 -0
- package/dist/planner/work-healthcheck.js +23 -2
- package/dist/planner/work-runtime-docker.js +24 -1
- package/dist/planner/work-runtime-kubernetes.js +37 -16
- package/dist/planner/work-secret.js +33 -11
- package/dist/planner/work-service-id.js +30 -6
- package/dist/planner/work-service.js +2 -2
- package/dist/program.js +19 -1
- package/dist/remote/annotations.js +8 -2
- package/dist/remote/remote-work-commands.js +5 -3
- package/dist/schema/build-file-base-task-schema.js +16 -1
- package/dist/schema/build-file-image-build-schema.js +5 -8
- package/dist/schema/build-file-service-container-healthcheck.js +25 -7
- package/dist/schema/reference-parser.js +108 -43
- package/dist/schema/work-scope-parser.js +8 -0
- package/dist/secrets/prefetch-secrets.js +20 -1
- package/dist/server/kubernetes-sandbox-storage.js +3 -2
- package/dist/server/overview.js +7 -1
- package/dist/server/plan.js +16 -1
- package/dist/server/run-source-environment.js +1 -1
- package/dist/server/sandbox-files-api.js +27 -12
- package/dist/server/sandbox-files.js +3 -2
- package/dist/server/sandbox-pod.js +1 -1
- package/dist/server/sandboxes-api.js +65 -14
- package/dist/server/sandboxes.js +19 -3
- package/package.json +1 -1
- package/dist/dashboard/assets/graph-canvas-DtJSpova.js +0 -8
- package/dist/dashboard/assets/index-BndChMep.css +0 -2
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildFileServiceContainerHealthcheck = void 0;
|
|
3
|
+
exports.buildFileServiceContainerHealthcheck = exports.buildFileServiceTcpHealthcheck = exports.buildFileServiceHttpHealthcheck = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const duration_schema_1 = require("./duration-schema");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
// How long the service may take to pass its check once its container runs
|
|
7
|
+
// (default 20s, HAMMERKIT_HEALTHCHECK_TIMEOUT changes the default).
|
|
8
|
+
const timeout = duration_schema_1.durationSchema.optional();
|
|
9
|
+
const port = (0, zod_1.number)().int().min(1).max(65535);
|
|
10
|
+
// A request to a port of the service, from its own network: no tool of the image runs it.
|
|
11
|
+
exports.buildFileServiceHttpHealthcheck = (0, zod_1.object)({
|
|
12
|
+
port,
|
|
13
|
+
path: (0, zod_1.string)().startsWith('/', 'path must start with /').optional(),
|
|
14
|
+
scheme: (0, zod_1.enum)(['http', 'https']).optional(),
|
|
15
|
+
// the status codes that count as healthy, any 2xx or 3xx without
|
|
16
|
+
status: (0, zod_1.array)((0, zod_1.number)().int().min(100).max(599)).min(1).optional(),
|
|
17
|
+
})
|
|
18
|
+
.strict()
|
|
19
|
+
.describe('GET <scheme>://<service>:<port><path>, healthy on one of status (default any 2xx or 3xx)');
|
|
20
|
+
// a connection to a port of the service
|
|
21
|
+
exports.buildFileServiceTcpHealthcheck = (0, zod_1.object)({ port })
|
|
22
|
+
.strict()
|
|
23
|
+
.describe('healthy once <port> takes a connection');
|
|
24
|
+
// Exactly one of `cmd`, `http` or `tcp`.
|
|
25
|
+
exports.buildFileServiceContainerHealthcheck = (0, zod_1.union)([
|
|
26
|
+
(0, zod_1.object)({ cmd: (0, zod_1.string)(), timeout }).strict(),
|
|
27
|
+
(0, zod_1.object)({ http: exports.buildFileServiceHttpHealthcheck, timeout }).strict(),
|
|
28
|
+
(0, zod_1.object)({ tcp: exports.buildFileServiceTcpHealthcheck, timeout }).strict(),
|
|
29
|
+
]).describe('exactly one of cmd, http or tcp, and how long it may take to pass');
|
|
12
30
|
//# sourceMappingURL=build-file-service-container-healthcheck.js.map
|
|
@@ -29,8 +29,15 @@ class UnpublishedError extends Error {
|
|
|
29
29
|
this.reason = reason;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
//
|
|
33
|
-
|
|
32
|
+
// What a task or service names that is a base (`abstract: true`), which only `extend` names
|
|
33
|
+
class AbstractError extends Error {
|
|
34
|
+
constructor(name) {
|
|
35
|
+
super(`${name} is abstract`);
|
|
36
|
+
this.name = name;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// The task or service `user` names another one by, which a server left out or which is a base:
|
|
40
|
+
// the error says which one names it, as an error elsewhere is left as it is
|
|
34
41
|
function findPublished(user, verb, find) {
|
|
35
42
|
try {
|
|
36
43
|
return find();
|
|
@@ -39,6 +46,9 @@ function findPublished(user, verb, find) {
|
|
|
39
46
|
if (e instanceof UnpublishedError) {
|
|
40
47
|
throw new Error(`${user} ${verb} ${e.name}, which is not published (${e.reason})`);
|
|
41
48
|
}
|
|
49
|
+
if (e instanceof AbstractError) {
|
|
50
|
+
throw new Error(`${user} ${verb} ${e.name}, which is abstract: a base that only extend names, it doesn't run`);
|
|
51
|
+
}
|
|
42
52
|
throw e;
|
|
43
53
|
}
|
|
44
54
|
}
|
|
@@ -67,6 +77,7 @@ async function parseReferences(ctx, mainScope, environment) {
|
|
|
67
77
|
const reference = {
|
|
68
78
|
files: {},
|
|
69
79
|
tasks: {},
|
|
80
|
+
bases: {},
|
|
70
81
|
services: {},
|
|
71
82
|
envFiles: {},
|
|
72
83
|
environments: {},
|
|
@@ -109,7 +120,8 @@ async function parseReferences(ctx, mainScope, environment) {
|
|
|
109
120
|
if (isLeftOut(file, relativeName, task)) {
|
|
110
121
|
continue;
|
|
111
122
|
}
|
|
112
|
-
|
|
123
|
+
const tasks = task.abstract ? reference.bases : reference.tasks;
|
|
124
|
+
tasks[relativeName] = {
|
|
113
125
|
type: 'task',
|
|
114
126
|
schema: task,
|
|
115
127
|
cwd: file.cwd,
|
|
@@ -159,7 +171,8 @@ async function parseReferences(ctx, mainScope, environment) {
|
|
|
159
171
|
}
|
|
160
172
|
}
|
|
161
173
|
}
|
|
162
|
-
|
|
174
|
+
// a base is checked as a task is, though only the tasks extending it run
|
|
175
|
+
for (const task of [...Object.values(reference.tasks), ...Object.values(reference.bases)]) {
|
|
163
176
|
applySchemaExtension(reference, task);
|
|
164
177
|
resolveDeps(reference, task, task.scope, task.schema);
|
|
165
178
|
resolveNeeds(reference, task, task.scope, task.schema);
|
|
@@ -188,57 +201,67 @@ function applySchemaExtension(reference, task) {
|
|
|
188
201
|
task.extension = 'applying';
|
|
189
202
|
task.depBases = [];
|
|
190
203
|
task.needBases = [];
|
|
191
|
-
//
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
const reset = new Set(task.schema.reset ?? []);
|
|
197
|
-
if (!task.schema.extend) {
|
|
204
|
+
// every property of every kind of task, as a task may take its kind from its base
|
|
205
|
+
const schema = task.schema;
|
|
206
|
+
const reset = new Set(schema.reset ?? []);
|
|
207
|
+
if (!schema.extend) {
|
|
198
208
|
if (reset.size > 0) {
|
|
199
209
|
throw new Error(`task ${task.relativeName} sets reset without extend`);
|
|
200
210
|
}
|
|
201
211
|
task.extension = 'applied';
|
|
202
212
|
return;
|
|
203
213
|
}
|
|
204
|
-
const name =
|
|
205
|
-
const extend = findPublished(task.relativeName, 'extends', () =>
|
|
206
|
-
// hammerkit makes the commands of a task that builds an image (see image-build.ts)
|
|
207
|
-
if ((0, build_file_task_schema_1.isBuildFileImageBuildTaskSchema)(extend.schema)) {
|
|
208
|
-
throw new Error(`task ${task.relativeName} extends ${name}, which builds an image: such a task can't be extended`);
|
|
209
|
-
}
|
|
214
|
+
const name = schema.extend;
|
|
215
|
+
const extend = findPublished(task.relativeName, 'extends', () => findBase(reference, task, name));
|
|
210
216
|
applySchemaExtension(reference, extend);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
+
const base = extend.schema;
|
|
218
|
+
// only a value the base has: `image` and `build` in a schema decide the kind of task
|
|
219
|
+
for (const key of ['shell', 'cache', 'timeout', 'runner', 'network', 'args', 'image']) {
|
|
220
|
+
if (schema[key] === undefined && base[key] !== undefined) {
|
|
221
|
+
Object.assign(schema, { [key]: base[key] });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
217
224
|
if (!reset.has('cmds'))
|
|
218
|
-
|
|
225
|
+
schema.cmds = extendArray(schema.cmds, base.cmds);
|
|
219
226
|
if (!reset.has('src'))
|
|
220
|
-
|
|
227
|
+
schema.src = extendArray(schema.src, base.src);
|
|
221
228
|
if (!reset.has('generates'))
|
|
222
|
-
|
|
229
|
+
schema.generates = extendArray(schema.generates, base.generates);
|
|
230
|
+
if (!reset.has('mounts'))
|
|
231
|
+
schema.mounts = extendArray(schema.mounts, base.mounts);
|
|
232
|
+
// key by key, the task's own value winning, as envs and labels: a base sets push and login
|
|
233
|
+
// for the tasks that set their own tags
|
|
234
|
+
if (!reset.has('build') && base.build)
|
|
235
|
+
schema.build = { ...base.build, ...schema.build };
|
|
236
|
+
// what is a task's own, for its own run, a base that only is extended declares for the tasks
|
|
237
|
+
// extending it: its credentials, limits and claim
|
|
238
|
+
if (base.abstract) {
|
|
239
|
+
for (const key of ['account', 'resources', 'volumeSize', 'platform']) {
|
|
240
|
+
if (schema[key] === undefined && base[key] !== undefined) {
|
|
241
|
+
Object.assign(schema, { [key]: base[key] });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (!reset.has('secrets'))
|
|
245
|
+
schema.secrets = extendArray(schema.secrets, base.secrets);
|
|
246
|
+
if (!reset.has('capAdd'))
|
|
247
|
+
schema.capAdd = extendArray(schema.capAdd, base.capAdd);
|
|
248
|
+
}
|
|
223
249
|
if (!reset.has('labels'))
|
|
224
|
-
|
|
250
|
+
schema.labels = extendObject(schema.labels, base.labels);
|
|
251
|
+
// the labels a task is filtered by: those of its build file with its own, now with its base's
|
|
252
|
+
task.labels = (0, label_values_1.mergeLabels)(task.scope.schema.labels, schema.labels);
|
|
225
253
|
// the base's resolved envs: its own plus the top-level envs of its build file
|
|
226
254
|
// (and the inputs an include passed), which carry the defaults it relies on
|
|
227
255
|
if (!reset.has('envs'))
|
|
228
256
|
task.envs = (0, merge_environment_variables_1.mergeEnvironmentVariables)(task.envs, extend.envs);
|
|
229
|
-
if ((0, build_file_task_schema_1.isBuildFileContainerTaskSchema)(extend.schema)) {
|
|
230
|
-
const taskSchema = task.schema;
|
|
231
|
-
taskSchema.image = taskSchema.image ?? extend.schema.image;
|
|
232
|
-
if (!reset.has('mounts'))
|
|
233
|
-
taskSchema.mounts = extendArray(taskSchema.mounts, extend.schema.mounts);
|
|
234
|
-
}
|
|
235
257
|
rejectContainerPropertiesWithoutImage(task);
|
|
258
|
+
rejectCommandsOfImageBuild(task);
|
|
236
259
|
// deps and needs resolve in the file that declares them, so every base up the
|
|
237
260
|
// chain contributes its own, not only the nearest; what a task resets is not
|
|
238
261
|
// passed on to the tasks extending it either
|
|
239
|
-
const
|
|
240
|
-
task.needBases = reset.has('needs') ? [] : [...(extend.needBases ?? []),
|
|
241
|
-
task.depBases = reset.has('deps') ? [] : [...(extend.depBases ?? []),
|
|
262
|
+
const declared = { scope: extend.scope, schema: extend.schema };
|
|
263
|
+
task.needBases = reset.has('needs') ? [] : [...(extend.needBases ?? []), declared];
|
|
264
|
+
task.depBases = reset.has('deps') ? [] : [...(extend.depBases ?? []), declared];
|
|
242
265
|
for (const needBase of task.needBases) {
|
|
243
266
|
resolveNeeds(reference, task, needBase.scope, needBase.schema);
|
|
244
267
|
}
|
|
@@ -247,6 +270,20 @@ function applySchemaExtension(reference, task) {
|
|
|
247
270
|
}
|
|
248
271
|
task.extension = 'applied';
|
|
249
272
|
}
|
|
273
|
+
// The task `extend` names, a base or a task, with what a build file is missing when there is none
|
|
274
|
+
function findBase(reference, task, name) {
|
|
275
|
+
try {
|
|
276
|
+
return findTask(reference, task.scope, name, null, true).task;
|
|
277
|
+
}
|
|
278
|
+
catch (e) {
|
|
279
|
+
if (!(e instanceof NotFoundError)) {
|
|
280
|
+
throw e;
|
|
281
|
+
}
|
|
282
|
+
const prefix = (0, split_name_1.splitName)(e.name).prefix;
|
|
283
|
+
const missing = prefix && !e.scope.references[prefix] ? `include or reference ${prefix}` : `task ${(0, split_name_1.splitName)(e.name).name}`;
|
|
284
|
+
throw new Error(`task ${task.relativeName} extends ${name}, but ${e.scope.fileName} has no ${missing}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
250
287
|
function rejectContainerPropertiesWithoutImage(task) {
|
|
251
288
|
if ((0, build_file_task_schema_1.isBuildFileContainerTaskSchema)(task.schema) || (0, build_file_task_schema_1.isBuildFileImageBuildTaskSchema)(task.schema)) {
|
|
252
289
|
return;
|
|
@@ -257,6 +294,22 @@ function rejectContainerPropertiesWithoutImage(task) {
|
|
|
257
294
|
throw new Error(`task ${task.relativeName} sets ${property}, but neither it nor its base has an image`);
|
|
258
295
|
}
|
|
259
296
|
}
|
|
297
|
+
// hammerkit makes the image and the command of a task that builds one (see image-build.ts)
|
|
298
|
+
const IMAGE_BUILD_EXCLUDED = ['image', 'cmds', 'shell', 'args', 'mounts', 'capAdd', 'platform'];
|
|
299
|
+
function rejectCommandsOfImageBuild(task) {
|
|
300
|
+
const schema = task.schema;
|
|
301
|
+
if (!schema.build) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const property = IMAGE_BUILD_EXCLUDED.find((key) => {
|
|
305
|
+
const value = schema[key];
|
|
306
|
+
return value !== undefined && !(Array.isArray(value) && value.length === 0);
|
|
307
|
+
});
|
|
308
|
+
if (property) {
|
|
309
|
+
throw new Error(`task ${task.relativeName} has build and ${property}, from it or the task it extends: ` +
|
|
310
|
+
`a task that builds an image takes no ${property}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
260
313
|
function extendArray(base, extend) {
|
|
261
314
|
if (!extend) {
|
|
262
315
|
return base;
|
|
@@ -325,21 +378,30 @@ function resolveNeeds(reference, taskOrService, scope, schema) {
|
|
|
325
378
|
throw new Error(`${taskOrService.relativeName} needs two services as ${twice}, give one another name with name:`);
|
|
326
379
|
}
|
|
327
380
|
}
|
|
328
|
-
|
|
381
|
+
// A name no task of a build file has
|
|
382
|
+
class NotFoundError extends Error {
|
|
383
|
+
constructor(scope, name) {
|
|
384
|
+
super('unable to find ' + name);
|
|
385
|
+
this.scope = scope;
|
|
386
|
+
this.name = name;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
// The task a name stands for in a build file; a base (`abstract`) only for `extend`
|
|
390
|
+
function findTask(ctx, scope, name, type, base = false) {
|
|
329
391
|
refuseNotFetched(scope, name);
|
|
330
392
|
const ref = (0, split_name_1.splitName)(name);
|
|
331
393
|
if (ref.prefix) {
|
|
332
394
|
if (scope.references[ref.prefix]) {
|
|
333
|
-
return findTask(ctx, scope.references[ref.prefix].scope, ref.name, scope.references[ref.prefix].type);
|
|
395
|
+
return findTask(ctx, scope.references[ref.prefix].scope, ref.name, scope.references[ref.prefix].type, base);
|
|
334
396
|
}
|
|
335
397
|
else if (scope.schema.tasks && scope.schema.tasks[name]) {
|
|
336
|
-
return resolveTask(ctx, scope, name, type ?? 'build-file');
|
|
398
|
+
return resolveTask(ctx, scope, name, type ?? 'build-file', base);
|
|
337
399
|
}
|
|
338
400
|
}
|
|
339
401
|
else if (scope.schema.tasks && scope.schema.tasks[ref.name]) {
|
|
340
|
-
return resolveTask(ctx, scope, ref.name, type ?? 'build-file');
|
|
402
|
+
return resolveTask(ctx, scope, ref.name, type ?? 'build-file', base);
|
|
341
403
|
}
|
|
342
|
-
throw new
|
|
404
|
+
throw new NotFoundError(scope, name);
|
|
343
405
|
}
|
|
344
406
|
exports.findTask = findTask;
|
|
345
407
|
// A name in a git source a server did not fetch, since it is left out
|
|
@@ -348,9 +410,12 @@ function refuseNotFetched(scope, name) {
|
|
|
348
410
|
throw new UnpublishedError(combinePath(scope.namePrefix, name), 'its build file is included with publish: false');
|
|
349
411
|
}
|
|
350
412
|
}
|
|
351
|
-
function resolveTask(ctx, scope, name, type) {
|
|
413
|
+
function resolveTask(ctx, scope, name, type, base) {
|
|
352
414
|
const fullName = combinePath(scope.namePrefix, name);
|
|
353
|
-
|
|
415
|
+
if (!base && ctx.bases[fullName]) {
|
|
416
|
+
throw new AbstractError(fullName);
|
|
417
|
+
}
|
|
418
|
+
const buildFileTask = ctx.tasks[fullName] ?? (base ? ctx.bases[fullName] : undefined);
|
|
354
419
|
if (!buildFileTask && ctx.unpublished?.[fullName]) {
|
|
355
420
|
throw new UnpublishedError(fullName, ctx.unpublished[fullName]);
|
|
356
421
|
}
|
|
@@ -48,6 +48,7 @@ function getWorkContext(context, scope, environment) {
|
|
|
48
48
|
// its init task's need on it, which narrowing follows
|
|
49
49
|
const tasks = Object.values(context.tasks).map((task) => (0, append_work_task_1.appendWorkTask)(workTree, task.cwd, task, environment, context));
|
|
50
50
|
const services = Object.values(context.services).map((service) => (0, append_work_service_1.appendWorkService)(workTree, service, environment, context));
|
|
51
|
+
refuseBases(context, (0, work_scope_1.isContextTaskFilter)(scope) ? [scope.taskName] : [...(scope.names ?? []), ...(scope.taskNames ?? [])]);
|
|
51
52
|
const apply = { servicesAlone: !(0, work_scope_1.isContextTaskFilter)(scope) && !!scope.names && !!scope.stop };
|
|
52
53
|
const selectedTasks = [];
|
|
53
54
|
const selectedServices = [];
|
|
@@ -86,6 +87,13 @@ function getWorkContext(context, scope, environment) {
|
|
|
86
87
|
return filteredWorkTree;
|
|
87
88
|
}
|
|
88
89
|
exports.getWorkContext = getWorkContext;
|
|
90
|
+
// A base (`abstract: true`) is not run by its name, as it is not listed
|
|
91
|
+
function refuseBases(context, names) {
|
|
92
|
+
const base = names.find((name) => name in context.bases);
|
|
93
|
+
if (base) {
|
|
94
|
+
throw new Error(`${base} is abstract, a base for extend that doesn't run: run a task that extends it`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
89
97
|
// The whole build file is planned first, so a shared service lists every task
|
|
90
98
|
// and service that needs it. Those outside this run never start or end, and a
|
|
91
99
|
// service waiting for them to finish would keep the run open forever.
|
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prefetchSecrets = void 0;
|
|
3
|
+
exports.prefetchSecrets = exports.requireReadableSecrets = void 0;
|
|
4
4
|
const plan_work_tasks_1 = require("../planner/utils/plan-work-tasks");
|
|
5
5
|
const work_secret_1 = require("../planner/work-secret");
|
|
6
6
|
const provider_values_1 = require("./provider-values");
|
|
7
|
+
function secretsOf(workTree) {
|
|
8
|
+
return [
|
|
9
|
+
...[...(0, plan_work_tasks_1.iterateWorkServices)(workTree)].flatMap((service) => ('secrets' in service.data ? service.data.secrets : [])),
|
|
10
|
+
...[...(0, plan_work_tasks_1.iterateWorkTasks)(workTree)].flatMap((task) => task.data.secrets),
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
// A secret of a provider that this machine does not declare fails a command only when the
|
|
14
|
+
// command needs it: a run needs every secret of the tasks and services it holds, the other
|
|
15
|
+
// commands the `cache: true` ones, for task ids. A task elsewhere in the build file that reads
|
|
16
|
+
// it does not stop them (ADR 0008).
|
|
17
|
+
function requireReadableSecrets(workTree, needed = () => true) {
|
|
18
|
+
for (const secret of secretsOf(workTree)) {
|
|
19
|
+
if (secret.source.type === 'unavailable' && needed(secret)) {
|
|
20
|
+
throw new Error(secret.source.error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.requireReadableSecrets = requireReadableSecrets;
|
|
7
25
|
// Fetches the values a task id needs; a run drops the ones of the previous run
|
|
8
26
|
// first (`newRun`), any other command reuses what the run already fetched. A task id is computed synchronously and holds the
|
|
9
27
|
// digest of each `cache: true` secret, so those values must be in memory before
|
|
10
28
|
// anything asks for an id. Secrets that don't affect the id are read when their
|
|
11
29
|
// task starts, and a plan without provider secrets calls no provider.
|
|
12
30
|
async function prefetchSecrets(workTree, environment, newRun = false) {
|
|
31
|
+
requireReadableSecrets(workTree, (secret) => secret.cache);
|
|
13
32
|
if (newRun) {
|
|
14
33
|
(0, provider_values_1.beginSecretRun)(environment);
|
|
15
34
|
}
|
|
@@ -1030,8 +1030,9 @@ class KubernetesSandboxFiles {
|
|
|
1030
1030
|
changes() {
|
|
1031
1031
|
return this.ask({ op: 'changes' });
|
|
1032
1032
|
}
|
|
1033
|
-
diff(format, author) {
|
|
1034
|
-
|
|
1033
|
+
diff(format, author, paths) {
|
|
1034
|
+
// a pod of an older image leaves `paths` out and answers the whole diff
|
|
1035
|
+
return this.ask({ op: 'diff', format, author, ...(paths ? { paths } : {}) });
|
|
1035
1036
|
}
|
|
1036
1037
|
async commit(author) {
|
|
1037
1038
|
return (await this.ask({ op: 'commit', author })) ?? undefined;
|
package/dist/server/overview.js
CHANGED
|
@@ -238,7 +238,7 @@ const STATES = [
|
|
|
238
238
|
'cancelled',
|
|
239
239
|
'rejected',
|
|
240
240
|
];
|
|
241
|
-
// `scope`, `state` (a comma separated list) and `
|
|
241
|
+
// `scope`, `state` (a comma separated list), `kind`, `id`, `sandbox`, `since` and `until` of GET /v1/runs.
|
|
242
242
|
function parseRunFilter(params, grant, now = Date.now()) {
|
|
243
243
|
const scope = params.get('scope') ?? 'mine';
|
|
244
244
|
if (scope !== 'mine' && scope !== 'visible' && scope !== 'all') {
|
|
@@ -264,6 +264,10 @@ function parseRunFilter(params, grant, now = Date.now()) {
|
|
|
264
264
|
if (id !== undefined && !/^run_[A-Za-z0-9_-]{16}$/.test(id)) {
|
|
265
265
|
throw new Error('id: the id of a run, run_...');
|
|
266
266
|
}
|
|
267
|
+
const sandbox = params.get('sandbox') ?? undefined;
|
|
268
|
+
if (sandbox !== undefined && !runs_1.SANDBOX_ID_PATTERN.test(sandbox)) {
|
|
269
|
+
throw new Error('sandbox: the id of a sandbox, sbx_...');
|
|
270
|
+
}
|
|
267
271
|
const since = parseMoment(params.get('since'), now, 'since');
|
|
268
272
|
const until = parseMoment(params.get('until'), now, 'until');
|
|
269
273
|
if (since !== undefined && until !== undefined && until < since) {
|
|
@@ -274,6 +278,7 @@ function parseRunFilter(params, grant, now = Date.now()) {
|
|
|
274
278
|
...(states ? { states } : {}),
|
|
275
279
|
...(kind ? { kind } : {}),
|
|
276
280
|
...(id ? { id } : {}),
|
|
281
|
+
...(sandbox ? { sandbox } : {}),
|
|
277
282
|
...(since !== undefined ? { since } : {}),
|
|
278
283
|
...(until !== undefined ? { until } : {}),
|
|
279
284
|
};
|
|
@@ -299,6 +304,7 @@ exports.FilterRefused = FilterRefused;
|
|
|
299
304
|
function filterRuns(runs, viewer, filter) {
|
|
300
305
|
return runs.filter((run) => (filter.scope === 'mine' ? owns(viewer, run) : maySee(viewer, run)) &&
|
|
301
306
|
(!filter.id || run.id === filter.id) &&
|
|
307
|
+
(!filter.sandbox || (run.source.type === 'sandbox' && run.source.id === filter.sandbox)) &&
|
|
302
308
|
(!filter.states || filter.states.includes(run.state)) &&
|
|
303
309
|
(!filter.kind || (filter.kind === 'services') === !!run.up) &&
|
|
304
310
|
(filter.since === undefined || Date.parse(run.createdAt) >= filter.since) &&
|
package/dist/server/plan.js
CHANGED
|
@@ -19,6 +19,7 @@ const parse_error_1 = require("../schema/parse-error");
|
|
|
19
19
|
const task_arguments_1 = require("../planner/utils/task-arguments");
|
|
20
20
|
const work_network_1 = require("../planner/work-network");
|
|
21
21
|
const run_source_envs_1 = require("../environment/run-source-envs");
|
|
22
|
+
const prefetch_secrets_1 = require("../secrets/prefetch-secrets");
|
|
22
23
|
class DefinitionError extends Error {
|
|
23
24
|
}
|
|
24
25
|
exports.DefinitionError = DefinitionError;
|
|
@@ -167,6 +168,9 @@ function describeSecret(secret) {
|
|
|
167
168
|
if (source.type === 'provider') {
|
|
168
169
|
return { from: `${source.provider}:${source.ref}`, account: source.account, target };
|
|
169
170
|
}
|
|
171
|
+
if (source.type === 'unavailable') {
|
|
172
|
+
return { from: source.from, account: null, target };
|
|
173
|
+
}
|
|
170
174
|
return { from: source.type === 'env' ? `env:${source.name}` : `file:${source.path}`, account: null, target };
|
|
171
175
|
}
|
|
172
176
|
// What a server refuses to publish. A secret that reads a file or a variable of the
|
|
@@ -335,7 +339,14 @@ function toPlan(root, item) {
|
|
|
335
339
|
const mounts = (0, work_task_1.isContainerWorkTask)(data) || (0, work_service_1.isContainerWorkService)(data)
|
|
336
340
|
? data.mounts.map((mount) => {
|
|
337
341
|
const inside = insideBundle(root, data.cwd, mount.localPath);
|
|
338
|
-
|
|
342
|
+
const readOnly = mount.readOnly ? ':ro' : '';
|
|
343
|
+
// a mount that names only its source (`- .`) lands at the same path in the container,
|
|
344
|
+
// which is in the directory the server read the bundle in, one of its own each time:
|
|
345
|
+
// such a mount is named as the build file names it
|
|
346
|
+
if (inside.length > 0 && mount.containerPath === (0, path_1.resolve)(data.cwd, mount.localPath)) {
|
|
347
|
+
return `${inside[0]}${readOnly}`;
|
|
348
|
+
}
|
|
349
|
+
return `${inside.length > 0 ? inside[0] : mount.localPath}:${mount.containerPath}${readOnly}`;
|
|
339
350
|
})
|
|
340
351
|
: [];
|
|
341
352
|
const ports = 'ports' in data ? data.ports.map((port) => `${port.hostPort ?? ''}:${port.containerPort}`) : [];
|
|
@@ -423,6 +434,10 @@ async function planBundle(bundle, environment, options = {}) {
|
|
|
423
434
|
}
|
|
424
435
|
const context = await (0, reference_parser_1.parseReferences)(ctx, scope, inspected);
|
|
425
436
|
const workTree = (0, work_scope_parser_1.getWorkContext)(context, options.scope ?? { environmentName: null }, inspected);
|
|
437
|
+
// the server's providers and accounts are the ones that count: a task it could never read
|
|
438
|
+
// a secret of is refused when it is published, and a run when it is planned (only the
|
|
439
|
+
// tasks and services of the run count then)
|
|
440
|
+
(0, prefetch_secrets_1.requireReadableSecrets)(workTree);
|
|
426
441
|
const items = itemsOf(workTree);
|
|
427
442
|
if (options.policy) {
|
|
428
443
|
const policyProblems = findPolicyProblems(items, options.policy, directory);
|
|
@@ -9,7 +9,7 @@ const COMMIT = /^[0-9a-f]{40}([0-9a-f]{24})?$/i;
|
|
|
9
9
|
// repository, and the branch or tag and the commit it was pinned to, or the repository and the
|
|
10
10
|
// sandbox. None of them is a credential, so a task that reads them still takes arguments and
|
|
11
11
|
// keeps its network (see PLAIN_SERVER_ENVS). A sandbox has no commit: its files may hold
|
|
12
|
-
// changes. A run from an upload has none of them.
|
|
12
|
+
// changes. A run from an upload has none of them. Each is a name of RUN_SOURCE_ENVS.
|
|
13
13
|
function runSourceEnvironment(source) {
|
|
14
14
|
if (source.type === 'ref') {
|
|
15
15
|
return {
|
|
@@ -76,10 +76,14 @@ const searchSchema = zod_1.z.preprocess((body) => {
|
|
|
76
76
|
* PUT /v1/sandboxes/<id>/files/<path> write bytes, If-Match: "<sha256>"
|
|
77
77
|
* POST /v1/sandboxes/<id>/search ripgrep
|
|
78
78
|
* POST /v1/sandboxes/<id>/edits { dryRun, ops }, all or nothing
|
|
79
|
-
* GET /v1/sandboxes/<id>/changes?format=summary|diff|patch
|
|
79
|
+
* GET /v1/sandboxes/<id>/changes?format=summary|diff|patch (diff: &path=… for some files)
|
|
80
80
|
*
|
|
81
81
|
* Reading a file works at any time. Writes, and the reads that walk the files (tree, search,
|
|
82
82
|
* changes), are `409` while a run holds the sandbox.
|
|
83
|
+
*
|
|
84
|
+
* Who may read the sandbox, its owner and who observes, was decided by `handleSandboxes`:
|
|
85
|
+
* reads go as its owner. Writes go as the caller, so the registry answers anybody but the
|
|
86
|
+
* owner `404`.
|
|
83
87
|
*/
|
|
84
88
|
async function handleSandboxFiles(sandboxes, log, principal, sandbox, action, path, req, res, url) {
|
|
85
89
|
const who = `iss=${principal.iss} sub=${principal.sub}`;
|
|
@@ -99,7 +103,7 @@ async function handleSandboxFiles(sandboxes, log, principal, sandbox, action, pa
|
|
|
99
103
|
limit: intParam(url, 'limit'),
|
|
100
104
|
cursor: url.searchParams.get('cursor') ?? undefined,
|
|
101
105
|
};
|
|
102
|
-
const tree = await sandboxes.read(
|
|
106
|
+
const tree = await sandboxes.read(sandbox.owner, sandbox.id, (files) => files.tree(query));
|
|
103
107
|
(0, http_1.send)(res, 200, tree);
|
|
104
108
|
}
|
|
105
109
|
else if (action === 'search') {
|
|
@@ -107,7 +111,7 @@ async function handleSandboxFiles(sandboxes, log, principal, sandbox, action, pa
|
|
|
107
111
|
return (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow: 'POST' });
|
|
108
112
|
}
|
|
109
113
|
const query = parse(searchSchema, await (0, http_1.readJson)(req));
|
|
110
|
-
(0, http_1.send)(res, 200, await sandboxes.read(
|
|
114
|
+
(0, http_1.send)(res, 200, await sandboxes.read(sandbox.owner, sandbox.id, (files) => files.search(query)));
|
|
111
115
|
}
|
|
112
116
|
else if (action === 'edits') {
|
|
113
117
|
if (method !== 'POST') {
|
|
@@ -124,7 +128,7 @@ async function handleSandboxFiles(sandboxes, log, principal, sandbox, action, pa
|
|
|
124
128
|
if (method !== 'GET') {
|
|
125
129
|
return (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow: 'GET' });
|
|
126
130
|
}
|
|
127
|
-
await handleChanges(sandboxes,
|
|
131
|
+
await handleChanges(sandboxes, sandbox, res, url);
|
|
128
132
|
}
|
|
129
133
|
}
|
|
130
134
|
catch (e) {
|
|
@@ -140,9 +144,10 @@ async function handleSandboxFiles(sandboxes, log, principal, sandbox, action, pa
|
|
|
140
144
|
exports.handleSandboxFiles = handleSandboxFiles;
|
|
141
145
|
async function handleFile(sandboxes, log, principal, sandbox, path, req, res, url) {
|
|
142
146
|
const method = req.method;
|
|
143
|
-
|
|
147
|
+
// reading, as its owner
|
|
148
|
+
const files = () => sandboxes.files(sandbox.owner, sandbox.id);
|
|
144
149
|
if (method === 'HEAD') {
|
|
145
|
-
const stat = await files.stat(path);
|
|
150
|
+
const stat = await files().stat(path);
|
|
146
151
|
if (!stat) {
|
|
147
152
|
res.writeHead(404, { 'cache-control': 'no-store' });
|
|
148
153
|
res.end();
|
|
@@ -153,11 +158,11 @@ async function handleFile(sandboxes, log, principal, sandbox, path, req, res, ur
|
|
|
153
158
|
}
|
|
154
159
|
else if (method === 'GET') {
|
|
155
160
|
if (url.searchParams.has('stat')) {
|
|
156
|
-
const stat = await files.stat(path);
|
|
161
|
+
const stat = await files().stat(path);
|
|
157
162
|
return stat ? (0, http_1.send)(res, 200, stat) : (0, http_1.send)(res, 404, { error: `${path} does not exist` });
|
|
158
163
|
}
|
|
159
164
|
if (url.searchParams.has('raw')) {
|
|
160
|
-
const raw = await files.raw(path);
|
|
165
|
+
const raw = await files().raw(path);
|
|
161
166
|
const headers = { ...statHeaders(raw.stat), 'content-type': 'application/octet-stream' };
|
|
162
167
|
if (raw.content) {
|
|
163
168
|
res.writeHead(200, { ...headers, etag: `"${raw.sha256}"` });
|
|
@@ -179,7 +184,7 @@ async function handleFile(sandboxes, log, principal, sandbox, path, req, res, ur
|
|
|
179
184
|
});
|
|
180
185
|
return;
|
|
181
186
|
}
|
|
182
|
-
(0, http_1.send)(res, 200, await files.read(path, { offset: intParam(url, 'offset'), limit: intParam(url, 'limit') }));
|
|
187
|
+
(0, http_1.send)(res, 200, await files().read(path, { offset: intParam(url, 'offset'), limit: intParam(url, 'limit') }));
|
|
183
188
|
}
|
|
184
189
|
else if (method === 'PUT') {
|
|
185
190
|
const content = await readBytes(req, sandbox_files_1.MAX_FILE_BYTES);
|
|
@@ -198,10 +203,12 @@ async function handleFile(sandboxes, log, principal, sandbox, path, req, res, ur
|
|
|
198
203
|
(0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow: 'GET, HEAD, PUT' });
|
|
199
204
|
}
|
|
200
205
|
}
|
|
201
|
-
|
|
206
|
+
// the most files one diff may name
|
|
207
|
+
const MAX_DIFF_PATHS = 100;
|
|
208
|
+
async function handleChanges(sandboxes, sandbox, res, url) {
|
|
202
209
|
const format = url.searchParams.get('format') ?? 'summary';
|
|
203
210
|
if (format === 'summary') {
|
|
204
|
-
const files = await sandboxes.read(
|
|
211
|
+
const files = await sandboxes.read(sandbox.owner, sandbox.id, (files) => files.changes());
|
|
205
212
|
return (0, http_1.send)(res, 200, { commit: sandbox.commit, files });
|
|
206
213
|
}
|
|
207
214
|
if (format !== 'diff' && format !== 'patch') {
|
|
@@ -212,7 +219,15 @@ async function handleChanges(sandboxes, principal, sandbox, res, url) {
|
|
|
212
219
|
email: textParam(url, 'email') ?? 'hammerkit@localhost',
|
|
213
220
|
message: textParam(url, 'message', 4000, true) ?? `Changes of sandbox ${sandbox.id}`,
|
|
214
221
|
};
|
|
215
|
-
|
|
222
|
+
// the diff of some files only, as a list of changes opens one; a rename names both its paths
|
|
223
|
+
const paths = url.searchParams.getAll('path');
|
|
224
|
+
if (paths.length > 0 && format !== 'diff') {
|
|
225
|
+
return (0, http_1.send)(res, 400, { error: 'path: only a diff takes paths, a patch is whole' });
|
|
226
|
+
}
|
|
227
|
+
if (paths.length > MAX_DIFF_PATHS || paths.some((path) => path === '' || path.length > 4096 || path.includes('\0'))) {
|
|
228
|
+
return (0, http_1.send)(res, 400, { error: `path: at most ${MAX_DIFF_PATHS}, each a path of the sandbox` });
|
|
229
|
+
}
|
|
230
|
+
const text = await sandboxes.read(sandbox.owner, sandbox.id, (files) => files.diff(format, author, paths.length > 0 ? paths : undefined));
|
|
216
231
|
res.writeHead(200, { 'content-type': 'text/x-diff; charset=utf-8', 'cache-control': 'no-store' });
|
|
217
232
|
res.end(text);
|
|
218
233
|
}
|
|
@@ -822,10 +822,11 @@ class HostSandboxFiles {
|
|
|
822
822
|
return files;
|
|
823
823
|
});
|
|
824
824
|
}
|
|
825
|
-
async diff(format, author) {
|
|
825
|
+
async diff(format, author, paths) {
|
|
826
826
|
return this.withFilesIndex(async (run) => {
|
|
827
827
|
if (format === 'diff') {
|
|
828
|
-
|
|
828
|
+
const only = paths && paths.length > 0 ? ['--', ...paths.map((path) => `:(literal)${path}`)] : [];
|
|
829
|
+
return run(['diff', '--cached', '-M', 'HEAD', ...only], 'read', { maxBuffer: this.maxChangesBytes });
|
|
829
830
|
}
|
|
830
831
|
// a commit of the changes on top of the commit the sandbox is at, which no branch
|
|
831
832
|
// points to, written out as `git format-patch` writes it
|
|
@@ -80,7 +80,7 @@ async function answer(storage, directory, request, out) {
|
|
|
80
80
|
case 'changes':
|
|
81
81
|
return send(await files().changes());
|
|
82
82
|
case 'diff':
|
|
83
|
-
return send(await files().diff(request.format, request.author));
|
|
83
|
+
return send(await files().diff(request.format, request.author, request.paths));
|
|
84
84
|
case 'commit':
|
|
85
85
|
return send((await storage.commit(key, request.author, AbortSignal.timeout(10 * 60000))) ?? null);
|
|
86
86
|
case 'move':
|