hammerkit 1.27.0-next.3 → 1.27.0-next.30
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 +188 -0
- package/dist/cache/backends/local-cache-backend.js +6 -0
- package/dist/cache/backends/registry-cache-backend.js +2 -2
- package/dist/cache/explain.js +17 -0
- package/dist/cli.js +2 -0
- package/dist/docker/item-network.js +13 -5
- package/dist/executer/deadline.js +17 -3
- package/dist/executer/deferred-restore.js +36 -0
- package/dist/executer/docker-service.js +30 -8
- package/dist/executer/docker-task.js +21 -1
- package/dist/executer/event-cache.js +20 -2
- package/dist/executer/execute-work-service.js +2 -0
- package/dist/executer/execute-work-task.js +10 -3
- package/dist/executer/execution-steps.js +25 -4
- package/dist/executer/reset-work-tree.js +4 -0
- package/dist/executer/scheduler/enqueue-next.js +57 -6
- package/dist/executer/scheduler/state-key.js +42 -5
- package/dist/executer/watch-loop.js +4 -1
- package/dist/harness/connect.js +20 -6
- package/dist/harness/mcp-command.js +22 -6
- package/dist/harness/mcp.js +63 -114
- package/dist/harness/opencode.js +158 -50
- package/dist/harness/pi.js +29 -0
- package/dist/harness/sandbox-client.js +168 -17
- package/dist/harness/service-tools.js +141 -0
- package/dist/harness/task-tools.js +221 -0
- package/dist/kubernetes/apply.js +27 -16
- package/dist/kubernetes/await-running-state.js +59 -13
- package/dist/kubernetes/claim-layout.js +71 -0
- package/dist/kubernetes/cluster-state.js +245 -0
- package/dist/kubernetes/ensure-http-route.js +1 -1
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +35 -12
- package/dist/kubernetes/ensure-kubernetes-persistent-volume-claim-exists.js +1 -1
- package/dist/kubernetes/ensure-kubernetes-service-exists.js +6 -9
- package/dist/kubernetes/ensure-persistent-data.js +30 -20
- package/dist/kubernetes/follow-pod-logs.js +182 -0
- package/dist/kubernetes/get-service-ip.js +2 -2
- package/dist/kubernetes/job-placement.js +36 -12
- package/dist/kubernetes/job-secrets.js +33 -19
- package/dist/kubernetes/kept-claims.js +22 -10
- package/dist/kubernetes/network-policy.js +85 -27
- package/dist/kubernetes/remove-persistent-data.js +3 -1
- package/dist/kubernetes/resources.js +25 -3
- package/dist/kubernetes/restore-kubernetes-data.js +9 -3
- package/dist/kubernetes/sandbox-runner.js +628 -0
- package/dist/kubernetes/secrets.js +7 -11
- package/dist/kubernetes/volumes.js +6 -3
- package/dist/main.js +2 -0
- package/dist/network/egress-proxy.js +45 -6
- package/dist/optimizer/calculate-checksum.js +3 -2
- package/dist/optimizer/check-key.js +94 -0
- package/dist/optimizer/check-keys.js +64 -0
- package/dist/optimizer/get-work-cache-stats.js +17 -3
- package/dist/optimizer/work-task-cache-description.js +51 -1
- package/dist/planner/utils/append-work-dependencies.js +10 -5
- package/dist/planner/utils/append-work-service.js +19 -1
- package/dist/planner/utils/append-work-task.js +18 -3
- package/dist/planner/utils/get-work-runtime.js +6 -1
- package/dist/planner/utils/normalize-path.js +19 -1
- package/dist/planner/utils/parse-work-mount.js +7 -1
- package/dist/planner/utils/parse-work-port.js +4 -1
- package/dist/planner/utils/task-arguments.js +3 -0
- package/dist/planner/validate.js +22 -0
- package/dist/planner/work-network.js +3 -1
- package/dist/planner/work-runtime-aggregate.js +32 -0
- package/dist/planner/work-runtime-docker.js +2 -1
- package/dist/planner/work-runtime-kubernetes.js +124 -48
- package/dist/planner/work-runtime-local.js +2 -1
- package/dist/planner/work-task.js +6 -1
- package/dist/program.js +31 -10
- package/dist/remote/device-login.js +7 -2
- package/dist/remote/host-config.js +69 -3
- package/dist/remote/remote-commands.js +30 -7
- package/dist/remote/remote-work-commands.js +426 -45
- package/dist/remote/server-client.js +15 -2
- package/dist/remote/token-source.js +64 -26
- package/dist/run-program.js +9 -0
- package/dist/schema/build-file-base-task-schema.js +8 -1
- package/dist/schema/build-file-container-service-schema.js +12 -0
- package/dist/schema/build-file-container-task-schema.js +16 -1
- package/dist/schema/build-file-include-schema.js +18 -4
- package/dist/schema/build-file-kubernetes-service-schema.js +2 -0
- package/dist/schema/build-file-task-schema.js +5 -1
- package/dist/schema/capabilities-schema.js +56 -0
- package/dist/schema/reference-parser.js +120 -11
- package/dist/schema/schema-parser.js +92 -41
- package/dist/schema/work-scope-parser.js +33 -10
- package/dist/secrets/command-secret-provider.js +3 -1
- package/dist/secrets/github-app-token-command.js +3 -1
- package/dist/secrets/secret-catalog.js +43 -19
- package/dist/server/accounts-api.js +3 -1
- package/dist/server/approvals-api.js +1 -1
- package/dist/server/checks-api.js +83 -0
- package/dist/server/checks.js +116 -0
- package/dist/server/definitions-api.js +66 -3
- package/dist/server/endpoints.js +739 -0
- package/dist/server/executor.js +57 -5
- package/dist/server/kubernetes-backend.js +367 -65
- package/dist/server/kubernetes-sandbox-storage.js +48 -3
- package/dist/server/oauth.js +12 -1
- package/dist/server/plan.js +188 -103
- package/dist/server/policy.js +32 -2
- package/dist/server/repo-access.js +5 -0
- package/dist/server/run-plan.js +50 -19
- package/dist/server/run-request.js +58 -3
- package/dist/server/run-worker.js +245 -12
- package/dist/server/runs.js +410 -27
- package/dist/server/sandbox-pod.js +28 -0
- package/dist/server/sandbox-storage.js +23 -0
- package/dist/server/sandboxes-api.js +10 -4
- package/dist/server/sandboxes.js +8 -0
- package/dist/server/server-command.js +39 -20
- package/dist/server/server-config.js +255 -14
- package/dist/server/server.js +269 -15
- package/dist/server/service-runs.js +82 -0
- package/dist/utils/abort-on-signals.js +46 -6
- package/dist/utils/tar.js +36 -0
- package/dist/utils/terminal-prompt.js +53 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizePath = void 0;
|
|
3
|
+
exports.normalizeHostPath = exports.getHomeReference = exports.normalizePath = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
function normalizePath(cwd, pwd, path) {
|
|
6
6
|
if (path.startsWith('/')) {
|
|
@@ -14,4 +14,22 @@ function normalizePath(cwd, pwd, path) {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
exports.normalizePath = normalizePath;
|
|
17
|
+
// What a path of the host starts with to name the home directory: `~` and `$HOME`, and
|
|
18
|
+
// `$PWD`, which in a mount has always meant the home directory, not the project it reads like
|
|
19
|
+
function getHomeReference(path) {
|
|
20
|
+
for (const reference of ['~', '$HOME']) {
|
|
21
|
+
if (path === reference || path.startsWith(`${reference}/`) || path.startsWith(`${reference}\\`)) {
|
|
22
|
+
return reference;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return path.startsWith('$PWD') ? '$PWD' : null;
|
|
26
|
+
}
|
|
27
|
+
exports.getHomeReference = getHomeReference;
|
|
28
|
+
// A path of the host in a mount: in the home directory when it starts with one of the
|
|
29
|
+
// references above, else in the directory of the build file unless it is absolute
|
|
30
|
+
function normalizeHostPath(cwd, home, path) {
|
|
31
|
+
const reference = getHomeReference(path);
|
|
32
|
+
return reference ? (0, path_1.join)(home, path.substring(reference.length)) : normalizePath(cwd, home, path);
|
|
33
|
+
}
|
|
34
|
+
exports.normalizeHostPath = normalizeHostPath;
|
|
17
35
|
//# sourceMappingURL=normalize-path.js.map
|
|
@@ -7,6 +7,12 @@ const path_1 = require("path");
|
|
|
7
7
|
function parseWorkMount(cwd, dir) {
|
|
8
8
|
const parts = dir.split(':');
|
|
9
9
|
if (parts.length === 1) {
|
|
10
|
+
const home = (0, normalize_path_1.getHomeReference)(dir);
|
|
11
|
+
if (home === '~' || home === '$HOME') {
|
|
12
|
+
// the container has no such directory: the same path on both sides would be one of the
|
|
13
|
+
// project there (`$PWD` has always been, so it stays)
|
|
14
|
+
throw new Error(`mount ${dir} is in the home directory, name where it goes in the container (${dir}:/path)`);
|
|
15
|
+
}
|
|
10
16
|
return parseLocalMount(cwd, dir, dir, dir, false);
|
|
11
17
|
}
|
|
12
18
|
else if (parts.length === 2) {
|
|
@@ -22,7 +28,7 @@ function parseWorkMount(cwd, dir) {
|
|
|
22
28
|
exports.parseWorkMount = parseWorkMount;
|
|
23
29
|
function parseLocalMount(cwd, localPath, containerPath, mount, readOnly) {
|
|
24
30
|
return {
|
|
25
|
-
localPath: (0, normalize_path_1.
|
|
31
|
+
localPath: (0, normalize_path_1.normalizeHostPath)(cwd, (0, os_1.homedir)(), localPath),
|
|
26
32
|
containerPath: (0, normalize_path_1.normalizePath)(cwd, cwd, containerPath),
|
|
27
33
|
isFile: (0, path_1.extname)(localPath).length > 1,
|
|
28
34
|
mount,
|
|
@@ -8,7 +8,10 @@ function parseWorkPort(port) {
|
|
|
8
8
|
return { containerPort: port, hostPort: port };
|
|
9
9
|
}
|
|
10
10
|
else if (parts.length === 2) {
|
|
11
|
-
|
|
11
|
+
// `0:80` is not published, as an empty host port: 0 (a free port) is for the endpoints
|
|
12
|
+
// of a server only
|
|
13
|
+
const hostPort = parsePort(parts[0], true);
|
|
14
|
+
return { containerPort: parsePort(parts[1], false), hostPort: hostPort === 0 ? null : hostPort };
|
|
12
15
|
}
|
|
13
16
|
else {
|
|
14
17
|
throw new Error(`invalid port ${port}`);
|
|
@@ -101,6 +101,9 @@ function applyArguments(selection, args, keepCache = false) {
|
|
|
101
101
|
if (item.type === 'kubernetes-service') {
|
|
102
102
|
throw new Error(`service ${item.name} is a kubernetes service and has no cmd for the arguments after --`);
|
|
103
103
|
}
|
|
104
|
+
if (item.args === false) {
|
|
105
|
+
throw new Error(`${item.type === 'container-service' ? 'service' : 'task'} ${item.name} takes no arguments after -- (args: false)`);
|
|
106
|
+
}
|
|
104
107
|
const target = getArgumentsTarget(item);
|
|
105
108
|
if (!target) {
|
|
106
109
|
throw new Error(item.type === 'container-service'
|
package/dist/planner/validate.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.checkIfContextExists = exports.hasDependencyCycle = exports.hasNeedCycle
|
|
|
4
4
|
const read_build_file_1 = require("../parser/read-build-file");
|
|
5
5
|
const plan_work_tasks_1 = require("./utils/plan-work-tasks");
|
|
6
6
|
const unreferenced_build_file_envs_1 = require("./unreferenced-build-file-envs");
|
|
7
|
+
const normalize_path_1 = require("./utils/normalize-path");
|
|
7
8
|
async function* validate(workTree, context) {
|
|
8
9
|
const cycleItems = [];
|
|
9
10
|
for (const item of (0, plan_work_tasks_1.iterateWorkServices)(workTree)) {
|
|
@@ -16,6 +17,10 @@ async function* validate(workTree, context) {
|
|
|
16
17
|
yield { type: 'warn', message: 'missing healthcheck', item: service };
|
|
17
18
|
}
|
|
18
19
|
for (const mount of service.mounts) {
|
|
20
|
+
const pwd = getPwdMountWarning(mount);
|
|
21
|
+
if (pwd) {
|
|
22
|
+
yield { type: 'warn', message: pwd, item: service };
|
|
23
|
+
}
|
|
19
24
|
if (!(await context.file.exists(mount.localPath))) {
|
|
20
25
|
yield {
|
|
21
26
|
type: 'warn',
|
|
@@ -62,6 +67,12 @@ async function* validate(workTree, context) {
|
|
|
62
67
|
item: task,
|
|
63
68
|
};
|
|
64
69
|
}
|
|
70
|
+
for (const mount of task.type === 'container-task' ? task.mounts : []) {
|
|
71
|
+
const pwd = getPwdMountWarning(mount);
|
|
72
|
+
if (pwd) {
|
|
73
|
+
yield { type: 'warn', message: pwd, item: task };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
65
76
|
for (const src of task.src) {
|
|
66
77
|
if (!(await context.file.exists(src.absolutePath))) {
|
|
67
78
|
yield {
|
|
@@ -146,4 +157,15 @@ async function checkIfContextExists(service, context) {
|
|
|
146
157
|
return false;
|
|
147
158
|
}
|
|
148
159
|
exports.checkIfContextExists = checkIfContextExists;
|
|
160
|
+
// `$PWD` in a mount is the home directory, which reads like a path of the project
|
|
161
|
+
function getPwdMountWarning(mount) {
|
|
162
|
+
const source = mount.mount.split(':')[0];
|
|
163
|
+
if ((0, normalize_path_1.getHomeReference)(source) !== '$PWD') {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const rest = source.substring('$PWD'.length);
|
|
167
|
+
const home = rest === '' || rest.startsWith('/') || rest.startsWith('\\') ? `~${rest}` : '~/…';
|
|
168
|
+
return (`mount ${source} is ${mount.localPath}: $PWD in a mount is the home directory, not the project. ` +
|
|
169
|
+
`Write ${home} for the home directory, or a relative path for the project`);
|
|
170
|
+
}
|
|
149
171
|
//# sourceMappingURL=validate.js.map
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyNetworkCeiling = exports.formatNetwork = exports.getTcpForwards = exports.matchesHost = exports.isLimitedNetwork = exports.toNetworkSchema = exports.exceedsNetwork = exports.getEffectiveNetwork = exports.limitNetwork = exports.parseNetworkOption = exports.parseWorkNetwork = exports.OPEN_NETWORK = void 0;
|
|
4
4
|
const network_schema_1 = require("../schema/network-schema");
|
|
5
|
+
const work_task_1 = require("./work-task");
|
|
5
6
|
exports.OPEN_NETWORK = { type: 'open' };
|
|
6
7
|
function parseWorkNetwork(schema) {
|
|
7
8
|
if (!schema || schema === 'open') {
|
|
@@ -153,7 +154,8 @@ exports.formatNetwork = formatNetwork;
|
|
|
153
154
|
function applyNetworkCeiling(workTree, ceiling) {
|
|
154
155
|
const limit = ceiling && isLimitedNetwork(ceiling) ? ceiling : null;
|
|
155
156
|
if (limit) {
|
|
156
|
-
|
|
157
|
+
// an aggregate runs nothing, so there is nothing of it to limit
|
|
158
|
+
const local = Object.values(workTree.tasks).find((task) => task.data.type === 'local-task' && !(0, work_task_1.isAggregateTask)(task.data));
|
|
157
159
|
if (local) {
|
|
158
160
|
throw new Error(`--network ${formatNetwork(limit)} needs every task in a container, ` +
|
|
159
161
|
`hammerkit can't limit the network of the local task ${local.name}`);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aggregateWorkRuntime = void 0;
|
|
4
|
+
// An aggregate runs nothing, so it touches nothing: no pid or state file in its
|
|
5
|
+
// directory (on a server that is a checkout it doesn't trust), no outputs.
|
|
6
|
+
function aggregateWorkRuntime() {
|
|
7
|
+
return {
|
|
8
|
+
async initialize() {
|
|
9
|
+
// nothing to prepare
|
|
10
|
+
},
|
|
11
|
+
async remove() {
|
|
12
|
+
// it has no outputs of its own
|
|
13
|
+
},
|
|
14
|
+
async execute() {
|
|
15
|
+
// its state stays running, and executeWorkTask completes it
|
|
16
|
+
},
|
|
17
|
+
async stop() {
|
|
18
|
+
// nothing is running
|
|
19
|
+
},
|
|
20
|
+
async archive() {
|
|
21
|
+
// never pushed, see pushToBackend
|
|
22
|
+
},
|
|
23
|
+
async restore() {
|
|
24
|
+
// never a hit, see checkCacheState
|
|
25
|
+
},
|
|
26
|
+
async currentStateKey() {
|
|
27
|
+
return null;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.aggregateWorkRuntime = aggregateWorkRuntime;
|
|
32
|
+
//# sourceMappingURL=work-runtime-aggregate.js.map
|
|
@@ -12,6 +12,7 @@ const event_cache_1 = require("../executer/event-cache");
|
|
|
12
12
|
const get_docker_executor_1 = require("../executer/get-docker-executor");
|
|
13
13
|
const path_1 = require("path");
|
|
14
14
|
const tar_1 = require("tar");
|
|
15
|
+
const tar_2 = require("../utils/tar");
|
|
15
16
|
const plan_work_volume_1 = require("./utils/plan-work-volume");
|
|
16
17
|
const work_instance_id_1 = require("./work-instance-id");
|
|
17
18
|
const stream_1 = require("stream");
|
|
@@ -302,7 +303,7 @@ async function archiveContainer(docker, environment, item, path) {
|
|
|
302
303
|
for (const generatedArchive of (0, event_cache_1.getArchivePaths)(item.data, path)) {
|
|
303
304
|
// a file output is a bind mount of a host file, so archive it from the host
|
|
304
305
|
const readable = hostFiles.has(generatedArchive.path)
|
|
305
|
-
? stream_1.Readable.from((0,
|
|
306
|
+
? stream_1.Readable.from((0, tar_2.packArchive)({ cwd: (0, path_1.dirname)(generatedArchive.path) }, [(0, path_1.basename)(generatedArchive.path)]))
|
|
306
307
|
: await container.getArchive({
|
|
307
308
|
path: generatedArchive.path,
|
|
308
309
|
});
|
|
@@ -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.kubernetesServiceRuntime = exports.kubernetesTaskRuntime = exports.describeFailedJob = void 0;
|
|
6
|
+
exports.kubernetesForwardRuntime = exports.kubernetesServiceRuntime = exports.kubernetesTaskRuntime = exports.getTaskJobContainers = exports.describeFailedJob = 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");
|
|
@@ -11,6 +11,7 @@ const replace_env_variables_1 = require("../environment/replace-env-variables");
|
|
|
11
11
|
const apply_1 = require("../kubernetes/apply");
|
|
12
12
|
const ensure_kubernetes_service_exists_1 = require("../kubernetes/ensure-kubernetes-service-exists");
|
|
13
13
|
const ensure_kubernetes_deployment_exists_1 = require("../kubernetes/ensure-kubernetes-deployment-exists");
|
|
14
|
+
const follow_pod_logs_1 = require("../kubernetes/follow-pod-logs");
|
|
14
15
|
const service_definition_1 = require("./service-definition");
|
|
15
16
|
const ensure_namespace_1 = require("../kubernetes/ensure-namespace");
|
|
16
17
|
const ensure_persistent_data_1 = require("../kubernetes/ensure-persistent-data");
|
|
@@ -34,11 +35,12 @@ const job_placement_1 = require("../kubernetes/job-placement");
|
|
|
34
35
|
const network_policy_1 = require("../kubernetes/network-policy");
|
|
35
36
|
const run_id_1 = require("../utils/run-id");
|
|
36
37
|
const work_network_1 = require("./work-network");
|
|
38
|
+
const sandbox_runner_1 = require("../kubernetes/sandbox-runner");
|
|
37
39
|
const work_secret_1 = require("./work-secret");
|
|
38
40
|
async function listJobNames(instance, kubernetes, task) {
|
|
39
41
|
const jobs = await instance.batchApi.listNamespacedJob({
|
|
40
42
|
namespace: kubernetes.namespace,
|
|
41
|
-
labelSelector:
|
|
43
|
+
labelSelector: (0, resources_1.getItemSelector)(task, kubernetes),
|
|
42
44
|
});
|
|
43
45
|
return jobs.items.flatMap((job) => (job.metadata?.name ? [job.metadata.name] : []));
|
|
44
46
|
}
|
|
@@ -125,6 +127,43 @@ async function describeFailedJob(instance, kubernetes, task, job, container, sec
|
|
|
125
127
|
return undefined;
|
|
126
128
|
}
|
|
127
129
|
exports.describeFailedJob = describeFailedJob;
|
|
130
|
+
/**
|
|
131
|
+
* The containers of the Job of a command: the network gate first, nothing runs before the
|
|
132
|
+
* item's policy holds, then the init containers that read its secrets, then the command. The
|
|
133
|
+
* proxy's token (`network.secretEnv`) reaches the init containers through `secretSpec` only:
|
|
134
|
+
* the command's container gets the proxy variables of a limited network without it. A task that
|
|
135
|
+
* adds capabilities gets them in the sandbox's RuntimeClass only.
|
|
136
|
+
*/
|
|
137
|
+
function getTaskJobContainers(options) {
|
|
138
|
+
const { task, cmd, envs, secrets, network, secretSpec, kubernetes } = options;
|
|
139
|
+
// the arguments after `--` keep their `$` as text, Kubernetes expands `$(NAME)`
|
|
140
|
+
const command = secretSpec.command(task.data.shell, (0, task_arguments_1.getKubernetesCommandText)(cmd));
|
|
141
|
+
const initContainers = [...network.initContainers, ...secretSpec.initContainers];
|
|
142
|
+
return {
|
|
143
|
+
...(initContainers.length > 0 ? { initContainers } : {}),
|
|
144
|
+
containers: [
|
|
145
|
+
{
|
|
146
|
+
image: task.data.image,
|
|
147
|
+
// through the task's shell, as on Docker
|
|
148
|
+
command: command.command,
|
|
149
|
+
args: command.args,
|
|
150
|
+
workingDir: cmd.cwd,
|
|
151
|
+
env: [
|
|
152
|
+
...Object.entries(envs).map(([key, value]) => ({ name: key, value })),
|
|
153
|
+
...secrets.env,
|
|
154
|
+
...network.env,
|
|
155
|
+
...command.env,
|
|
156
|
+
],
|
|
157
|
+
name: options.container,
|
|
158
|
+
volumeMounts: [...options.mounts, ...secrets.mounts, ...secretSpec.mounts],
|
|
159
|
+
...(0, container_resources_1.getKubernetesResources)(task.data.resources),
|
|
160
|
+
...(0, job_placement_1.getContainerSecurity)(kubernetes, task.data.capAdd),
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
...(0, job_placement_1.getPodRuntimeClass)({ name: task.name, capAdd: task.data.capAdd }, kubernetes),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
exports.getTaskJobContainers = getTaskJobContainers;
|
|
128
167
|
function kubernetesTaskRuntime(task, kubernetes) {
|
|
129
168
|
const instance = (0, kubernetes_instance_1.createKubernetesInstances)(kubernetes);
|
|
130
169
|
// on a server that keeps them, the task's claim stays after the run with the state of its
|
|
@@ -153,6 +192,28 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
153
192
|
const envs = (0, replace_env_variables_1.getEnvironmentVariables)(task.data.envs);
|
|
154
193
|
const persistence = await (0, volumes_1.getKubernetesPersistence)(task, kubernetes);
|
|
155
194
|
const workspace = (0, volumes_1.getWorkspacePodSpec)(kubernetes, persistence, { name: task.name, pool: task.data.pool });
|
|
195
|
+
// a shell of a sandbox: its commands go into the sandbox's runner, when it has one now
|
|
196
|
+
if ((0, sandbox_runner_1.canUseRunner)(task, kubernetes, persistence)) {
|
|
197
|
+
try {
|
|
198
|
+
const result = await (0, sandbox_runner_1.executeInRunner)(instance, task, kubernetes, persistence, options.abort);
|
|
199
|
+
if (result.type === 'crash') {
|
|
200
|
+
options.state.set({ stateKey: options.stateKey, type: 'crash', exitCode: result.exitCode });
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
// stopped while the runner started: no Job for it either
|
|
204
|
+
if (result.type === 'canceled' || options.abort.aborted) {
|
|
205
|
+
options.state.set({ stateKey: options.stateKey, type: 'canceled' });
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (result.type === 'done') {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch (e) {
|
|
213
|
+
options.state.set({ stateKey: options.stateKey, type: 'error', errorMessage: (0, log_1.getErrorMessage)(e) });
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
156
217
|
await (0, ensure_namespace_1.ensureNamespace)(instance, kubernetes.namespace);
|
|
157
218
|
try {
|
|
158
219
|
// the task writes to it now: what it holds stops being the outputs of a state, and
|
|
@@ -166,10 +227,11 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
166
227
|
}
|
|
167
228
|
const server = kubernetes.server;
|
|
168
229
|
const { delivered, inJob } = (0, job_secrets_1.splitJobSecrets)(task.data.secrets, server);
|
|
169
|
-
const secrets = (0, secrets_1.getKubernetesSecretRefs)(task, delivered);
|
|
230
|
+
const secrets = (0, secrets_1.getKubernetesSecretRefs)(task, kubernetes, delivered);
|
|
170
231
|
const admitted = environment.hosted?.accounts;
|
|
232
|
+
let secretHosts;
|
|
171
233
|
try {
|
|
172
|
-
(0, job_secrets_1.
|
|
234
|
+
secretHosts = (0, job_secrets_1.getSecretHosts)(task, inJob, server);
|
|
173
235
|
if (server) {
|
|
174
236
|
(0, job_secrets_1.assertJobAccounts)(inJob, server, admitted);
|
|
175
237
|
}
|
|
@@ -194,7 +256,7 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
194
256
|
: {}),
|
|
195
257
|
};
|
|
196
258
|
const labels = {
|
|
197
|
-
|
|
259
|
+
...(0, resources_1.getItemLabels)(task, kubernetes),
|
|
198
260
|
'hammerkit.dev/state': options.stateKey,
|
|
199
261
|
...workspace.labels,
|
|
200
262
|
[network_policy_1.RUN_LABEL]: scope.run,
|
|
@@ -210,7 +272,11 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
210
272
|
// NetworkPolicy and proxy of a limited network, both of this run
|
|
211
273
|
let network;
|
|
212
274
|
try {
|
|
213
|
-
network = await (0, network_policy_1.ensureKubernetesItemNetwork)(instance, kubernetes, task, {
|
|
275
|
+
network = await (0, network_policy_1.ensureKubernetesItemNetwork)(instance, kubernetes, task, {
|
|
276
|
+
followLog: true,
|
|
277
|
+
secretHosts,
|
|
278
|
+
...scope,
|
|
279
|
+
});
|
|
214
280
|
}
|
|
215
281
|
catch (e) {
|
|
216
282
|
await removeTaskSecrets(instance, kubernetes, task).catch(() => undefined);
|
|
@@ -218,7 +284,7 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
218
284
|
return;
|
|
219
285
|
}
|
|
220
286
|
try {
|
|
221
|
-
const podName = (0, resources_1.getResourceName)(task, '-job');
|
|
287
|
+
const podName = (0, resources_1.getResourceName)(task, kubernetes, '-job');
|
|
222
288
|
let i = 0;
|
|
223
289
|
for (const cmd of task.data.cmds) {
|
|
224
290
|
const container = `cmd-${++i}`;
|
|
@@ -226,15 +292,13 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
226
292
|
try {
|
|
227
293
|
// made for each Job right before it, so a later command's token is as fresh
|
|
228
294
|
const credentials = await (0, job_secrets_1.ensureJobCredentials)(instance, kubernetes, task, inJob, admitted);
|
|
229
|
-
secretSpec = (0, job_secrets_1.getJobSecretSpec)(task, inJob, server, credentials, environment);
|
|
295
|
+
secretSpec = (0, job_secrets_1.getJobSecretSpec)(task, inJob, server, credentials, environment, network.secretEnv);
|
|
230
296
|
}
|
|
231
297
|
catch (e) {
|
|
232
298
|
await removeTaskSecrets(instance, kubernetes, task).catch(() => undefined);
|
|
233
299
|
options.state.set({ stateKey: options.stateKey, type: 'error', errorMessage: (0, log_1.getErrorMessage)(e) });
|
|
234
300
|
return;
|
|
235
301
|
}
|
|
236
|
-
// the arguments after `--` keep their `$` as text, Kubernetes expands `$(NAME)`
|
|
237
|
-
const command = secretSpec.command(task.data.shell, (0, task_arguments_1.getKubernetesCommandText)(cmd));
|
|
238
302
|
const spec = {
|
|
239
303
|
kind: 'Job',
|
|
240
304
|
apiVersion: 'batch/v1',
|
|
@@ -255,33 +319,17 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
255
319
|
labels,
|
|
256
320
|
},
|
|
257
321
|
spec: {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
env: [
|
|
270
|
-
...Object.entries(envs).map(([key, value]) => ({ name: key, value })),
|
|
271
|
-
...secrets.env,
|
|
272
|
-
...network.env,
|
|
273
|
-
...command.env,
|
|
274
|
-
],
|
|
275
|
-
name: container,
|
|
276
|
-
volumeMounts: [
|
|
277
|
-
...persistence.mounts.map((m) => m.mount),
|
|
278
|
-
...secrets.mounts,
|
|
279
|
-
...secretSpec.mounts,
|
|
280
|
-
],
|
|
281
|
-
...(0, container_resources_1.getKubernetesResources)(task.data.resources),
|
|
282
|
-
...(0, job_placement_1.getContainerSecurity)(kubernetes),
|
|
283
|
-
},
|
|
284
|
-
],
|
|
322
|
+
...getTaskJobContainers({
|
|
323
|
+
task,
|
|
324
|
+
cmd,
|
|
325
|
+
container,
|
|
326
|
+
envs,
|
|
327
|
+
secrets,
|
|
328
|
+
network,
|
|
329
|
+
secretSpec,
|
|
330
|
+
mounts: persistence.mounts.map((m) => m.mount),
|
|
331
|
+
kubernetes,
|
|
332
|
+
}),
|
|
285
333
|
volumes: [
|
|
286
334
|
...persistence.volumes,
|
|
287
335
|
...persistence.workspace,
|
|
@@ -365,7 +413,7 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
365
413
|
async stop() {
|
|
366
414
|
const jobs = await instance.batchApi.listNamespacedJob({
|
|
367
415
|
namespace: kubernetes.namespace,
|
|
368
|
-
labelSelector:
|
|
416
|
+
labelSelector: (0, resources_1.getItemSelector)(task, kubernetes),
|
|
369
417
|
});
|
|
370
418
|
for (const job of jobs.items) {
|
|
371
419
|
if (job.metadata?.name) {
|
|
@@ -374,7 +422,7 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
374
422
|
}
|
|
375
423
|
const deployments = await instance.appsApi.listNamespacedDeployment({
|
|
376
424
|
namespace: kubernetes.namespace,
|
|
377
|
-
labelSelector:
|
|
425
|
+
labelSelector: (0, resources_1.getItemSelector)(task, kubernetes),
|
|
378
426
|
});
|
|
379
427
|
for (const deploy of deployments.items) {
|
|
380
428
|
if (deploy.metadata?.name) {
|
|
@@ -386,7 +434,7 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
386
434
|
}
|
|
387
435
|
const pods = await instance.coreApi.listNamespacedPod({
|
|
388
436
|
namespace: kubernetes.namespace,
|
|
389
|
-
labelSelector:
|
|
437
|
+
labelSelector: (0, resources_1.getItemSelector)(task, kubernetes),
|
|
390
438
|
});
|
|
391
439
|
for (const pod of pods.items) {
|
|
392
440
|
if (pod.metadata?.name) {
|
|
@@ -408,7 +456,7 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
408
456
|
}
|
|
409
457
|
const jobs = await instance.batchApi.listNamespacedJob({
|
|
410
458
|
namespace: kubernetes.namespace,
|
|
411
|
-
labelSelector:
|
|
459
|
+
labelSelector: (0, resources_1.getItemSelector)(task, kubernetes),
|
|
412
460
|
});
|
|
413
461
|
const completedStates = jobs.items
|
|
414
462
|
.filter((j) => j.status?.succeeded && j.metadata?.labels?.['hammerkit.dev/state'])
|
|
@@ -445,7 +493,7 @@ function kubernetesServiceRuntime(service, kubernetes) {
|
|
|
445
493
|
async initialize(state) {
|
|
446
494
|
const deployments = await instance.appsApi.listNamespacedDeployment({
|
|
447
495
|
namespace: kubernetes.namespace,
|
|
448
|
-
labelSelector:
|
|
496
|
+
labelSelector: (0, resources_1.getItemSelector)(service, kubernetes),
|
|
449
497
|
});
|
|
450
498
|
const deployment = deployments.items[0];
|
|
451
499
|
if (!deployment?.metadata?.name) {
|
|
@@ -472,7 +520,7 @@ function kubernetesServiceRuntime(service, kubernetes) {
|
|
|
472
520
|
async stop() {
|
|
473
521
|
const deployments = await instance.appsApi.listNamespacedDeployment({
|
|
474
522
|
namespace: kubernetes.namespace,
|
|
475
|
-
labelSelector:
|
|
523
|
+
labelSelector: (0, resources_1.getItemSelector)(service, kubernetes),
|
|
476
524
|
});
|
|
477
525
|
for (const deployment of deployments.items) {
|
|
478
526
|
if (deployment.metadata?.name) {
|
|
@@ -492,9 +540,37 @@ function kubernetesServiceRuntime(service, kubernetes) {
|
|
|
492
540
|
await (0, ensure_kubernetes_service_exists_1.ensureKubernetesServiceExists)(instance, kubernetes, service);
|
|
493
541
|
await (0, ensure_persistent_data_1.ensurePersistentData)(instance, kubernetes, environment, service, persistence);
|
|
494
542
|
await (0, secrets_1.ensureKubernetesSecret)(instance, kubernetes, service, service.data.secrets, environment);
|
|
495
|
-
|
|
496
|
-
await (0,
|
|
497
|
-
|
|
543
|
+
// on a server, the run's: its runs share the namespace, and the service goes with the run
|
|
544
|
+
const network = await (0, network_policy_1.ensureKubernetesItemNetwork)(instance, kubernetes, service, {
|
|
545
|
+
followLog: false,
|
|
546
|
+
run: kubernetes.server ? (0, job_placement_1.getRunLabelValue)(kubernetes.server.run) : null,
|
|
547
|
+
});
|
|
548
|
+
// its output, as on Docker: while it starts, and while it runs unless it runs on
|
|
549
|
+
// without hammerkit (`up --daemon`)
|
|
550
|
+
const logs = (0, follow_pod_logs_1.followPodLogs)(instance, kubernetes.namespace, (0, resources_1.getItemSelector)(service, kubernetes), (0, ensure_kubernetes_deployment_exists_1.getServiceContainerName)(service), (line) => service.status.console('stdout', line), { onError: (text) => service.status.write('debug', text) });
|
|
551
|
+
try {
|
|
552
|
+
await (0, ensure_kubernetes_deployment_exists_1.ensureKubernetesDeploymentExists)(instance, kubernetes, service, persistence, (0, secrets_1.getKubernetesSecretRefs)(service, kubernetes, service.data.secrets), options.stateKey, network);
|
|
553
|
+
}
|
|
554
|
+
catch (e) {
|
|
555
|
+
// the last words of a container that crashed, before why it failed
|
|
556
|
+
await logs.settle().catch(() => undefined);
|
|
557
|
+
logs.stop();
|
|
558
|
+
throw e;
|
|
559
|
+
}
|
|
560
|
+
if (options.daemon || options.abort.aborted || environment.abortCtrl.signal.aborted) {
|
|
561
|
+
logs.stop();
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
// either ends it, and takes the other listener with it
|
|
565
|
+
const listening = new AbortController();
|
|
566
|
+
const stop = () => {
|
|
567
|
+
logs.stop();
|
|
568
|
+
listening.abort();
|
|
569
|
+
};
|
|
570
|
+
options.abort.addEventListener('abort', stop, { once: true, signal: listening.signal });
|
|
571
|
+
environment.abortCtrl.signal.addEventListener('abort', stop, { once: true, signal: listening.signal });
|
|
572
|
+
}
|
|
573
|
+
const name = (0, resources_1.getResourceName)(service, kubernetes);
|
|
498
574
|
options.state.set({
|
|
499
575
|
type: 'running',
|
|
500
576
|
dns: { containerId: name },
|
|
@@ -526,7 +602,7 @@ function kubernetesServiceRuntime(service, kubernetes) {
|
|
|
526
602
|
}
|
|
527
603
|
const services = await instance.coreApi.listNamespacedService({
|
|
528
604
|
namespace: kubernetes.namespace,
|
|
529
|
-
labelSelector:
|
|
605
|
+
labelSelector: (0, resources_1.getItemSelector)(service, kubernetes),
|
|
530
606
|
});
|
|
531
607
|
for (const service of services.items) {
|
|
532
608
|
if (service.metadata?.name) {
|
|
@@ -542,7 +618,7 @@ function kubernetesServiceRuntime(service, kubernetes) {
|
|
|
542
618
|
async currentStateKey() {
|
|
543
619
|
const deployments = await instance.appsApi.listNamespacedDeployment({
|
|
544
620
|
namespace: kubernetes.namespace,
|
|
545
|
-
labelSelector:
|
|
621
|
+
labelSelector: (0, resources_1.getItemSelector)(service, kubernetes),
|
|
546
622
|
});
|
|
547
623
|
const deployment = deployments.items[0];
|
|
548
624
|
return deployment?.metadata?.labels?.['hammerkit.dev/state'] ?? null;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getLocalWorkRuntime = exports.getStateFilename = void 0;
|
|
7
7
|
const tar_1 = require("tar");
|
|
8
|
+
const tar_2 = require("../utils/tar");
|
|
8
9
|
const path_1 = require("path");
|
|
9
10
|
const local_task_1 = require("../executer/local-task");
|
|
10
11
|
const event_cache_1 = require("../executer/event-cache");
|
|
@@ -121,7 +122,7 @@ async function archiveLocal(environment, task, path) {
|
|
|
121
122
|
for (const generatedArchive of (0, event_cache_1.getArchivePaths)(task.data, path)) {
|
|
122
123
|
await environment.file.writeStream(generatedArchive.filename,
|
|
123
124
|
// tar's stream is a Minipass stream; Readable.from adapts it to a Node one
|
|
124
|
-
stream_1.Readable.from((0,
|
|
125
|
+
stream_1.Readable.from((0, tar_2.packArchive)({ cwd: task.data.cwd, gzip: true }, [(0, path_1.relative)(task.data.cwd, generatedArchive.path)])));
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
async function restoreLocal(environment, task, path) {
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isWorkTask = exports.isContainerWorkTask = void 0;
|
|
3
|
+
exports.isAggregateTask = exports.isWorkTask = exports.isContainerWorkTask = void 0;
|
|
4
4
|
const isContainerWorkTask = (val) => val.type === 'container-task';
|
|
5
5
|
exports.isContainerWorkTask = isContainerWorkTask;
|
|
6
6
|
const isWorkTask = (val) => val.type === 'container-task' || val.type === 'local-task';
|
|
7
7
|
exports.isWorkTask = isWorkTask;
|
|
8
|
+
// A task that only groups its dependencies: `deps`, and no `image`, `cmds`, `src`,
|
|
9
|
+
// `generates`, `secrets`, `needs` or `continuous`. It needs no runtime, hands on what its dependencies generate to what
|
|
10
|
+
// depends on it, and is up to date (or verified) when all its dependencies are.
|
|
11
|
+
const isAggregateTask = (val) => val.type === 'local-task' && val.aggregate === true;
|
|
12
|
+
exports.isAggregateTask = isAggregateTask;
|
|
8
13
|
//# sourceMappingURL=work-task.js.map
|