hammerkit 2.1.0-next.2 → 2.1.0-next.4
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 +39 -18
- package/dist/optimizer/work-task-cache-description.js +3 -2
- package/dist/planner/image-build.js +5 -0
- package/dist/planner/validate.js +16 -0
- package/dist/planner/work-runtime-docker.js +24 -1
- package/dist/planner/work-runtime-kubernetes.js +37 -16
- package/dist/planner/work-service-id.js +30 -6
- 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/reference-parser.js +108 -43
- package/dist/schema/work-scope-parser.js +8 -0
- package/package.json +1 -1
package/build.schema.json
CHANGED
|
@@ -56,6 +56,31 @@
|
|
|
56
56
|
"description": {
|
|
57
57
|
"type": "string"
|
|
58
58
|
},
|
|
59
|
+
"extend": {
|
|
60
|
+
"type": "string"
|
|
61
|
+
},
|
|
62
|
+
"abstract": {
|
|
63
|
+
"type": "boolean"
|
|
64
|
+
},
|
|
65
|
+
"reset": {
|
|
66
|
+
"type": "array",
|
|
67
|
+
"items": {
|
|
68
|
+
"type": "string",
|
|
69
|
+
"enum": [
|
|
70
|
+
"deps",
|
|
71
|
+
"needs",
|
|
72
|
+
"src",
|
|
73
|
+
"generates",
|
|
74
|
+
"cmds",
|
|
75
|
+
"mounts",
|
|
76
|
+
"envs",
|
|
77
|
+
"labels",
|
|
78
|
+
"build",
|
|
79
|
+
"secrets",
|
|
80
|
+
"capAdd"
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
},
|
|
59
84
|
"envs": {
|
|
60
85
|
"$ref": "#/definitions/hammerkit/properties/envs",
|
|
61
86
|
"description": "Environment values for the current build task\nhttps://hammerkit.dev/docs/build-file/environment-variables"
|
|
@@ -376,23 +401,13 @@
|
|
|
376
401
|
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/description"
|
|
377
402
|
},
|
|
378
403
|
"extend": {
|
|
379
|
-
"
|
|
404
|
+
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/extend"
|
|
405
|
+
},
|
|
406
|
+
"abstract": {
|
|
407
|
+
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/abstract"
|
|
380
408
|
},
|
|
381
409
|
"reset": {
|
|
382
|
-
"
|
|
383
|
-
"items": {
|
|
384
|
-
"type": "string",
|
|
385
|
-
"enum": [
|
|
386
|
-
"deps",
|
|
387
|
-
"needs",
|
|
388
|
-
"src",
|
|
389
|
-
"generates",
|
|
390
|
-
"cmds",
|
|
391
|
-
"mounts",
|
|
392
|
-
"envs",
|
|
393
|
-
"labels"
|
|
394
|
-
]
|
|
395
|
-
}
|
|
410
|
+
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/reset"
|
|
396
411
|
},
|
|
397
412
|
"envs": {
|
|
398
413
|
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/envs"
|
|
@@ -544,10 +559,13 @@
|
|
|
544
559
|
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/description"
|
|
545
560
|
},
|
|
546
561
|
"extend": {
|
|
547
|
-
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/
|
|
562
|
+
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/extend"
|
|
563
|
+
},
|
|
564
|
+
"abstract": {
|
|
565
|
+
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/abstract"
|
|
548
566
|
},
|
|
549
567
|
"reset": {
|
|
550
|
-
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/
|
|
568
|
+
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/reset"
|
|
551
569
|
},
|
|
552
570
|
"envs": {
|
|
553
571
|
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/envs"
|
|
@@ -634,8 +652,11 @@
|
|
|
634
652
|
"extend": {
|
|
635
653
|
"type": "string"
|
|
636
654
|
},
|
|
655
|
+
"abstract": {
|
|
656
|
+
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/abstract"
|
|
657
|
+
},
|
|
637
658
|
"reset": {
|
|
638
|
-
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/
|
|
659
|
+
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/reset"
|
|
639
660
|
},
|
|
640
661
|
"envs": {
|
|
641
662
|
"$ref": "#/definitions/hammerkit/properties/tasks/additionalProperties/anyOf/0/properties/envs"
|
|
@@ -88,7 +88,8 @@ function isInitOf(item, service) {
|
|
|
88
88
|
// Everything that makes a service what a task needing it talks to: its definition, the ids of
|
|
89
89
|
// the tasks it depends on and of its init task, and the services it needs in turn. The source
|
|
90
90
|
// of those tasks and of the service is in the state key (computeStateKey), like a dependency's.
|
|
91
|
-
// Not the service id, which leaves out what a service runs
|
|
91
|
+
// Not the service id, which leaves out what a service runs, and without its name: to a task,
|
|
92
|
+
// a renamed service is the same (getUnnamedWorkServiceId).
|
|
92
93
|
function getWorkServiceCacheIdentity(item, visiting = new Set()) {
|
|
93
94
|
const service = item.data;
|
|
94
95
|
const definition = (0, work_service_1.isContainerWorkService)(service)
|
|
@@ -110,7 +111,7 @@ function getWorkServiceCacheIdentity(item, visiting = new Set()) {
|
|
|
110
111
|
: { namespace: service.namespace };
|
|
111
112
|
return (0, crypto_1.createHash)('sha256')
|
|
112
113
|
.update(JSON.stringify({
|
|
113
|
-
id: (0, work_service_id_1.
|
|
114
|
+
id: (0, work_service_id_1.getUnnamedWorkServiceId)(service),
|
|
114
115
|
...definition,
|
|
115
116
|
ports: service.ports.map((port) => `${port.hostPort ?? ''}:${port.containerPort}`).sort(),
|
|
116
117
|
deps: item.deps.map((dep) => dep.id()).sort(),
|
|
@@ -25,6 +25,11 @@ const METADATA_FILE = '/tmp/hammerkit-build.json';
|
|
|
25
25
|
const IMAGE = /^[a-z0-9][a-z0-9._/:@-]*$/i;
|
|
26
26
|
// The build of a task, with the values of its envs in place
|
|
27
27
|
function parseWorkImageBuild(cwd, build, envs, taskName) {
|
|
28
|
+
// checked here, not in the schema: a base of `extend` may set push for tasks that set their tags
|
|
29
|
+
const needsTags = build.push ? 'push' : build.digest !== undefined ? 'digest' : null;
|
|
30
|
+
if (needsTags && build.tags === undefined) {
|
|
31
|
+
throw new Error(`task ${taskName}: build ${needsTags} needs tags, the names of the image`);
|
|
32
|
+
}
|
|
28
33
|
const context = (0, path_1.join)(cwd, (0, template_value_1.templateValue)(build.context ?? '.', envs));
|
|
29
34
|
const dockerfile = build.dockerfile ? (0, path_1.join)(cwd, (0, template_value_1.templateValue)(build.dockerfile, envs)) : (0, path_1.join)(context, 'Dockerfile');
|
|
30
35
|
const tags = (build.tags === undefined ? [] : Array.isArray(build.tags) ? build.tags : [build.tags]).map((tag) => checkImage((0, template_value_1.templateValue)(tag, envs), 'tag', taskName));
|
package/dist/planner/validate.js
CHANGED
|
@@ -13,6 +13,7 @@ async function* validate(workTree, context) {
|
|
|
13
13
|
yield { type: 'warn', message: `missing description`, item: service };
|
|
14
14
|
}
|
|
15
15
|
if (service.type === 'container-service') {
|
|
16
|
+
yield* warnUnsetEnvs(service.envs, service);
|
|
16
17
|
if (!service.healthcheck) {
|
|
17
18
|
yield { type: 'warn', message: 'missing healthcheck', item: service };
|
|
18
19
|
}
|
|
@@ -52,6 +53,7 @@ async function* validate(workTree, context) {
|
|
|
52
53
|
if (!task.description) {
|
|
53
54
|
yield { type: 'warn', message: `missing description`, item: task };
|
|
54
55
|
}
|
|
56
|
+
yield* warnUnsetEnvs(task.envs, task);
|
|
55
57
|
if (task.type === 'local-task' && task.resources) {
|
|
56
58
|
yield { type: 'warn', message: 'resources are not enforced for a local task', item: task };
|
|
57
59
|
}
|
|
@@ -103,6 +105,20 @@ async function* validate(workTree, context) {
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
exports.validate = validate;
|
|
108
|
+
// An env that reads a variable set nowhere, such as an input of an included file run on its
|
|
109
|
+
// own: the task fails when it starts, and until then `$NAME` stays in what it templates
|
|
110
|
+
function* warnUnsetEnvs(envs, item) {
|
|
111
|
+
for (const replacement of envs.replacements) {
|
|
112
|
+
if (!replacement.available) {
|
|
113
|
+
yield {
|
|
114
|
+
type: 'warn',
|
|
115
|
+
message: `env ${replacement.key} reads $${replacement.name}, which neither the environment nor a .env file sets: ` +
|
|
116
|
+
`it can't start, and $${replacement.key} stays as it is written in its build file`,
|
|
117
|
+
item,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
106
122
|
function hasMixedCycle(item, currentPath) {
|
|
107
123
|
if (currentPath.indexOf(item) >= 0) {
|
|
108
124
|
return [...currentPath, item];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dockerServiceRuntime = exports.getCacheHelperOptions = exports.dockerTaskRuntime = void 0;
|
|
3
|
+
exports.removeLegacyService = exports.dockerServiceRuntime = exports.getCacheHelperOptions = exports.dockerTaskRuntime = void 0;
|
|
4
4
|
const run_labels_1 = require("../docker/run-labels");
|
|
5
5
|
const execute_docker_1 = require("../executer/execute-docker");
|
|
6
6
|
const remove_container_1 = require("../docker/remove-container");
|
|
@@ -14,6 +14,7 @@ const path_1 = require("path");
|
|
|
14
14
|
const tar_1 = require("../utils/tar");
|
|
15
15
|
const plan_work_volume_1 = require("./utils/plan-work-volume");
|
|
16
16
|
const work_instance_id_1 = require("./work-instance-id");
|
|
17
|
+
const work_service_id_1 = require("./work-service-id");
|
|
17
18
|
const stream_1 = require("stream");
|
|
18
19
|
const service_definition_1 = require("./service-definition");
|
|
19
20
|
const image_build_1 = require("./image-build");
|
|
@@ -204,6 +205,7 @@ function dockerServiceRuntime(service, workEnvironment) {
|
|
|
204
205
|
const docker = (0, execute_docker_1.getContainerCli)(workEnvironment);
|
|
205
206
|
return {
|
|
206
207
|
async initialize(state) {
|
|
208
|
+
await removeLegacyService(docker, service);
|
|
207
209
|
const currentServices = await docker.listContainers({
|
|
208
210
|
filters: {
|
|
209
211
|
label: [`hammerkit-id=${(0, work_instance_id_1.getWorkInstanceId)(service)}`],
|
|
@@ -292,6 +294,27 @@ function dockerServiceRuntime(service, workEnvironment) {
|
|
|
292
294
|
};
|
|
293
295
|
}
|
|
294
296
|
exports.dockerServiceRuntime = dockerServiceRuntime;
|
|
297
|
+
// A service an earlier version started, labeled with the id it had then: it goes with its
|
|
298
|
+
// network and secrets, and is recreated under its own id (getLegacyServiceItem).
|
|
299
|
+
async function removeLegacyService(docker, service) {
|
|
300
|
+
const legacy = (0, work_service_id_1.getLegacyServiceItem)(service);
|
|
301
|
+
const containers = await docker.listContainers({
|
|
302
|
+
all: true,
|
|
303
|
+
filters: {
|
|
304
|
+
label: [`hammerkit-id=${(0, work_instance_id_1.getWorkInstanceId)(legacy)}`, 'hammerkit-type=service'],
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
if (containers.length === 0) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
service.status.write('info', `${service.name} was started by an earlier version of hammerkit, recreating it`);
|
|
311
|
+
for (const container of containers) {
|
|
312
|
+
await (0, remove_container_1.removeContainer)(docker.getContainer(container.Id));
|
|
313
|
+
}
|
|
314
|
+
await (0, item_network_1.removeItemNetworks)(docker, legacy);
|
|
315
|
+
await (0, container_secrets_1.removeContainerSecrets)((0, work_instance_id_1.getWorkInstanceId)(legacy));
|
|
316
|
+
}
|
|
317
|
+
exports.removeLegacyService = removeLegacyService;
|
|
295
318
|
async function archiveContainer(docker, environment, item, path) {
|
|
296
319
|
await (0, execution_steps_1.refuseHostLinks)(item, environment);
|
|
297
320
|
await (0, using_container_1.usingContainer)(docker, item, getCacheHelperOptions(item, environment), async (container) => {
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.kubernetesForwardRuntime = exports.isRolledOut = exports.kubernetesServiceRuntime = exports.kubernetesTaskRuntime = exports.getTaskJobContainers = exports.describeFailedJob = exports.recordJobExecution = void 0;
|
|
6
|
+
exports.kubernetesForwardRuntime = exports.isRolledOut = exports.kubernetesServiceRuntime = exports.removeLegacyKubernetesService = exports.kubernetesTaskRuntime = exports.getTaskJobContainers = exports.describeFailedJob = exports.recordJobExecution = void 0;
|
|
7
7
|
const abort_1 = require("../executer/abort");
|
|
8
8
|
const kubernetes_service_1 = require("../executer/kubernetes-service");
|
|
9
9
|
const kubernetes_instance_1 = require("../kubernetes/kubernetes-instance");
|
|
@@ -14,6 +14,7 @@ const ensure_kubernetes_deployment_exists_1 = require("../kubernetes/ensure-kube
|
|
|
14
14
|
const follow_pod_logs_1 = require("../kubernetes/follow-pod-logs");
|
|
15
15
|
const work_item_executions_1 = require("./work-item-executions");
|
|
16
16
|
const service_definition_1 = require("./service-definition");
|
|
17
|
+
const work_service_id_1 = require("./work-service-id");
|
|
17
18
|
const ensure_namespace_1 = require("../kubernetes/ensure-namespace");
|
|
18
19
|
const ensure_persistent_data_1 = require("../kubernetes/ensure-persistent-data");
|
|
19
20
|
const network_gate_1 = require("../kubernetes/network-gate");
|
|
@@ -530,6 +531,35 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
530
531
|
};
|
|
531
532
|
}
|
|
532
533
|
exports.kubernetesTaskRuntime = kubernetesTaskRuntime;
|
|
534
|
+
async function stopKubernetesService(instance, kubernetes, service) {
|
|
535
|
+
const deployments = await instance.appsApi.listNamespacedDeployment({
|
|
536
|
+
namespace: kubernetes.namespace,
|
|
537
|
+
labelSelector: (0, resources_1.getItemSelector)(service, kubernetes),
|
|
538
|
+
});
|
|
539
|
+
for (const deployment of deployments.items) {
|
|
540
|
+
if (deployment.metadata?.name) {
|
|
541
|
+
await instance.appsApi.deleteNamespacedDeployment({
|
|
542
|
+
name: deployment.metadata.name,
|
|
543
|
+
namespace: kubernetes.namespace,
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
await (0, secrets_1.removeKubernetesSecret)(instance, kubernetes, service);
|
|
548
|
+
// the limits go last, once the service's pods ended
|
|
549
|
+
await (0, network_policy_1.removeAllKubernetesItemNetworks)(instance, kubernetes, service);
|
|
550
|
+
}
|
|
551
|
+
async function removeLegacyKubernetesService(instance, kubernetes, service) {
|
|
552
|
+
const legacy = (0, work_service_id_1.getLegacyServiceItem)(service);
|
|
553
|
+
const deployments = await instance.appsApi.listNamespacedDeployment({
|
|
554
|
+
namespace: kubernetes.namespace,
|
|
555
|
+
labelSelector: (0, resources_1.getItemSelector)(legacy, kubernetes),
|
|
556
|
+
});
|
|
557
|
+
if (deployments.items.length > 0) {
|
|
558
|
+
service.status.write('info', `${service.name} was started by an earlier version of hammerkit, recreating it`);
|
|
559
|
+
await stopKubernetesService(instance, kubernetes, legacy);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
exports.removeLegacyKubernetesService = removeLegacyKubernetesService;
|
|
533
563
|
function kubernetesServiceRuntime(service, kubernetes) {
|
|
534
564
|
const instance = (0, kubernetes_instance_1.createKubernetesInstances)(kubernetes);
|
|
535
565
|
return {
|
|
@@ -541,6 +571,11 @@ function kubernetesServiceRuntime(service, kubernetes) {
|
|
|
541
571
|
// a service run starts every service: one that did not change stays as it is (execute)
|
|
542
572
|
return;
|
|
543
573
|
}
|
|
574
|
+
// one an earlier version started, under the id it had then (getLegacyServiceItem); on a
|
|
575
|
+
// server a run finds only objects of its own
|
|
576
|
+
if (!kubernetes.server) {
|
|
577
|
+
await removeLegacyKubernetesService(instance, kubernetes, service);
|
|
578
|
+
}
|
|
544
579
|
const deployments = await instance.appsApi.listNamespacedDeployment({
|
|
545
580
|
namespace: kubernetes.namespace,
|
|
546
581
|
labelSelector: (0, resources_1.getItemSelector)(service, kubernetes),
|
|
@@ -568,21 +603,7 @@ function kubernetesServiceRuntime(service, kubernetes) {
|
|
|
568
603
|
await (0, store_kubernetes_data_1.storeKubernetesData)(service, kubernetes, instance, environment, path);
|
|
569
604
|
},
|
|
570
605
|
async stop() {
|
|
571
|
-
|
|
572
|
-
namespace: kubernetes.namespace,
|
|
573
|
-
labelSelector: (0, resources_1.getItemSelector)(service, kubernetes),
|
|
574
|
-
});
|
|
575
|
-
for (const deployment of deployments.items) {
|
|
576
|
-
if (deployment.metadata?.name) {
|
|
577
|
-
await instance.appsApi.deleteNamespacedDeployment({
|
|
578
|
-
name: deployment.metadata.name,
|
|
579
|
-
namespace: kubernetes.namespace,
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
await (0, secrets_1.removeKubernetesSecret)(instance, kubernetes, service);
|
|
584
|
-
// the limits go last, once the service's pods ended
|
|
585
|
-
await (0, network_policy_1.removeAllKubernetesItemNetworks)(instance, kubernetes, service);
|
|
606
|
+
await stopKubernetesService(instance, kubernetes, service);
|
|
586
607
|
},
|
|
587
608
|
async execute(environment, options) {
|
|
588
609
|
const name = (0, resources_1.getResourceName)(service, kubernetes);
|
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getWorkServiceId = void 0;
|
|
3
|
+
exports.getLegacyServiceItem = exports.getUnnamedWorkServiceId = exports.getWorkServiceId = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const work_service_1 = require("./work-service");
|
|
6
6
|
const portable_path_1 = require("./utils/portable-path");
|
|
7
7
|
const plan_work_volume_1 = require("./utils/plan-work-volume");
|
|
8
|
+
// The id of a service: its name in the work tree and what it runs from. Two services of
|
|
9
|
+
// one build file may run the same image from the same directory and differ only in their
|
|
10
|
+
// command, envs or network (an app's api and its worker); the name gives each its own
|
|
11
|
+
// container, Deployment, claim and NetworkPolicy. What the service runs is left out, so
|
|
12
|
+
// a service whose command changed is found again and recreated (getServiceDefinitionHash).
|
|
13
|
+
function getWorkServiceId(service) {
|
|
14
|
+
return hashServiceId({ name: service.name, ...getServiceShape(service) });
|
|
15
|
+
}
|
|
16
|
+
exports.getWorkServiceId = getWorkServiceId;
|
|
17
|
+
// The id without the name, which is all the id was up to 2.0. A task that needs the service
|
|
18
|
+
// caches by it (getWorkServiceCacheIdentity): to the task, a renamed service is the same.
|
|
19
|
+
// A container or Deployment an earlier version started carries it (getLegacyServiceItem).
|
|
20
|
+
function getUnnamedWorkServiceId(service) {
|
|
21
|
+
return hashServiceId(getServiceShape(service));
|
|
22
|
+
}
|
|
23
|
+
exports.getUnnamedWorkServiceId = getUnnamedWorkServiceId;
|
|
24
|
+
// The service under the id an earlier version labeled what it started with. A container or
|
|
25
|
+
// Deployment of it goes once, and the service starts anew under its own id, instead of
|
|
26
|
+
// beside the old one on the same host ports, where neither `up` nor `down` would find it.
|
|
27
|
+
function getLegacyServiceItem(item) {
|
|
28
|
+
return { ...item, id: () => getUnnamedWorkServiceId(item.data) };
|
|
29
|
+
}
|
|
30
|
+
exports.getLegacyServiceItem = getLegacyServiceItem;
|
|
31
|
+
function hashServiceId(shape) {
|
|
32
|
+
return (0, crypto_1.createHash)('sha1').update(JSON.stringify(shape)).digest('hex');
|
|
33
|
+
}
|
|
8
34
|
// Paths are made project-relative (portablePath) so a service id is identical
|
|
9
35
|
// wherever the project is checked out, like a task id.
|
|
10
|
-
function
|
|
36
|
+
function getServiceShape(service) {
|
|
11
37
|
const portable = (path) => (0, portable_path_1.portablePath)(service.projectRoot, path);
|
|
12
|
-
|
|
38
|
+
return (0, work_service_1.isContainerWorkService)(service)
|
|
13
39
|
? {
|
|
14
40
|
cwd: portable(service.cwd),
|
|
15
41
|
image: service.image,
|
|
@@ -31,8 +57,6 @@ function getWorkServiceId(service) {
|
|
|
31
57
|
context: service.context,
|
|
32
58
|
selector: service.selector,
|
|
33
59
|
kubeconfig: portable(service.kubeconfig),
|
|
34
|
-
}
|
|
35
|
-
return (0, crypto_1.createHash)('sha1').update(jsonData).digest('hex');
|
|
60
|
+
};
|
|
36
61
|
}
|
|
37
|
-
exports.getWorkServiceId = getWorkServiceId;
|
|
38
62
|
//# sourceMappingURL=work-service-id.js.map
|
|
@@ -14,12 +14,27 @@ const resources_schema_1 = require("./resources-schema");
|
|
|
14
14
|
const runner_schema_1 = require("./runner-schema");
|
|
15
15
|
const network_schema_1 = require("./network-schema");
|
|
16
16
|
// what `extend` adds to (the rest, e.g. `image` or `shell`, the task just overrides)
|
|
17
|
-
exports.RESET_PROPERTIES = [
|
|
17
|
+
exports.RESET_PROPERTIES = [
|
|
18
|
+
'deps',
|
|
19
|
+
'needs',
|
|
20
|
+
'src',
|
|
21
|
+
'generates',
|
|
22
|
+
'cmds',
|
|
23
|
+
'mounts',
|
|
24
|
+
'envs',
|
|
25
|
+
'labels',
|
|
26
|
+
'build',
|
|
27
|
+
'secrets',
|
|
28
|
+
'capAdd',
|
|
29
|
+
];
|
|
18
30
|
exports.buildFileBaseTaskSchema = (0, zod_1.object)({
|
|
19
31
|
deps: (0, zod_1.array)((0, zod_1.string)()).optional(),
|
|
20
32
|
needs: (0, zod_1.array)(build_file_need_schema_1.buildFileNeedSchema).optional(),
|
|
21
33
|
description: (0, zod_1.string)().optional(),
|
|
22
34
|
extend: (0, zod_1.string)().optional(),
|
|
35
|
+
// true: a base other tasks extend, which doesn't run itself: not listed, no dependency, not
|
|
36
|
+
// published by a server. Unlike a task, it passes on its secrets, resources and claim too.
|
|
37
|
+
abstract: (0, zod_1.boolean)().optional(),
|
|
23
38
|
// properties of the `extend` base this task does not inherit
|
|
24
39
|
reset: (0, zod_1.array)((0, zod_1.enum)(exports.RESET_PROPERTIES)).optional(),
|
|
25
40
|
envs: envs_schema_1.envsSchema.optional(),
|
|
@@ -57,17 +57,14 @@ exports.buildFileImageBuildSchema = (0, zod_1.object)({
|
|
|
57
57
|
.describe('the platforms to build for, such as linux/amd64 and linux/arm64, as docker build --platform'),
|
|
58
58
|
})
|
|
59
59
|
.strict()
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})
|
|
63
|
-
.refine((build) => build.digest === undefined || build.tags !== undefined, {
|
|
64
|
-
message: 'digest needs tags, the name the digest is written with',
|
|
65
|
-
})
|
|
60
|
+
// that push and digest need tags is checked once `extend` has merged in the base's
|
|
61
|
+
// (parseWorkImageBuild): a base may set push for tasks that set their tags
|
|
66
62
|
.describe('builds a Dockerfile with BuildKit, as docker build does');
|
|
67
63
|
// A task that builds an image: hammerkit runs BuildKit for it, so it names no image, commands or
|
|
68
|
-
// shell of its own
|
|
64
|
+
// shell of its own and takes no arguments. It may extend another task, which merges `build` key
|
|
65
|
+
// by key (applySchemaExtension).
|
|
69
66
|
exports.buildFileImageBuildTaskSchema = build_file_base_task_schema_1.buildFileBaseTaskSchema
|
|
70
|
-
.omit({
|
|
67
|
+
.omit({ cmds: true, shell: true, args: true })
|
|
71
68
|
.extend({
|
|
72
69
|
build: exports.buildFileImageBuildSchema,
|
|
73
70
|
volumeSize: size_schema_1.sizeSchema.describe('size of its claim on Kubernetes, e.g. 10Gi').optional(),
|
|
@@ -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.
|
package/package.json
CHANGED