hammerkit 2.0.0-next.2 → 2.0.0-next.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache/backends/registry/registry-client.js +8 -2
- package/dist/cache/explain.js +7 -5
- package/dist/cache/last-resolved.js +11 -0
- package/dist/cli.js +4 -1
- package/dist/dashboard/assets/graph-canvas-DLioOiRN.css +1 -0
- package/dist/dashboard/assets/graph-canvas-HmkW_-XJ.js +8 -0
- package/dist/dashboard/assets/index-gIBDC_m8.css +2 -0
- package/dist/dashboard/assets/index-vE22S5E_.js +17 -0
- package/dist/dashboard/index.html +3 -3
- package/dist/dashboard/logo.png +0 -0
- 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 +21 -5
- package/dist/executer/execute-command.js +9 -15
- package/dist/executer/execute-work-task.js +14 -2
- package/dist/executer/execute-work-tree.js +2 -1
- package/dist/executer/execution-steps.js +3 -2
- package/dist/executer/local-task.js +3 -0
- package/dist/executer/print-container-options.js +10 -10
- package/dist/executer/process-manager.js +84 -5
- package/dist/executer/scheduler/enqueue-next.js +6 -1
- package/dist/executer/scheduler/state-key.js +71 -34
- package/dist/executer/task-priority.js +131 -0
- package/dist/executer/watch-loop.js +18 -5
- package/dist/file/get-file-context.js +5 -1
- 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 +98 -18
- package/dist/kubernetes/claim-layout.js +10 -1
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +10 -1
- package/dist/kubernetes/ensure-persistent-data.js +129 -26
- package/dist/kubernetes/follow-pod-logs.js +128 -29
- package/dist/kubernetes/kept-claims.js +16 -1
- package/dist/kubernetes/network-gate.js +74 -11
- package/dist/kubernetes/network-policy.js +35 -13
- package/dist/kubernetes/quota-wait.js +97 -0
- package/dist/kubernetes/remove-stale-items.js +15 -2
- package/dist/kubernetes/restore-kubernetes-data.js +28 -4
- package/dist/kubernetes/sandbox-runner.js +3 -4
- package/dist/kubernetes/store-kubernetes-data.js +14 -2
- package/dist/kubernetes/transfer-tools.js +66 -0
- package/dist/kubernetes/volumes.js +78 -14
- package/dist/optimizer/calculate-checksum.js +46 -3
- package/dist/optimizer/check-key.js +7 -0
- package/dist/optimizer/check-keys.js +19 -5
- package/dist/optimizer/get-work-cache-stats.js +55 -31
- package/dist/optimizer/work-task-cache-description.js +36 -7
- package/dist/parser/read-build-file.js +8 -3
- package/dist/planner/utils/append-work-service.js +1 -1
- package/dist/planner/utils/append-work-task.js +1 -1
- package/dist/planner/utils/assert-item-paths.js +6 -7
- package/dist/planner/utils/template-value.js +20 -4
- package/dist/planner/work-item-executions.js +27 -0
- package/dist/planner/work-runtime-docker.js +31 -50
- package/dist/planner/work-runtime-kubernetes.js +70 -41
- 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-work-commands.js +19 -10
- package/dist/schema/schema-parser.js +46 -2
- package/dist/schema/work-scope-parser.js +16 -1
- package/dist/secrets/secret-catalog.js +8 -1
- package/dist/server/capacity.js +71 -41
- package/dist/server/dashboard.js +27 -9
- package/dist/server/endpoints.js +10 -1
- package/dist/server/executor.js +68 -35
- package/dist/server/kubernetes-backend.js +29 -4
- package/dist/server/kubernetes-sandbox-storage.js +14 -4
- package/dist/server/oauth.js +16 -1
- package/dist/server/overview.js +80 -11
- package/dist/server/plan.js +41 -6
- package/dist/server/policy.js +22 -9
- 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-source-environment.js +39 -0
- package/dist/server/run-worker.js +71 -9
- package/dist/server/runs.js +133 -7
- package/dist/server/sandbox-files.js +339 -55
- package/dist/server/sandbox-patch.js +43 -17
- package/dist/server/sandboxes.js +57 -23
- package/dist/server/server-config.js +28 -5
- package/dist/server/server.js +94 -16
- package/dist/server/service-runs.js +50 -5
- package/dist/server/sources.js +68 -11
- package/dist/server/timings.js +23 -3
- package/dist/utils/buffer-context.js +30 -20
- package/dist/utils/limit.js +30 -0
- package/dist/utils/line-splitter.js +52 -0
- package/dist/utils/read-lines.js +65 -0
- package/dist/utils/tar.js +51 -1
- package/dist/utils/units.js +36 -1
- package/dist/utils/web-links.js +34 -0
- package/package.json +1 -1
- package/dist/dashboard/assets/index-CjnKm5-3.css +0 -2
- package/dist/dashboard/assets/index-zPXa4klZ.js +0 -13
- package/dist/dashboard/favicon.svg +0 -1
|
@@ -4,12 +4,18 @@ exports.getStaleItemSelector = exports.removeStaleItems = void 0;
|
|
|
4
4
|
const job_placement_1 = require("./job-placement");
|
|
5
5
|
const resources_1 = require("./resources");
|
|
6
6
|
const apply_1 = require("./apply");
|
|
7
|
+
const network_policy_1 = require("./network-policy");
|
|
7
8
|
/**
|
|
8
9
|
* What a service run made for items it has no more, once it moved to another commit: the
|
|
9
10
|
* Deployment, Service, Secret, policies and Jobs of a service or task whose id changed (a new
|
|
10
|
-
* image, other volumes). Their claims stay, with the namespace of the run.
|
|
11
|
+
* image, other volumes). Their claims stay, with the namespace of the run. The policies go
|
|
12
|
+
* last, once the pods they limit ended: a pod that is still terminating would otherwise run
|
|
13
|
+
* a moment without its limits. When pods outlast the wait, the policies stay, and the next
|
|
14
|
+
* move or the end of the run removes them.
|
|
11
15
|
*/
|
|
12
|
-
async function removeStaleItems(instance, env, ids
|
|
16
|
+
async function removeStaleItems(instance, env, ids,
|
|
17
|
+
// a run stopped while its old pods end: the policies stay, and go with the run
|
|
18
|
+
options = {}) {
|
|
13
19
|
if (!env.server) {
|
|
14
20
|
return;
|
|
15
21
|
}
|
|
@@ -20,6 +26,13 @@ async function removeStaleItems(instance, env, ids) {
|
|
|
20
26
|
await instance.batchApi.deleteCollectionNamespacedJob({ ...selector, propagationPolicy: 'Background' });
|
|
21
27
|
await instance.coreApi.deleteCollectionNamespacedService(selector);
|
|
22
28
|
await instance.coreApi.deleteCollectionNamespacedSecret(selector);
|
|
29
|
+
const ended = await (0, network_policy_1.awaitPodsEnded)(instance, env, labelSelector, options.podEndTimeout, options.podEndPollInterval, options.signal);
|
|
30
|
+
if (options.signal?.aborted) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!ended) {
|
|
34
|
+
throw new Error('pods of the previous commit are still running, so their network policies stay');
|
|
35
|
+
}
|
|
23
36
|
const policies = await instance.objectApi.list('networking.k8s.io/v1', 'NetworkPolicy', namespace, undefined, undefined, undefined, undefined, labelSelector);
|
|
24
37
|
for (const policy of policies.items) {
|
|
25
38
|
const metadata = { name: policy.metadata?.name, namespace };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.restoreKubernetesData = exports.getRestoreTarget = void 0;
|
|
3
|
+
exports.restoreKubernetesData = exports.getRestoreTarget = exports.RESTORE_FILE = void 0;
|
|
4
4
|
const event_cache_1 = require("../executer/event-cache");
|
|
5
5
|
const log_1 = require("../log");
|
|
6
6
|
const volumes_1 = require("./volumes");
|
|
7
7
|
const ensure_persistent_data_1 = require("./ensure-persistent-data");
|
|
8
8
|
const claim_layout_1 = require("./claim-layout");
|
|
9
|
+
const transfer_tools_1 = require("./transfer-tools");
|
|
10
|
+
// Unpacks the archive of an output that is a file to `$1`: by its content, since the name in
|
|
11
|
+
// the archive is the file's and the one in the claim may carry a hash (see getClaimSubPath)
|
|
12
|
+
exports.RESTORE_FILE = 'mkdir -p "$(dirname "$1")" && rm -rf "$1" && tar xzf - -O > "$1"';
|
|
9
13
|
// Where the upload pod (which mounts the work's claim at /dev/hammerkit/<id>) unpacks the
|
|
10
14
|
// archive of an output: the output's place in the claim, which its mount reads
|
|
11
15
|
function getRestoreTarget(work, path,
|
|
@@ -16,14 +20,28 @@ stateDir) {
|
|
|
16
20
|
exports.getRestoreTarget = getRestoreTarget;
|
|
17
21
|
async function restoreKubernetesData(work, kubernetes, instance, environment, path,
|
|
18
22
|
// the kept claim of the work holds what an earlier run left, which goes first; on a
|
|
19
|
-
// service run, the outputs go into the folder of `stateKey` (see getStateFilesDir)
|
|
23
|
+
// service run, the outputs go into the folder of `stateKey` (see getStateFilesDir);
|
|
24
|
+
// `otherStates`: the folders of the other states go but these (the ones pods of the run
|
|
25
|
+
// mount), and the folder of `stateKey` is emptied first
|
|
20
26
|
options = {}) {
|
|
21
27
|
const persistence = await (0, volumes_1.getKubernetesPersistence)(work, kubernetes, options.stateKey);
|
|
22
28
|
const stateDir = kubernetes.server?.serviceRun ? (0, volumes_1.getItemFilesDir)(work, options.stateKey) : undefined;
|
|
23
|
-
|
|
29
|
+
// an output that is a file: its archive holds it alone (see storeKubernetesData), and it
|
|
30
|
+
// takes the place of whatever is at its path in the claim
|
|
31
|
+
const files = new Set(work.data.type === 'container-task'
|
|
32
|
+
? work.data.generates
|
|
33
|
+
.filter((generate) => generate.isFile && !generate.inherited)
|
|
34
|
+
.map((generate) => generate.path)
|
|
35
|
+
: []);
|
|
36
|
+
// a run stopped while the pod waits for room under the quota
|
|
37
|
+
const { signal } = environment.abortCtrl;
|
|
38
|
+
await (0, ensure_persistent_data_1.getPodForPersistence)(instance, kubernetes, work, persistence, 'write', signal, async (name) => {
|
|
24
39
|
if (options.reset) {
|
|
25
40
|
await (0, ensure_persistent_data_1.clearClaim)(instance, kubernetes, work, name);
|
|
26
41
|
}
|
|
42
|
+
if (stateDir && options.otherStates) {
|
|
43
|
+
await (0, ensure_persistent_data_1.clearStateFiles)(instance, kubernetes, work, name, stateDir, options.otherStates);
|
|
44
|
+
}
|
|
27
45
|
for (const generatedArchive of (0, event_cache_1.getArchivePaths)(work.data, path)) {
|
|
28
46
|
if (!(await environment.file.exists(generatedArchive.filename))) {
|
|
29
47
|
continue;
|
|
@@ -32,7 +50,13 @@ options = {}) {
|
|
|
32
50
|
// a claim made for this run (a server removes the claims of a run when it
|
|
33
51
|
// ends) does not have the directory of the output yet
|
|
34
52
|
let failure = null;
|
|
35
|
-
const res = await instance.exec.exec(kubernetes.namespace, name, 'volume',
|
|
53
|
+
const res = await instance.exec.exec(kubernetes.namespace, name, 'volume', (0, transfer_tools_1.inTransferPod)([
|
|
54
|
+
'sh',
|
|
55
|
+
'-c',
|
|
56
|
+
files.has(generatedArchive.path) ? exports.RESTORE_FILE : 'mkdir -p "$1" && tar xzf - -C "$1"',
|
|
57
|
+
'sh',
|
|
58
|
+
targetPath,
|
|
59
|
+
]), process.stdout, process.stderr, environment.file.readStream(generatedArchive.filename), false, (status) => {
|
|
36
60
|
work.status.write('debug', `upload ${generatedArchive.filename} to ${name}: ${status.status}`);
|
|
37
61
|
if (status.status !== 'Success') {
|
|
38
62
|
failure = status.message ?? status.reason ?? 'unknown';
|
|
@@ -16,6 +16,7 @@ const container_resources_1 = require("./container-resources");
|
|
|
16
16
|
const job_placement_1 = require("./job-placement");
|
|
17
17
|
const network_policy_1 = require("./network-policy");
|
|
18
18
|
const resources_1 = require("./resources");
|
|
19
|
+
const transfer_tools_1 = require("./transfer-tools");
|
|
19
20
|
const volumes_1 = require("./volumes");
|
|
20
21
|
/**
|
|
21
22
|
* The runner of a sandbox: one pod that the commands of a run on the sandbox are exec'd
|
|
@@ -46,10 +47,8 @@ const TMP_VOLUME = 'hammerkit-runner-tmp';
|
|
|
46
47
|
const TOOLS_VOLUME = 'hammerkit-runner-tools';
|
|
47
48
|
const TOOLS_PATH = '/.hammerkit';
|
|
48
49
|
const BUSYBOX = `${TOOLS_PATH}/busybox`;
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
// busybox:<version>-musl`).
|
|
52
|
-
exports.RUNNER_TOOLS_IMAGE = 'busybox:1.37.0-musl@sha256:5cec3fc171c87218698e85a52af7087de727372aae264a787b8112901a5b0092';
|
|
50
|
+
// copied into the runner by an init container
|
|
51
|
+
exports.RUNNER_TOOLS_IMAGE = transfer_tools_1.HELPER_TOOLS_IMAGE;
|
|
53
52
|
const RUNNER_START_MS = 5 * 60 * 1000;
|
|
54
53
|
const RUNNER_POLL_MS = 250;
|
|
55
54
|
const PULL_FAILURES = ['ErrImagePull', 'ImagePullBackOff', 'InvalidImageName'];
|
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.storeKubernetesData = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
4
5
|
const log_1 = require("../log");
|
|
5
6
|
const event_cache_1 = require("../executer/event-cache");
|
|
6
7
|
const volumes_1 = require("./volumes");
|
|
7
8
|
const ensure_persistent_data_1 = require("./ensure-persistent-data");
|
|
9
|
+
const transfer_tools_1 = require("./transfer-tools");
|
|
8
10
|
async function storeKubernetesData(work, kubernetes, instance, environment, path,
|
|
9
11
|
// the state the outputs are of: on a service run, they are in its folder (see
|
|
10
12
|
// getStateFilesDir)
|
|
11
13
|
stateKey) {
|
|
12
14
|
const persistence = await (0, volumes_1.getKubernetesPersistence)(work, kubernetes, stateKey);
|
|
13
|
-
|
|
15
|
+
// a run stopped while the pod waits for room under the quota
|
|
16
|
+
const { signal } = environment.abortCtrl;
|
|
17
|
+
// an output that is a file is mounted as one: its archive holds it by its name, as on Docker
|
|
18
|
+
const files = new Set(work.data.type === 'container-task'
|
|
19
|
+
? work.data.generates
|
|
20
|
+
.filter((generate) => generate.isFile && !generate.inherited)
|
|
21
|
+
.map((generate) => generate.path)
|
|
22
|
+
: []);
|
|
23
|
+
await (0, ensure_persistent_data_1.getPodForPersistence)(instance, kubernetes, work, persistence, 'read', signal, async (name) => {
|
|
14
24
|
for (const generatedArchive of (0, event_cache_1.getArchivePaths)(work.data, path)) {
|
|
15
25
|
const writerStream = environment.file.createWriteStream(generatedArchive.filename);
|
|
16
|
-
const res = await instance.exec.exec(kubernetes.namespace, name, 'volume',
|
|
26
|
+
const res = await instance.exec.exec(kubernetes.namespace, name, 'volume', (0, transfer_tools_1.inTransferPod)(files.has(generatedArchive.path)
|
|
27
|
+
? ['tar', 'zcf', '-', '-C', path_1.posix.dirname(generatedArchive.path), path_1.posix.basename(generatedArchive.path)]
|
|
28
|
+
: ['tar', 'zcf', '-', '-C', generatedArchive.path, '.']), writerStream, process.stderr, null, false, (status) => {
|
|
17
29
|
work.status.write('debug', `archive ${generatedArchive.path} of ${name}: ${status}`);
|
|
18
30
|
writerStream.close();
|
|
19
31
|
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRANSFER_TOOLS_ENV = exports.TRANSFER_TOOLS_MOUNT = exports.TRANSFER_TOOLS_VOLUMES = exports.getTransferToolsInitContainer = exports.inTransferPod = exports.isTransferToolsPath = exports.TRANSFER_BUSYBOX = exports.TRANSFER_TOOLS_PATH = exports.HELPER_TOOLS_IMAGE = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
// Pinned, static (it runs in any image) busybox: the tools of the pods hammerkit runs its own
|
|
6
|
+
// commands in, such as the runner of a sandbox and the pods that copy files into and out of
|
|
7
|
+
// a claim. To bump it, take the index digest of the tag (`docker buildx imagetools inspect
|
|
8
|
+
// busybox:<version>-musl`).
|
|
9
|
+
exports.HELPER_TOOLS_IMAGE = 'busybox:1.37.0-musl@sha256:5cec3fc171c87218698e85a52af7087de727372aae264a787b8112901a5b0092';
|
|
10
|
+
/**
|
|
11
|
+
* The pod that copies files into and out of a claim mounts the outputs of a task at the
|
|
12
|
+
* paths the task wrote them to, which may be any path, /bin included. So what it runs comes
|
|
13
|
+
* from a folder no mount of the task can be: an init container copies the pinned busybox
|
|
14
|
+
* into it and links each of its tools there, and the pod's own container finds them by its
|
|
15
|
+
* PATH, mounted read-only. Every command starts with the busybox itself, so a tool of the
|
|
16
|
+
* same name in a mounted output never runs.
|
|
17
|
+
*/
|
|
18
|
+
exports.TRANSFER_TOOLS_PATH = '/.hammerkit';
|
|
19
|
+
const TRANSFER_TOOLS_VOLUME = 'hammerkit-transfer-tools';
|
|
20
|
+
exports.TRANSFER_BUSYBOX = `${exports.TRANSFER_TOOLS_PATH}/busybox`;
|
|
21
|
+
const TRANSFER_BIN = `${exports.TRANSFER_TOOLS_PATH}/bin`;
|
|
22
|
+
// a path in or over the folder of the tools (`/`, `/.hammerkit`, `/.hammerkit/bin`), where a
|
|
23
|
+
// mount would hide them
|
|
24
|
+
function isTransferToolsPath(path) {
|
|
25
|
+
const normalized = path_1.posix.normalize(path).replace(/\/+$/, '') || '/';
|
|
26
|
+
return normalized === '/' || normalized === exports.TRANSFER_TOOLS_PATH || normalized.startsWith(`${exports.TRANSFER_TOOLS_PATH}/`);
|
|
27
|
+
}
|
|
28
|
+
exports.isTransferToolsPath = isTransferToolsPath;
|
|
29
|
+
// `command` (a tool and its arguments) run by the busybox of the transfer pod
|
|
30
|
+
function inTransferPod(command) {
|
|
31
|
+
return [exports.TRANSFER_BUSYBOX, ...command];
|
|
32
|
+
}
|
|
33
|
+
exports.inTransferPod = inTransferPod;
|
|
34
|
+
function getTransferToolsInitContainer() {
|
|
35
|
+
return {
|
|
36
|
+
name: TRANSFER_TOOLS_VOLUME,
|
|
37
|
+
image: exports.HELPER_TOOLS_IMAGE,
|
|
38
|
+
command: [
|
|
39
|
+
'/bin/busybox',
|
|
40
|
+
'sh',
|
|
41
|
+
'-c',
|
|
42
|
+
`/bin/busybox cp /bin/busybox ${exports.TRANSFER_BUSYBOX} && /bin/busybox mkdir -p ${TRANSFER_BIN} && ${exports.TRANSFER_BUSYBOX} --install -s ${TRANSFER_BIN}`,
|
|
43
|
+
],
|
|
44
|
+
volumeMounts: [{ name: TRANSFER_TOOLS_VOLUME, mountPath: exports.TRANSFER_TOOLS_PATH }],
|
|
45
|
+
securityContext: {
|
|
46
|
+
runAsNonRoot: true,
|
|
47
|
+
runAsUser: 65534,
|
|
48
|
+
allowPrivilegeEscalation: false,
|
|
49
|
+
readOnlyRootFilesystem: true,
|
|
50
|
+
capabilities: { drop: ['ALL'] },
|
|
51
|
+
},
|
|
52
|
+
// its own requests: the defaults of a namespace are sized for tasks, and a pod's
|
|
53
|
+
// request is the larger of its init containers' and the sum of its containers'
|
|
54
|
+
resources: { requests: { cpu: '10m', memory: '16Mi' }, limits: { memory: '16Mi' } },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.getTransferToolsInitContainer = getTransferToolsInitContainer;
|
|
58
|
+
exports.TRANSFER_TOOLS_VOLUMES = [{ name: TRANSFER_TOOLS_VOLUME, emptyDir: {} }];
|
|
59
|
+
exports.TRANSFER_TOOLS_MOUNT = {
|
|
60
|
+
name: TRANSFER_TOOLS_VOLUME,
|
|
61
|
+
mountPath: exports.TRANSFER_TOOLS_PATH,
|
|
62
|
+
readOnly: true,
|
|
63
|
+
};
|
|
64
|
+
// the tools a script of the transfer pod runs, and nothing else
|
|
65
|
+
exports.TRANSFER_TOOLS_ENV = [{ name: 'PATH', value: TRANSFER_BIN }];
|
|
66
|
+
//# sourceMappingURL=transfer-tools.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getItemFilesDir = exports.isLiveService = exports.LIVE_FILES_DIR = exports.getStateFilesDir = exports.STATE_FILES_PREFIX = exports.getSandboxAffinity = exports.SANDBOX_LABEL = exports.getClaimMountLabel = exports.getClaimPodSpec = exports.getWorkspacePodSpec = exports.appendVolume = exports.getKubernetesPersistence = exports.getVolumeName = void 0;
|
|
3
|
+
exports.getItemFilesDir = exports.isLiveService = exports.LIVE_FILES_DIR = exports.getStateFilesDir = exports.STATE_FILES_PREFIX = exports.getSandboxAffinity = exports.SANDBOX_LABEL = exports.getClaimMountLabel = exports.getClaimPodSpec = exports.getWorkspacePodSpec = exports.appendVolume = exports.getMountedSources = exports.getKubernetesPersistence = exports.getVolumeName = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
@@ -59,29 +59,34 @@ stateKey) {
|
|
|
59
59
|
sources: [],
|
|
60
60
|
mounts: [],
|
|
61
61
|
initCommands: [],
|
|
62
|
+
files: [],
|
|
62
63
|
};
|
|
63
64
|
const workspace = kubernetes.server?.workspace;
|
|
64
65
|
for (const mount of work.data.mounts) {
|
|
66
|
+
const isFile = isLocalFile(mount.localPath, mount.isFile);
|
|
65
67
|
if (workspace &&
|
|
66
|
-
appendWorkspaceMount(workspace, persistence, mount.containerPath, mount.localPath,
|
|
68
|
+
appendWorkspaceMount(workspace, persistence, mount.containerPath, mount.localPath, isFile, mount.readOnly)) {
|
|
67
69
|
continue;
|
|
68
70
|
}
|
|
69
|
-
appendVolume(work, persistence, mount.containerPath, mount.localPath,
|
|
71
|
+
appendVolume(work, persistence, mount.containerPath, mount.localPath, isFile, true, kubernetes, mounted, own);
|
|
70
72
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
// its deps' src too, uploaded into its own claim: a container task sees them as it does on
|
|
74
|
+
// docker (a tsc -b of a project that references another reads the other's tsconfig)
|
|
75
|
+
for (const src of getMountedSources(work.data.src)) {
|
|
76
|
+
const isFile = isLocalFile(src.absolutePath, src.isFile);
|
|
77
|
+
if (workspace && appendWorkspaceMount(workspace, persistence, src.absolutePath, src.absolutePath, isFile, false)) {
|
|
73
78
|
continue;
|
|
74
79
|
}
|
|
75
|
-
|
|
76
|
-
appendWorkspaceMount(workspace, persistence, src.absolutePath, src.absolutePath, src.isFile, false)) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
appendVolume(work, persistence, src.absolutePath, src.absolutePath, src.isFile, true, kubernetes, mounted, own); // TODO matcher
|
|
80
|
+
appendVolume(work, persistence, src.absolutePath, src.absolutePath, isFile, true, kubernetes, mounted, own, src.inherited ? (0, claim_layout_1.getInheritedSourceSubPath)(work, src.absolutePath) : undefined); // TODO matcher
|
|
80
81
|
}
|
|
81
82
|
if (work.data.type === 'container-task') {
|
|
82
83
|
for (const generate of work.data.generates) {
|
|
83
|
-
appendVolume(generate.inherited ?? work, persistence, generate.path, null,
|
|
84
|
+
const subPath = appendVolume(generate.inherited ?? work, persistence, generate.path, null, generate.isFile, !!generate.inherited, kubernetes, dirOf(generate.inherited ?? work));
|
|
85
|
+
if (generate.isFile && !generate.inherited) {
|
|
86
|
+
persistence.files.push(subPath);
|
|
87
|
+
}
|
|
84
88
|
}
|
|
89
|
+
persistence.files.push(...getNestedMountPlaces(persistence, getVolumeName(work, kubernetes)));
|
|
85
90
|
}
|
|
86
91
|
else {
|
|
87
92
|
for (const volume of work.data.volumes) {
|
|
@@ -93,14 +98,70 @@ stateKey) {
|
|
|
93
98
|
return persistence;
|
|
94
99
|
}
|
|
95
100
|
exports.getKubernetesPersistence = getKubernetesPersistence;
|
|
101
|
+
// Whether the path `localPath` is a file: what it is on disk, as docker binds it, and else
|
|
102
|
+
// `guess`, which goes by its name (a `Dockerfile` or `LICENSE` has no extension, and a
|
|
103
|
+
// `conf.d` folder has one)
|
|
104
|
+
function isLocalFile(localPath, guess) {
|
|
105
|
+
try {
|
|
106
|
+
return !(0, fs_1.statSync)(localPath).isDirectory();
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return guess;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// The srcs a pod mounts, each path once: a src inside a folder of another one (`docs/Dockerfile`
|
|
113
|
+
// with `docs`) is in the upload and the mount of that folder, as on docker, and is not mounted
|
|
114
|
+
// apart. A mount of its own inside the folder, which is mounted read only, needs its place
|
|
115
|
+
// there, and two mounts of the same path are refused by Kubernetes. A task's own src is kept
|
|
116
|
+
// before the same path of a dep, so it stays where getClaimSubPath puts it.
|
|
117
|
+
function getMountedSources(sources) {
|
|
118
|
+
const unique = new Map();
|
|
119
|
+
for (const src of sources) {
|
|
120
|
+
const other = unique.get(src.absolutePath);
|
|
121
|
+
if (!other || (other.inherited && !src.inherited)) {
|
|
122
|
+
unique.set(src.absolutePath, src);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const all = [...unique.values()];
|
|
126
|
+
const folders = all.filter((src) => !isLocalFile(src.absolutePath, src.isFile));
|
|
127
|
+
return all.filter((src) => !folders.some((folder) => folder !== src && isInside(folder.absolutePath, src.absolutePath)));
|
|
128
|
+
}
|
|
129
|
+
exports.getMountedSources = getMountedSources;
|
|
130
|
+
function isInside(folder, path) {
|
|
131
|
+
const rel = (0, path_1.relative)(folder, path);
|
|
132
|
+
return rel.length > 0 && rel !== '..' && !rel.startsWith(`..${path_1.sep}`) && !(0, path_1.isAbsolute)(rel);
|
|
133
|
+
}
|
|
134
|
+
// The places in the claim `claim` of the paths mounted inside a folder that is mounted read
|
|
135
|
+
// only from it: an output of a task inside a folder of its src (pkg/coverage/lcov.info with a
|
|
136
|
+
// src pkg). The container runtime makes the place of a mount where it isn't there, which it
|
|
137
|
+
// can't in a folder mounted read only, and the pod fails to start (exit 128). Each is in the
|
|
138
|
+
// claim's folder of the read-only path, a folder ending in `/`, or a file.
|
|
139
|
+
function getNestedMountPlaces(persistence, claim) {
|
|
140
|
+
const own = persistence.mounts.filter((m) => !m.workspace);
|
|
141
|
+
const folders = own.filter((m) => m.mount.name === claim && m.mount.readOnly && m.cwd === m.mount.mountPath && m.mount.subPath);
|
|
142
|
+
const places = [];
|
|
143
|
+
for (const mount of own) {
|
|
144
|
+
const parent = folders
|
|
145
|
+
.filter((folder) => folder !== mount && isInside(folder.mount.mountPath, mount.mount.mountPath))
|
|
146
|
+
.sort((a, b) => b.mount.mountPath.length - a.mount.mountPath.length)[0];
|
|
147
|
+
if (!parent) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const inside = (0, path_1.relative)(parent.mount.mountPath, mount.mount.mountPath).split(path_1.sep).join('/');
|
|
151
|
+
const place = `${parent.mount.subPath}/${inside}`;
|
|
152
|
+
places.push(mount.cwd === mount.mount.mountPath ? `${place}/` : place);
|
|
153
|
+
}
|
|
154
|
+
return places;
|
|
155
|
+
}
|
|
96
156
|
function appendVolume(sourceWork, persistence, containerPath, localPath, isFile, readOnly, kubernetes,
|
|
97
157
|
// the folder of the state of `sourceWork` the path is in, see getStateFilesDir
|
|
98
158
|
stateDir,
|
|
99
159
|
// the folder its upload goes to, when it is not the one the path is mounted from (a
|
|
100
160
|
// service that watches its files, see syncLiveFiles)
|
|
101
|
-
uploadDir = stateDir
|
|
161
|
+
uploadDir = stateDir,
|
|
162
|
+
// where it goes in the claim, when not where getClaimSubPath puts it
|
|
163
|
+
claimPath = (0, claim_layout_1.getClaimSubPath)(sourceWork, containerPath)) {
|
|
102
164
|
const volumeName = getVolumeName(sourceWork, kubernetes);
|
|
103
|
-
const claimPath = (0, claim_layout_1.getClaimSubPath)(sourceWork, containerPath);
|
|
104
165
|
const subPath = (stateDir ? `${stateDir}/` : '') + claimPath;
|
|
105
166
|
const existVolume = persistence.volumes.some((v) => v.name === volumeName);
|
|
106
167
|
if (!existVolume) {
|
|
@@ -128,12 +189,15 @@ uploadDir = stateDir) {
|
|
|
128
189
|
if (localPath) {
|
|
129
190
|
persistence.sources.push({
|
|
130
191
|
localPath: localPath,
|
|
131
|
-
|
|
192
|
+
// TODO: a matcher that uploads less than the whole folder has to keep the srcs
|
|
193
|
+
// inside it that getMountedSources leaves out (a `docs/Dockerfile` next to `docs/**/*.md`)
|
|
194
|
+
matcher: () => true,
|
|
132
195
|
containerPath,
|
|
133
196
|
subPath: (uploadDir ? `${uploadDir}/` : '') + claimPath,
|
|
134
197
|
stateKey: '', // TODO
|
|
135
198
|
});
|
|
136
199
|
}
|
|
200
|
+
return subPath;
|
|
137
201
|
}
|
|
138
202
|
exports.appendVolume = appendVolume;
|
|
139
203
|
/**
|
|
@@ -1,17 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateChecksum = void 0;
|
|
3
|
+
exports.calculateChecksum = exports.racyWindow = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
|
+
// The checksums a process computed, by the file context and path: every task of a run hashes
|
|
6
|
+
// the sources of the tasks it depends on too, so most files are asked for many times
|
|
7
|
+
const known = new WeakMap();
|
|
8
|
+
// A file written again soon after it was hashed, with the same size, keeps its times on a
|
|
9
|
+
// file system whose timestamps are coarser than that: a checksum of a file changed within
|
|
10
|
+
// the window before it was hashed is not kept. Whole seconds are taken for a file system
|
|
11
|
+
// that has no more (FAT, ext3, HFS+), else the window is short.
|
|
12
|
+
function racyWindow(stats) {
|
|
13
|
+
return stats.lastModified % 1000 === 0 && stats.identity.changed % 1000 === 0 ? 2000 : 50;
|
|
14
|
+
}
|
|
15
|
+
exports.racyWindow = racyWindow;
|
|
5
16
|
// Hashes the raw bytes: decoding to text first would map every invalid UTF-8
|
|
6
17
|
// sequence to U+FFFD, so two different binary files could share a checksum.
|
|
7
18
|
// For UTF-8 text the result is unchanged. sha256, which nobody can make two files share:
|
|
8
19
|
// a cache hit is also what a verified check counts (check-key.ts).
|
|
9
|
-
|
|
20
|
+
//
|
|
21
|
+
// With the `stats` of the file, the checksum is reused while the file stays the same file:
|
|
22
|
+
// the same modification and change time, size and inode. A write changes its times, a
|
|
23
|
+
// replacement (a checkout, a rename over it) its inode.
|
|
24
|
+
async function calculateChecksum(environment, path, stats) {
|
|
25
|
+
const identity = stats?.identity;
|
|
26
|
+
if (!identity) {
|
|
27
|
+
return hashFile(environment, path);
|
|
28
|
+
}
|
|
29
|
+
let files = known.get(environment.file);
|
|
30
|
+
if (!files) {
|
|
31
|
+
files = new Map();
|
|
32
|
+
known.set(environment.file, files);
|
|
33
|
+
}
|
|
34
|
+
const cached = files.get(path);
|
|
35
|
+
if (cached &&
|
|
36
|
+
cached.lastModified === stats.lastModified &&
|
|
37
|
+
cached.size === identity.size &&
|
|
38
|
+
cached.changed === identity.changed &&
|
|
39
|
+
cached.inode === identity.inode) {
|
|
40
|
+
return cached.checksum;
|
|
41
|
+
}
|
|
42
|
+
const hashedAt = Date.now();
|
|
43
|
+
const checksum = await hashFile(environment, path);
|
|
44
|
+
if (hashedAt - Math.max(stats.lastModified, identity.changed) > racyWindow({ ...stats, identity })) {
|
|
45
|
+
files.set(path, { lastModified: stats.lastModified, ...identity, checksum });
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
files.delete(path);
|
|
49
|
+
}
|
|
50
|
+
return checksum;
|
|
51
|
+
}
|
|
52
|
+
exports.calculateChecksum = calculateChecksum;
|
|
53
|
+
async function hashFile(environment, path) {
|
|
10
54
|
const hash = (0, crypto_1.createHash)('sha256');
|
|
11
55
|
for await (const chunk of environment.file.readStream(path)) {
|
|
12
56
|
hash.update(chunk);
|
|
13
57
|
}
|
|
14
58
|
return hash.digest('hex');
|
|
15
59
|
}
|
|
16
|
-
exports.calculateChecksum = calculateChecksum;
|
|
17
60
|
//# sourceMappingURL=calculate-checksum.js.map
|
|
@@ -5,6 +5,7 @@ const crypto_1 = require("crypto");
|
|
|
5
5
|
const state_key_1 = require("../executer/scheduler/state-key");
|
|
6
6
|
const get_work_cache_stats_1 = require("./get-work-cache-stats");
|
|
7
7
|
const work_task_cache_description_1 = require("./work-task-cache-description");
|
|
8
|
+
const run_source_envs_1 = require("../environment/run-source-envs");
|
|
8
9
|
/**
|
|
9
10
|
* What a passed check is recorded under, and what `remote verify` looks it up by: the
|
|
10
11
|
* inputs of the task's cache key, so a cached result counts for the same key it was
|
|
@@ -46,6 +47,12 @@ function getNeedKey(item, environment, memo, path) {
|
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
async function getInputKeys(item, environment, memo, path) {
|
|
50
|
+
// what a run is from differs from run to run, and `remote verify` never has it: a result
|
|
51
|
+
// that read it says nothing about the files (a CI job keyed the same task on the default)
|
|
52
|
+
const runSource = ('envs' in item.data ? item.data.envs.processNames ?? [] : []).find(run_source_envs_1.isRunSourceEnv);
|
|
53
|
+
if (runSource) {
|
|
54
|
+
throw new Error(`${item.name} reads ${runSource}, which differs from run to run`);
|
|
55
|
+
}
|
|
49
56
|
const deps = [];
|
|
50
57
|
for (const dep of item.deps) {
|
|
51
58
|
const key = await getCheckKey(dep, environment, memo, path);
|
|
@@ -15,9 +15,11 @@ const check_key_1 = require("./check-key");
|
|
|
15
15
|
* nodes) is the server's, and a result counts for the server it passed on. The secrets'
|
|
16
16
|
* providers and accounts are the server's too, and no part of a key, so any is taken here.
|
|
17
17
|
*/
|
|
18
|
-
async function getCheckKeys(entry, environment, scope
|
|
18
|
+
async function getCheckKeys(entry, environment, scope,
|
|
19
|
+
// on a server: the build files are read from the published files and work on the source
|
|
20
|
+
directory) {
|
|
19
21
|
const keyed = { ...environment, hosted: { catalog: anyCatalog(), localTasksInContainers: true } };
|
|
20
|
-
const { ctx, scope: parsed } = await (0, schema_parser_1.createParseContext)(entry, keyed);
|
|
22
|
+
const { ctx, scope: parsed } = await (0, schema_parser_1.createParseContext)(entry, keyed, { directory });
|
|
21
23
|
const workTree = (0, work_scope_parser_1.getWorkContext)(await (0, reference_parser_1.parseReferences)(ctx, parsed, keyed), scope, keyed);
|
|
22
24
|
const memo = new Map();
|
|
23
25
|
const keys = {};
|
|
@@ -40,6 +42,18 @@ async function getCheckKeys(entry, environment, scope) {
|
|
|
40
42
|
}
|
|
41
43
|
exports.getCheckKeys = getCheckKeys;
|
|
42
44
|
// Every provider and account name resolves, to a definition nothing runs.
|
|
45
|
+
// A record that holds an entry under any name, as its own property: the catalog is looked up by
|
|
46
|
+
// own properties only.
|
|
47
|
+
function anyRecord(make) {
|
|
48
|
+
const entry = (name) => (typeof name === 'string' ? make(name) : undefined);
|
|
49
|
+
return new Proxy({}, {
|
|
50
|
+
get: (_target, name) => entry(name),
|
|
51
|
+
has: (_target, name) => typeof name === 'string',
|
|
52
|
+
getOwnPropertyDescriptor: (_target, name) => typeof name === 'string'
|
|
53
|
+
? { value: make(name), writable: false, enumerable: true, configurable: true }
|
|
54
|
+
: undefined,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
43
57
|
function anyCatalog() {
|
|
44
58
|
const provider = (name) => ({
|
|
45
59
|
name,
|
|
@@ -52,12 +66,12 @@ function anyCatalog() {
|
|
|
52
66
|
const account = (name) => ({
|
|
53
67
|
name,
|
|
54
68
|
default: false,
|
|
55
|
-
providers:
|
|
69
|
+
providers: anyRecord(() => ({ env: {} })),
|
|
56
70
|
declaredIn: 'the server',
|
|
57
71
|
});
|
|
58
72
|
return {
|
|
59
|
-
providers:
|
|
60
|
-
accounts:
|
|
73
|
+
providers: anyRecord(provider),
|
|
74
|
+
accounts: anyRecord(account),
|
|
61
75
|
explicitAccounts: true,
|
|
62
76
|
};
|
|
63
77
|
}
|