hammerkit 2.0.0-next.9 → 2.1.0-next.1
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 +228 -63
- package/dist/cache/backends/registry/registry-client.js +8 -2
- package/dist/cache/explain.js +5 -0
- package/dist/cache/last-resolved.js +11 -0
- package/dist/cli.js +4 -1
- package/dist/dashboard/assets/{graph-canvas-HmkW_-XJ.js → graph-canvas-DtJSpova.js} +1 -1
- package/dist/dashboard/assets/index-BndChMep.css +2 -0
- package/dist/dashboard/assets/{index-vE22S5E_.js → index-DRSwIRXd.js} +9 -9
- package/dist/dashboard/index.html +2 -2
- package/dist/docker/item-network.js +51 -18
- package/dist/docker/package.js +85 -76
- package/dist/docker/server-tools.js +96 -0
- package/dist/docker/stream.js +15 -7
- package/dist/environment/replace-env-variables.js +1 -1
- package/dist/environment/run-source-envs.js +18 -0
- package/dist/executer/check-container-binds.js +158 -0
- package/dist/executer/docker-service.js +42 -3
- package/dist/executer/docker-task.js +33 -6
- package/dist/executer/execute-command.js +9 -15
- package/dist/executer/execute-work-task.js +11 -1
- package/dist/executer/execute-work-tree.js +2 -1
- package/dist/executer/execution-steps.js +6 -2
- package/dist/executer/get-container-binds.js +2 -0
- package/dist/executer/print-container-options.js +10 -10
- package/dist/executer/process-manager.js +84 -5
- package/dist/executer/scheduler/state-key.js +19 -1
- package/dist/executer/task-priority.js +131 -0
- package/dist/file/stat-beneath.js +66 -0
- package/dist/file/within-root.js +13 -4
- package/dist/harness/connect.js +1 -6
- package/dist/harness/mcp-command.js +1 -1
- package/dist/harness/sandbox-client.js +39 -4
- package/dist/harness/service-tools.js +2 -2
- package/dist/kubernetes/await-running-state.js +42 -26
- package/dist/kubernetes/ensure-persistent-data.js +22 -7
- package/dist/kubernetes/kept-claims.js +12 -9
- package/dist/kubernetes/network-gate.js +74 -11
- package/dist/kubernetes/network-policy.js +32 -10
- package/dist/kubernetes/remove-stale-items.js +15 -2
- package/dist/kubernetes/restore-kubernetes-data.js +3 -2
- package/dist/kubernetes/sandbox-runner.js +3 -4
- package/dist/kubernetes/store-kubernetes-data.js +3 -2
- package/dist/kubernetes/transfer-tools.js +66 -0
- package/dist/kubernetes/volumes.js +52 -10
- package/dist/optimizer/check-key.js +7 -0
- package/dist/optimizer/check-keys.js +19 -5
- package/dist/optimizer/get-work-cache-stats.js +19 -7
- package/dist/optimizer/work-task-cache-description.js +42 -8
- package/dist/planner/image-build.js +172 -0
- package/dist/planner/utils/append-work-dependencies.js +14 -1
- package/dist/planner/utils/append-work-service.js +1 -1
- package/dist/planner/utils/append-work-task.js +51 -1
- package/dist/planner/utils/assert-item-paths.js +6 -7
- package/dist/planner/utils/dependency-outputs.js +18 -0
- package/dist/planner/work-runtime-docker.js +48 -50
- package/dist/planner/work-runtime-kubernetes.js +1 -0
- package/dist/planner/work-runtime-local.js +3 -7
- package/dist/planner/work-secret.js +135 -13
- package/dist/planner/work-tree.js +10 -0
- package/dist/remote/collect-bundle.js +9 -1
- package/dist/remote/host-config.js +49 -3
- package/dist/remote/location.js +5 -5
- package/dist/remote/remote-commands.js +12 -14
- package/dist/remote/remote-status.js +1 -1
- package/dist/remote/remote-work-commands.js +20 -8
- package/dist/schema/build-file-image-build-schema.js +77 -0
- package/dist/schema/build-file-task-schema.js +9 -2
- package/dist/schema/reference-parser.js +10 -1
- package/dist/schema/work-scope-parser.js +16 -1
- package/dist/secrets/secret-catalog.js +8 -1
- package/dist/server/borrowed-quota.js +216 -0
- package/dist/server/capacity.js +18 -6
- package/dist/server/dashboard.js +8 -5
- package/dist/server/executor.js +58 -35
- package/dist/server/kubernetes-backend.js +143 -32
- package/dist/server/overview.js +20 -2
- package/dist/server/plan.js +31 -3
- package/dist/server/policy.js +14 -7
- package/dist/server/repo-access.js +4 -3
- package/dist/server/run-environment.js +5 -2
- package/dist/server/run-plan.js +18 -6
- package/dist/server/run-retry.js +57 -0
- package/dist/server/run-source-environment.js +39 -0
- package/dist/server/run-worker.js +38 -9
- package/dist/server/runs.js +63 -7
- package/dist/server/sandbox-files.js +232 -39
- package/dist/server/server-config.js +83 -6
- package/dist/server/server.js +107 -12
- package/dist/server/service-runs.js +42 -4
- package/dist/utils/line-splitter.js +52 -0
- package/dist/utils/tar.js +51 -1
- package/package.json +1 -1
- package/dist/dashboard/assets/index-gIBDC_m8.css +0 -2
|
@@ -14,6 +14,8 @@ const remove_container_1 = require("../docker/remove-container");
|
|
|
14
14
|
const check_readiness_1 = require("./check-readiness");
|
|
15
15
|
const main_process_user_1 = require("./main-process-user");
|
|
16
16
|
const execution_steps_1 = require("./execution-steps");
|
|
17
|
+
const check_container_binds_1 = require("./check-container-binds");
|
|
18
|
+
const server_tools_1 = require("../docker/server-tools");
|
|
17
19
|
const item_network_1 = require("../docker/item-network");
|
|
18
20
|
const container_secrets_1 = require("./container-secrets");
|
|
19
21
|
const replace_env_variables_1 = require("../environment/replace-env-variables");
|
|
@@ -44,9 +46,12 @@ async function readPublishedPorts(container, ports) {
|
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
exports.readPublishedPorts = readPublishedPorts;
|
|
47
|
-
function buildServiceCreateOptions(item, options, network, secrets, resources = {}
|
|
49
|
+
function buildServiceCreateOptions(item, options, network, secrets, resources = {},
|
|
50
|
+
// on a server: the server's tools, and the command the service runs once the server
|
|
51
|
+
// checked its binds (gatedCommand)
|
|
52
|
+
gate) {
|
|
48
53
|
const envs = (0, replace_env_variables_1.getEnvironmentVariables)(item.data.envs);
|
|
49
|
-
const command = (0, work_service_1.getServiceCommand)(item.data);
|
|
54
|
+
const command = gate ? { entrypoint: (0, server_tools_1.gatedCommand)(gate.tools, gate.command), cmd: [] } : (0, work_service_1.getServiceCommand)(item.data);
|
|
50
55
|
return {
|
|
51
56
|
Image: item.data.image,
|
|
52
57
|
Hostname: (0, service_hostname_1.getServiceHostname)(item.name),
|
|
@@ -74,7 +79,9 @@ function buildServiceCreateOptions(item, options, network, secrets, resources =
|
|
|
74
79
|
...item.data.mounts.map((v) => `${v.localPath}:${(0, execute_docker_1.convertToPosixPath)(v.containerPath)}${v.readOnly ? ':ro' : ''}`),
|
|
75
80
|
...item.data.volumes.map((v) => `${v.name}:${(0, execute_docker_1.convertToPosixPath)(v.containerPath)}${v.readOnly ? ':ro' : ''}`),
|
|
76
81
|
...secrets.binds,
|
|
82
|
+
...(gate ? (0, server_tools_1.serverToolsBinds)(gate.tools) : []),
|
|
77
83
|
],
|
|
84
|
+
...(gate ? { Tmpfs: (0, server_tools_1.serviceGateTmpfs)(gate.tools) } : {}),
|
|
78
85
|
// host ports are for `hammerkit up` and local tasks; container tasks
|
|
79
86
|
// reach the service over its link, and a run publishing them would
|
|
80
87
|
// collide with another run on the same host. A limited service's are
|
|
@@ -89,6 +96,15 @@ function buildServiceCreateOptions(item, options, network, secrets, resources =
|
|
|
89
96
|
};
|
|
90
97
|
}
|
|
91
98
|
exports.buildServiceCreateOptions = buildServiceCreateOptions;
|
|
99
|
+
// What docker would run in the service's container: its own command, or the image's.
|
|
100
|
+
async function getServiceProcess(docker, service) {
|
|
101
|
+
const { entrypoint, cmd } = (0, work_service_1.getServiceCommand)(service);
|
|
102
|
+
if (entrypoint) {
|
|
103
|
+
return [...entrypoint, ...(cmd ?? [])];
|
|
104
|
+
}
|
|
105
|
+
const config = (await docker.getImage(service.image).inspect()).Config;
|
|
106
|
+
return [...(config.Entrypoint ?? []), ...(cmd ?? config.Cmd ?? [])];
|
|
107
|
+
}
|
|
92
108
|
async function dockerService(docker, item, options, environment) {
|
|
93
109
|
let container = null;
|
|
94
110
|
let network = null;
|
|
@@ -107,12 +123,35 @@ async function dockerService(docker, item, options, environment) {
|
|
|
107
123
|
item.status.write('debug', `create container with image ${item.data.image}`);
|
|
108
124
|
const secrets = await (0, container_secrets_1.prepareContainerSecrets)(item.data.secrets, (0, work_instance_id_1.getWorkInstanceId)(item), environment);
|
|
109
125
|
const resources = await (0, docker_resources_1.resolveDockerResources)(docker, item.data.resources, item.status);
|
|
126
|
+
(0, check_container_binds_1.refuseServerToolsPaths)(item, environment);
|
|
127
|
+
const gate = (0, execution_steps_1.hostedRoot)(environment)
|
|
128
|
+
? {
|
|
129
|
+
tools: (0, server_tools_1.createServerTools)(await (0, server_tools_1.ensureServerBusybox)(docker, item.status, environment)),
|
|
130
|
+
command: await getServiceProcess(docker, item.data),
|
|
131
|
+
}
|
|
132
|
+
: undefined;
|
|
110
133
|
await (0, execution_steps_1.refuseHostLinks)(item, environment);
|
|
111
|
-
container = await docker.createContainer(buildServiceCreateOptions(item, options, network.options, secrets, resources));
|
|
134
|
+
container = await docker.createContainer(buildServiceCreateOptions(item, options, network.options, secrets, resources, gate));
|
|
112
135
|
const relay = await network.connect(container);
|
|
113
136
|
const stream = await container.attach({ stream: true, stdout: true, stderr: true });
|
|
114
137
|
(0, stream_1.logStream)(item.status, stream);
|
|
138
|
+
// the engine resolves the paths it binds when the container starts: on a server the
|
|
139
|
+
// service's own command waits for the server to check them (gatedCommand)
|
|
140
|
+
await (0, execution_steps_1.refuseHostLinks)(item, environment);
|
|
115
141
|
await container.start();
|
|
142
|
+
const started = container;
|
|
143
|
+
const binds = [
|
|
144
|
+
...item.data.src.map((s) => ({ localPath: s.absolutePath, containerPath: s.absolutePath })),
|
|
145
|
+
...item.data.mounts,
|
|
146
|
+
];
|
|
147
|
+
await (0, check_container_binds_1.assertContainerBinds)(item, environment, started, binds, gate?.tools)
|
|
148
|
+
.then(() => (gate ? (0, check_container_binds_1.openServiceGate)(started, gate.tools) : undefined))
|
|
149
|
+
.catch(async (e) => {
|
|
150
|
+
// not kept, not even for a daemon
|
|
151
|
+
container = null;
|
|
152
|
+
await (0, remove_container_1.removeContainer)(started);
|
|
153
|
+
throw e;
|
|
154
|
+
});
|
|
116
155
|
const published = options.publishPorts ? await readPublishedPorts(relay ?? container, item.data.ports) : [];
|
|
117
156
|
if (!item.data.healthcheck || !options.waitForReady) {
|
|
118
157
|
options.state.set({
|
|
@@ -8,6 +8,8 @@ const abort_1 = require("./abort");
|
|
|
8
8
|
const log_1 = require("../log");
|
|
9
9
|
const execution_steps_1 = require("./execution-steps");
|
|
10
10
|
const using_container_1 = require("../docker/using-container");
|
|
11
|
+
const check_container_binds_1 = require("./check-container-binds");
|
|
12
|
+
const server_tools_1 = require("../docker/server-tools");
|
|
11
13
|
const print_container_options_1 = require("./print-container-options");
|
|
12
14
|
const tar_1 = require("tar");
|
|
13
15
|
const replace_env_variables_1 = require("../environment/replace-env-variables");
|
|
@@ -18,7 +20,11 @@ const get_outputs_to_reset_1 = require("../planner/utils/get-outputs-to-reset");
|
|
|
18
20
|
const container_secrets_1 = require("./container-secrets");
|
|
19
21
|
const container_task_state_1 = require("./container-task-state");
|
|
20
22
|
const docker_resources_1 = require("./docker-resources");
|
|
21
|
-
|
|
23
|
+
const image_build_1 = require("../planner/image-build");
|
|
24
|
+
const get_docker_executor_1 = require("./get-docker-executor");
|
|
25
|
+
function buildCreateOptions(item, stateKey, network, environment, secrets, resources = {},
|
|
26
|
+
// on a server: the server's tools, whose busybox is the container's first process
|
|
27
|
+
tools) {
|
|
22
28
|
const binds = (0, get_container_binds_1.getContainerBinds)(item);
|
|
23
29
|
const envs = (0, replace_env_variables_1.getEnvironmentVariables)(item.data.envs);
|
|
24
30
|
// Running as the host's uid (Linux), the user has no home in the image and
|
|
@@ -29,8 +35,9 @@ function buildCreateOptions(item, stateKey, network, environment, secrets, resou
|
|
|
29
35
|
abortSignal: environment.abortCtrl.signal,
|
|
30
36
|
Image: item.data.image,
|
|
31
37
|
Tty: true,
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
// on a server nothing of the image runs before its binds are checked (check-container-binds.ts)
|
|
39
|
+
Entrypoint: tools ? [(0, server_tools_1.serverBusybox)(tools)] : [item.data.shell],
|
|
40
|
+
Cmd: tools ? ['sleep', '3600'] : ['-c', 'sleep 3600'],
|
|
34
41
|
Env: Object.entries({ ...envs, ...home, ...network.env, ...secrets.env }).map(([key, value]) => `${key}=${value}`),
|
|
35
42
|
WorkingDir: (0, execute_docker_1.convertToPosixPath)(item.data.cwd),
|
|
36
43
|
Labels: {
|
|
@@ -44,6 +51,8 @@ function buildCreateOptions(item, stateKey, network, environment, secrets, resou
|
|
|
44
51
|
Binds: [
|
|
45
52
|
...binds.map((b) => `${b.localPath}:${(0, execute_docker_1.convertToPosixPath)(b.containerPath)}${b.readOnly ? ':ro' : ''}`),
|
|
46
53
|
...secrets.binds,
|
|
54
|
+
...getBuildKitBinds(item, environment),
|
|
55
|
+
...(tools ? (0, server_tools_1.serverToolsBinds)(tools) : []),
|
|
47
56
|
],
|
|
48
57
|
...(0, item_network_1.getNetworkHostConfig)(network),
|
|
49
58
|
AutoRemove: true,
|
|
@@ -63,7 +72,10 @@ function getCapabilityHostConfig(item, environment) {
|
|
|
63
72
|
return {};
|
|
64
73
|
}
|
|
65
74
|
if (!environment.hosted) {
|
|
66
|
-
|
|
75
|
+
// BuildKit of a task that builds an image (`build`) needs more than SYS_ADMIN where the
|
|
76
|
+
// kernel is the container's own: AppArmor, the read-only cgroups and the masked /proc
|
|
77
|
+
// stop it. On a dev machine it runs privileged, as `docker buildx` runs its BuildKit.
|
|
78
|
+
return item.data.build ? { CapAdd: capAdd, Privileged: true } : { CapAdd: capAdd };
|
|
67
79
|
}
|
|
68
80
|
const runtime = environment.hosted.capabilityRuntime;
|
|
69
81
|
if (!runtime) {
|
|
@@ -72,6 +84,11 @@ function getCapabilityHostConfig(item, environment) {
|
|
|
72
84
|
return { CapAdd: capAdd, Runtime: runtime };
|
|
73
85
|
}
|
|
74
86
|
exports.getCapabilityHostConfig = getCapabilityHostConfig;
|
|
87
|
+
// On a dev machine BuildKit keeps its layers in a volume of the task, for the next build; on
|
|
88
|
+
// a server it has a tmpfs, which its command mounts (see getImageBuildCommand).
|
|
89
|
+
function getBuildKitBinds(item, environment) {
|
|
90
|
+
return item.data.build && !environment.hosted ? [`${(0, image_build_1.getBuildKitVolumeName)(item.data)}:${image_build_1.BUILDKIT_STATE}`] : [];
|
|
91
|
+
}
|
|
75
92
|
async function dockerTask(docker, item, environment, options) {
|
|
76
93
|
item.status.write('info', `execute ${item.name} in container`);
|
|
77
94
|
let network = null;
|
|
@@ -89,16 +106,26 @@ async function dockerTask(docker, item, environment, options) {
|
|
|
89
106
|
await (0, execution_steps_1.pullImage)(item, docker, environment);
|
|
90
107
|
(0, abort_1.checkForAbort)(options.abort);
|
|
91
108
|
await (0, execution_steps_1.prepareVolume)(item, docker, environment);
|
|
109
|
+
if (item.data.build && !environment.hosted) {
|
|
110
|
+
await (0, get_docker_executor_1.ensureVolumeExists)(docker, item.status, (0, image_build_1.getBuildKitVolumeName)(item.data));
|
|
111
|
+
}
|
|
92
112
|
(0, abort_1.checkForAbort)(options.abort);
|
|
93
113
|
network = await (0, item_network_1.prepareItemNetwork)(docker, item, environment, { daemon: false });
|
|
94
114
|
(0, abort_1.checkForAbort)(options.abort);
|
|
95
115
|
const secrets = await (0, container_secrets_1.prepareContainerSecrets)(item.data.secrets, (0, work_instance_id_1.getWorkInstanceId)(item), environment);
|
|
96
116
|
const resources = await (0, docker_resources_1.resolveDockerResources)(docker, item.data.resources, item.status);
|
|
97
|
-
|
|
98
|
-
(0,
|
|
117
|
+
(0, check_container_binds_1.refuseServerToolsPaths)(item, environment);
|
|
118
|
+
(0, check_container_binds_1.refuseUncheckableBinds)(item, environment);
|
|
119
|
+
const tools = (0, execution_steps_1.hostedRoot)(environment)
|
|
120
|
+
? (0, server_tools_1.createServerTools)(await (0, server_tools_1.ensureServerBusybox)(docker, item.status, environment))
|
|
121
|
+
: undefined;
|
|
122
|
+
const containerOptions = buildCreateOptions(item, options.stateKey, network.options, environment, secrets, resources, tools);
|
|
123
|
+
(0, print_container_options_1.printContainerOptions)(item.status, containerOptions, tools);
|
|
99
124
|
await (0, execution_steps_1.refuseHostLinks)(item, environment);
|
|
100
125
|
const itemNetwork = network;
|
|
101
126
|
const succeeded = await (0, using_container_1.usingContainer)(docker, item, containerOptions, async (container) => {
|
|
127
|
+
// the engine resolved the paths it binds as the container started: before anything runs in it
|
|
128
|
+
await (0, check_container_binds_1.assertContainerBinds)(item, environment, container, (0, get_container_binds_1.getContainerBinds)(item), tools);
|
|
102
129
|
await itemNetwork.connect(container);
|
|
103
130
|
await (0, execution_steps_1.setUserPermissions)(item, container, environment);
|
|
104
131
|
for (const generate of outputsToReset.filter((g) => !g.isFile)) {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.executeCommand = exports.processEnv = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const os_1 = require("os");
|
|
6
|
-
const
|
|
6
|
+
const line_splitter_1 = require("../utils/line-splitter");
|
|
7
7
|
const abort_1 = require("./abort");
|
|
8
8
|
const abort_event_1 = require("../utils/abort-event");
|
|
9
9
|
const environment_config_1 = require("../utils/environment-config");
|
|
@@ -43,25 +43,19 @@ async function executeCommand(status, abortSignal, cwd, command, envs, environme
|
|
|
43
43
|
// they would keep running and holding the output open
|
|
44
44
|
detached: !windows,
|
|
45
45
|
});
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
ps.stdout?.on('data',
|
|
51
|
-
|
|
52
|
-
status.console('stdout', log);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
ps.stderr?.on('data', async (data) => {
|
|
56
|
-
for (const log of (0, log_1.getLogs)(data)) {
|
|
57
|
-
status.console('stderr', log);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
46
|
+
// a line that two chunks split is logged once it ends, whole: a multi-byte character
|
|
47
|
+
// stays intact, and so does a secret value, which is masked per line
|
|
48
|
+
const stdout = (0, line_splitter_1.lineSplitter)((line) => status.console('stdout', line));
|
|
49
|
+
const stderr = (0, line_splitter_1.lineSplitter)((line) => status.console('stderr', line));
|
|
50
|
+
ps.stdout?.on('data', (data) => stdout.write(data));
|
|
51
|
+
ps.stderr?.on('data', (data) => stderr.write(data));
|
|
60
52
|
ps.on('error', (err) => {
|
|
61
53
|
reject(err);
|
|
62
54
|
});
|
|
63
55
|
ps.on('close', (code) => {
|
|
64
56
|
abortListener.close();
|
|
57
|
+
stdout.end();
|
|
58
|
+
stderr.end();
|
|
65
59
|
if (abortSignal.aborted) {
|
|
66
60
|
reject(new abort_1.AbortError());
|
|
67
61
|
return;
|
|
@@ -13,6 +13,7 @@ const explain_1 = require("../cache/explain");
|
|
|
13
13
|
const archive_task_entry_1 = require("./archive-task-entry");
|
|
14
14
|
const units_1 = require("../utils/units");
|
|
15
15
|
const deferred_restore_1 = require("./deferred-restore");
|
|
16
|
+
const task_priority_1 = require("./task-priority");
|
|
16
17
|
async function pushToBackend(work, environment, cacheState, options) {
|
|
17
18
|
const { resolved, stateKey, provable } = cacheState;
|
|
18
19
|
// an aggregate has nothing to store, see checkCacheState
|
|
@@ -97,6 +98,8 @@ dependents = null) {
|
|
|
97
98
|
}
|
|
98
99
|
await (0, await_completed_dependencies_1.awaitRunningNeeds)(work, work.needs.map((n) => n.service), abort);
|
|
99
100
|
await options.processManager.task(work, async () => {
|
|
101
|
+
// from here it runs; `started` also counts its wait for dependencies and a place
|
|
102
|
+
const ranFrom = new Date();
|
|
100
103
|
work.state.set({
|
|
101
104
|
type: 'running',
|
|
102
105
|
stateKey: cacheState.stateKey,
|
|
@@ -114,6 +117,7 @@ dependents = null) {
|
|
|
114
117
|
daemon: options.daemon,
|
|
115
118
|
publishPorts: false,
|
|
116
119
|
waitForReady: true,
|
|
120
|
+
onQuotaRefused: (refused) => options.processManager.quotaRefused(work, refused),
|
|
117
121
|
});
|
|
118
122
|
}
|
|
119
123
|
finally {
|
|
@@ -137,13 +141,19 @@ dependents = null) {
|
|
|
137
141
|
work.status.write('debug', 'completed for state key ' + cacheState.stateKey);
|
|
138
142
|
await pushToBackend(work, environment, cacheState, options);
|
|
139
143
|
const cached = onlyGroupsCacheHits(work);
|
|
144
|
+
const duration = (0, states_1.getDuration)(started);
|
|
140
145
|
work.state.set({
|
|
141
146
|
stateKey: cacheState.stateKey,
|
|
142
147
|
type: 'completed',
|
|
143
148
|
cached,
|
|
144
|
-
duration
|
|
149
|
+
duration,
|
|
145
150
|
missCauses: cached ? undefined : missCauses,
|
|
146
151
|
});
|
|
152
|
+
// what it took orders the next runs, see getTaskPriority
|
|
153
|
+
// on a server the runs are the record, see RunRegistry
|
|
154
|
+
if (!(0, work_task_1.isAggregateTask)(work.data) && !environment.hosted) {
|
|
155
|
+
await (0, task_priority_1.recordTaskDuration)(environment, work, (0, states_1.getDuration)(ranFrom));
|
|
156
|
+
}
|
|
147
157
|
}
|
|
148
158
|
else {
|
|
149
159
|
if (!options.watch) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeWorkTree = void 0;
|
|
4
|
+
const work_tree_1 = require("../planner/work-tree");
|
|
4
5
|
const plan_work_tasks_1 = require("../planner/utils/plan-work-tasks");
|
|
5
6
|
const execute_work_service_1 = require("./execute-work-service");
|
|
6
7
|
const execute_work_task_1 = require("./execute-work-task");
|
|
@@ -18,7 +19,7 @@ async function executeWorkTree(work, environment, options) {
|
|
|
18
19
|
if (initOf) {
|
|
19
20
|
const service = work.services[initOf.serviceName] ?? null;
|
|
20
21
|
// asked for alone (by name), it runs against a service already running too
|
|
21
|
-
const requested =
|
|
22
|
+
const requested = (0, work_tree_1.isAskedByName)(work, task.name);
|
|
22
23
|
itemPromises.push((0, execute_init_task_1.executeInitTask)(task, initOf.init, service, requested, environment, options));
|
|
23
24
|
continue;
|
|
24
25
|
}
|
|
@@ -20,8 +20,9 @@ exports.hostedRoot = hostedRoot;
|
|
|
20
20
|
* reads or writes for it, has to stay inside the run's files with no link on the way:
|
|
21
21
|
* tasks of this or an earlier run on a sandbox, or the commit of a ref, could have left
|
|
22
22
|
* one pointing anywhere on the server. The runtime checks before an item runs; this is
|
|
23
|
-
* checked again right before a container is made
|
|
24
|
-
* other tasks of the
|
|
23
|
+
* checked again right before a container is made, after it started (the engine resolves
|
|
24
|
+
* the paths it binds as it starts) and before outputs are copied, after other tasks of the
|
|
25
|
+
* run had their turn.
|
|
25
26
|
*/
|
|
26
27
|
async function refuseHostLinks(item, environment) {
|
|
27
28
|
const root = hostedRoot(environment);
|
|
@@ -99,6 +100,9 @@ async function prepareMounts(item, environment) {
|
|
|
99
100
|
if (exists) {
|
|
100
101
|
continue;
|
|
101
102
|
}
|
|
103
|
+
// a file in a folder that isn't there yet (`.images/app.ref`), which docker would bind
|
|
104
|
+
// as a directory
|
|
105
|
+
await environment.file.createDirectory((0, path_1.dirname)(gen.path));
|
|
102
106
|
await environment.file.writeFile(gen.path, '');
|
|
103
107
|
}
|
|
104
108
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getContainerBinds = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
+
const dependency_outputs_1 = require("../planner/utils/dependency-outputs");
|
|
5
6
|
function isInside(path, parent) {
|
|
6
7
|
const rel = (0, path_1.relative)(parent, path);
|
|
7
8
|
return rel !== '' && !rel.startsWith('..') && !(0, path_1.isAbsolute)(rel);
|
|
@@ -16,6 +17,7 @@ function getContainerBinds(item) {
|
|
|
16
17
|
// host delete while the container exists.
|
|
17
18
|
...sources
|
|
18
19
|
.filter((path) => !sources.some((other) => isInside(path, other)))
|
|
20
|
+
.filter((path) => !(0, dependency_outputs_1.isDependencyOutput)(item.data, path))
|
|
19
21
|
.map((path) => ({ localPath: path, containerPath: path, readOnly: false })),
|
|
20
22
|
...item.data.generates
|
|
21
23
|
.filter((g) => !g.isFile)
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.printContainerOptions = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const server_tools_1 = require("../docker/server-tools");
|
|
5
|
+
// `tools`: the server's tools in the container, whose folder is not printed
|
|
6
|
+
function printContainerOptions(status, containerOptions, tools) {
|
|
7
|
+
const write = (text) => status.write('debug', (0, server_tools_1.hideServerTools)(text, tools));
|
|
8
|
+
write(`create container with image ${containerOptions.Image} with ${containerOptions.Entrypoint}`);
|
|
6
9
|
for (const mount of containerOptions.HostConfig?.Binds || []) {
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
for (const mount of containerOptions.HostConfig?.Binds || []) {
|
|
10
|
-
status.write('debug', `bind ${mount}`);
|
|
10
|
+
write(`bind ${mount}`);
|
|
11
11
|
}
|
|
12
12
|
if (containerOptions.HostConfig?.NanoCpus) {
|
|
13
|
-
|
|
13
|
+
write(`limit cpus to ${containerOptions.HostConfig.NanoCpus / 1e9}`);
|
|
14
14
|
}
|
|
15
15
|
if (containerOptions.HostConfig?.Memory) {
|
|
16
|
-
|
|
16
|
+
write(`limit memory to ${containerOptions.HostConfig.Memory} bytes`);
|
|
17
17
|
}
|
|
18
18
|
if (containerOptions.HostConfig?.MemoryReservation) {
|
|
19
|
-
|
|
19
|
+
write(`reserve memory ${containerOptions.HostConfig.MemoryReservation} bytes`);
|
|
20
20
|
}
|
|
21
21
|
for (const link of containerOptions.HostConfig?.Links || []) {
|
|
22
|
-
|
|
22
|
+
write(`link ${link}`);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.printContainerOptions = printContainerOptions;
|
|
@@ -7,14 +7,27 @@ class ProcessManager {
|
|
|
7
7
|
// runs already; one starts regardless when nothing else runs, so a run
|
|
8
8
|
// whose services alone fill the budget, or a task bigger than it, still
|
|
9
9
|
// makes progress.
|
|
10
|
-
|
|
10
|
+
// With a priority, the waiting task that is most urgent takes a free place,
|
|
11
|
+
// else the one that waits longest. Places are then given out a moment after a
|
|
12
|
+
// task arrives or one ends, so the tasks that the same event made ready (the
|
|
13
|
+
// dependents of a task that completed) compete for them together.
|
|
14
|
+
constructor(workerLimit, budget = null, priority = null) {
|
|
11
15
|
this.workerLimit = workerLimit;
|
|
12
16
|
this.budget = budget;
|
|
17
|
+
this.priority = priority;
|
|
13
18
|
this.processes = [];
|
|
14
19
|
this.pendingProcesses = [];
|
|
20
|
+
this.pickScheduled = false;
|
|
21
|
+
// the running tasks whose pod the quota of the namespace refuses now
|
|
22
|
+
this.refused = new Set();
|
|
15
23
|
}
|
|
16
24
|
task(item, factory) {
|
|
17
25
|
return new Promise((resolve, reject) => {
|
|
26
|
+
if (this.priority) {
|
|
27
|
+
this.pendingProcesses.push({ item, factory, resolve, reject });
|
|
28
|
+
this.schedulePick();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
18
31
|
if (this.budget) {
|
|
19
32
|
this.pendingProcesses.push({ item, factory, resolve, reject });
|
|
20
33
|
this.startFitting();
|
|
@@ -43,11 +56,76 @@ class ProcessManager {
|
|
|
43
56
|
if (!released) {
|
|
44
57
|
released = true;
|
|
45
58
|
budget.release(requests);
|
|
46
|
-
this.
|
|
59
|
+
if (this.priority) {
|
|
60
|
+
this.schedulePick();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.startFitting();
|
|
64
|
+
}
|
|
47
65
|
}
|
|
48
66
|
};
|
|
49
67
|
}
|
|
68
|
+
// A running task tells whether the quota refuses its pod now. While it is refused, the
|
|
69
|
+
// tasks less urgent than it wait, so the room that frees goes to it and not to a pod of
|
|
70
|
+
// theirs; without a priority nothing changes.
|
|
71
|
+
quotaRefused(item, refused) {
|
|
72
|
+
if (refused) {
|
|
73
|
+
this.refused.add(item);
|
|
74
|
+
}
|
|
75
|
+
else if (this.refused.delete(item) && this.priority) {
|
|
76
|
+
this.schedulePick();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
schedulePick() {
|
|
80
|
+
if (this.pickScheduled) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.pickScheduled = true;
|
|
84
|
+
setImmediate(() => {
|
|
85
|
+
this.pickScheduled = false;
|
|
86
|
+
if (this.budget) {
|
|
87
|
+
this.startFitting();
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this.startByPriority();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// The waiting tasks that may start now, most urgent first; of equal ones, the one
|
|
95
|
+
// waiting longest. While the quota refuses a running task's pod, only those more urgent
|
|
96
|
+
// than it.
|
|
97
|
+
startable() {
|
|
98
|
+
const priority = this.priority;
|
|
99
|
+
if (!priority) {
|
|
100
|
+
return [...this.pendingProcesses];
|
|
101
|
+
}
|
|
102
|
+
const memo = new Map();
|
|
103
|
+
const floor = this.refused.size > 0 ? Math.max(...[...this.refused].map((item) => priority(item, memo))) : null;
|
|
104
|
+
// A task that needs a service is never held back: its service is up already and holds
|
|
105
|
+
// its room until the task ran, so holding the task back would keep that room taken.
|
|
106
|
+
return this.pendingProcesses
|
|
107
|
+
.map((pending, index) => ({ pending, index, rank: priority(pending.item, memo) }))
|
|
108
|
+
.filter(({ pending, rank }) => floor === null || rank > floor || pending.item.needs.length > 0)
|
|
109
|
+
.sort((a, b) => b.rank - a.rank || a.index - b.index)
|
|
110
|
+
.map(({ pending }) => pending);
|
|
111
|
+
}
|
|
112
|
+
startByPriority() {
|
|
113
|
+
for (const pending of this.startable()) {
|
|
114
|
+
if (this.workerLimit !== 0 && this.processes.length >= this.workerLimit) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (this.processes.some((p) => p.id === pending.item.name)) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
this.pendingProcesses.splice(this.pendingProcesses.indexOf(pending), 1);
|
|
121
|
+
this.startProcess(pending);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
50
124
|
enqueuePendingProcesses() {
|
|
125
|
+
if (this.priority) {
|
|
126
|
+
this.schedulePick();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
51
129
|
if (this.budget) {
|
|
52
130
|
this.startFitting();
|
|
53
131
|
return;
|
|
@@ -64,10 +142,10 @@ class ProcessManager {
|
|
|
64
142
|
this.startProcess(pendingProcess);
|
|
65
143
|
}
|
|
66
144
|
}
|
|
67
|
-
// In order, every pending task that fits; a
|
|
68
|
-
// while an earlier one waits for room.
|
|
145
|
+
// In order (by priority when there is one), every pending task that fits; a
|
|
146
|
+
// later, smaller one may start while an earlier one waits for room.
|
|
69
147
|
startFitting() {
|
|
70
|
-
for (const pending of
|
|
148
|
+
for (const pending of this.startable()) {
|
|
71
149
|
if (this.workerLimit !== 0 && this.processes.length >= this.workerLimit) {
|
|
72
150
|
return;
|
|
73
151
|
}
|
|
@@ -98,6 +176,7 @@ class ProcessManager {
|
|
|
98
176
|
pendingProcess.reject(err);
|
|
99
177
|
})
|
|
100
178
|
.finally(() => {
|
|
179
|
+
this.refused.delete(pendingProcess.item);
|
|
101
180
|
const index = this.processes.indexOf(item);
|
|
102
181
|
this.processes.splice(index, 1);
|
|
103
182
|
if (requests) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computeStateKey = exports.combineStateKeys = exports.getExecutionStateKeys = exports.isOwnProvable = exports.resolveEffective = void 0;
|
|
3
|
+
exports.computeStateKey = exports.combineStateKeys = exports.getExecutionStateKeys = exports.getUncachedFileSources = exports.isOwnProvable = exports.resolveEffective = void 0;
|
|
4
4
|
const get_work_cache_stats_1 = require("../../optimizer/get-work-cache-stats");
|
|
5
5
|
const work_task_1 = require("../../planner/work-task");
|
|
6
6
|
// The state-key engine is shared by the scheduler's hit/miss decision
|
|
@@ -29,6 +29,23 @@ function isOwnProvable(item, unmatched) {
|
|
|
29
29
|
return unmatched.length < item.data.src.filter((src) => !src.inherited).length;
|
|
30
30
|
}
|
|
31
31
|
exports.isOwnProvable = isOwnProvable;
|
|
32
|
+
// The tasks with `cache: none` whose file outputs the item reads, such as the digest of an
|
|
33
|
+
// image a `build` pushes. Such a task runs every time and its file can be new each time (a new
|
|
34
|
+
// build is a new digest), while the item's key holds only its sources: a cached item would
|
|
35
|
+
// restore what it made from an older file, so it runs too.
|
|
36
|
+
function getUncachedFileSources(item) {
|
|
37
|
+
if (!(0, work_task_1.isWorkTask)(item.data)) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
const makers = new Set();
|
|
41
|
+
for (const generate of item.data.generates) {
|
|
42
|
+
if (generate.isFile && generate.inherited && generate.inherited.data.caching.method === 'none') {
|
|
43
|
+
makers.add(generate.inherited);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return [...makers];
|
|
47
|
+
}
|
|
48
|
+
exports.getUncachedFileSources = getUncachedFileSources;
|
|
32
49
|
// What an item on its own way down stands for. Items that depend on or need each other in a
|
|
33
50
|
// loop fail to plan (checkForLoop) and never run: this only has to end. The loop is told by
|
|
34
51
|
// the path of one computation, never by the shared memo, which tasks checked at the same time
|
|
@@ -114,6 +131,7 @@ parentPath = new Set()) {
|
|
|
114
131
|
depKeys.push(effective.stateKey);
|
|
115
132
|
provable = provable && effective.provable;
|
|
116
133
|
}
|
|
134
|
+
provable = provable && getUncachedFileSources(item).length === 0;
|
|
117
135
|
// what a task that needs a service passed against: the sources of the service and of the
|
|
118
136
|
// tasks it depends on (its definition is in the task id, getWorkServiceCacheIdentity)
|
|
119
137
|
for (const need of item.needs) {
|