hammerkit 2.0.0-next.9 → 2.0.0
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/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-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/dashboard.js +8 -5
- package/dist/server/executor.js +58 -35
- package/dist/server/kubernetes-backend.js +29 -4
- 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 +59 -1
- package/dist/server/sandbox-files.js +232 -39
- package/dist/server/server-config.js +24 -4
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeSandboxProxies = exports.getProxyReadinessScript = exports.removeAllKubernetesItemNetworks = exports.releaseKubernetesItemNetwork = exports.awaitPodsEnded = exports.removeKubernetesItemNetwork = exports.ensureKubernetesItemNetwork = exports.buildProxyPolicy = exports.buildNetworkPolicy = exports.getNetworkPolicyName = exports.getSandboxProxy = exports.getProxyName = exports.getNetworkLabels = exports.NETWORK_PROXY = exports.NETWORK_LIMITED = exports.NETWORK_LABEL = exports.PROXY_OF_SANDBOX_LABEL = exports.RUN_LABEL = void 0;
|
|
3
|
+
exports.removeSandboxProxies = exports.getProxyReadinessScript = exports.removeAllKubernetesItemNetworks = exports.releaseKubernetesItemNetwork = exports.awaitPodsEnded = exports.removeKubernetesItemNetwork = exports.ensureKubernetesItemNetwork = exports.buildProxyPolicy = exports.buildNetworkPolicy = exports.getNetworkPolicyName = exports.getSandboxProxy = exports.getProxyName = exports.getNetworkLabels = exports.getTransferNetworkLabels = exports.TRANSFER_LABEL = exports.NETWORK_PROXY = exports.NETWORK_LIMITED = exports.NETWORK_LABEL = exports.PROXY_OF_SANDBOX_LABEL = exports.RUN_LABEL = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const stream_1 = require("stream");
|
|
6
6
|
const readline_1 = require("readline");
|
|
@@ -35,6 +35,14 @@ const POD_END_POLL_MS = 500;
|
|
|
35
35
|
exports.NETWORK_LABEL = 'hammerkit.dev/network';
|
|
36
36
|
exports.NETWORK_LIMITED = 'limited';
|
|
37
37
|
exports.NETWORK_PROXY = 'proxy';
|
|
38
|
+
// on the pods that copy files into and out of a claim on a server: they need no network, so
|
|
39
|
+
// the policies of the caller's namespace for open pods leave them out (`limited`), and one
|
|
40
|
+
// of its own lets nothing in or out (see getNamespacePolicies)
|
|
41
|
+
exports.TRANSFER_LABEL = 'hammerkit.dev/transfer';
|
|
42
|
+
function getTransferNetworkLabels() {
|
|
43
|
+
return { [exports.NETWORK_LABEL]: exports.NETWORK_LIMITED, [exports.TRANSFER_LABEL]: 'true' };
|
|
44
|
+
}
|
|
45
|
+
exports.getTransferNetworkLabels = getTransferNetworkLabels;
|
|
38
46
|
function getNetworkLabels(env, item) {
|
|
39
47
|
return env.server && (0, work_network_1.getEffectiveNetwork)(item.data).type !== 'open' ? { [exports.NETWORK_LABEL]: exports.NETWORK_LIMITED } : {};
|
|
40
48
|
}
|
|
@@ -88,6 +96,13 @@ exports.getNetworkPolicyName = getNetworkPolicyName;
|
|
|
88
96
|
function getItemPodLabels(item, scope) {
|
|
89
97
|
return { [resources_1.ID_LABEL]: item.id(), ...(scope.run ? { [job_placement_1.RUN_LABEL]: scope.run } : {}) };
|
|
90
98
|
}
|
|
99
|
+
// The pods of the item, but those that copy files into and out of its claims on a server,
|
|
100
|
+
// which carry its labels too: the policy of their namespace lets nothing in or out of them,
|
|
101
|
+
// and the item's policy doesn't widen it.
|
|
102
|
+
const NOT_TRANSFER = { key: exports.TRANSFER_LABEL, operator: 'DoesNotExist' };
|
|
103
|
+
function withoutTransferPods(labels) {
|
|
104
|
+
return { matchLabels: labels, matchExpressions: [NOT_TRANSFER] };
|
|
105
|
+
}
|
|
91
106
|
function toSelector(labels) {
|
|
92
107
|
return Object.entries(labels)
|
|
93
108
|
.map(([key, value]) => `${key}=${value}`)
|
|
@@ -110,7 +125,7 @@ function getIngress(env, item) {
|
|
|
110
125
|
// on a server, of this run: the runs of a caller share their namespace
|
|
111
126
|
const run = (0, job_placement_1.getRunLabels)(env);
|
|
112
127
|
const from = {
|
|
113
|
-
matchExpressions: [{ key: resources_1.ID_LABEL, operator: 'In', values: ids }],
|
|
128
|
+
matchExpressions: [{ key: resources_1.ID_LABEL, operator: 'In', values: ids }, NOT_TRANSFER],
|
|
114
129
|
...(Object.keys(run).length > 0 ? { matchLabels: run } : {}),
|
|
115
130
|
};
|
|
116
131
|
// the client's name for `from`, a reserved word
|
|
@@ -133,12 +148,12 @@ function buildNetworkPolicy(env, item, network, scope, proxy = getRunProxy(item,
|
|
|
133
148
|
...(scope.owners ? { ownerReferences: scope.owners } : {}),
|
|
134
149
|
},
|
|
135
150
|
spec: {
|
|
136
|
-
podSelector:
|
|
151
|
+
podSelector: withoutTransferPods(getItemPodLabels(item, scope)),
|
|
137
152
|
policyTypes: ['Ingress', 'Egress'],
|
|
138
153
|
ingress: getIngress(env, item),
|
|
139
154
|
egress: [
|
|
140
155
|
...(needs.length > 0
|
|
141
|
-
? [{ to: needs.map((need) => ({ podSelector:
|
|
156
|
+
? [{ to: needs.map((need) => ({ podSelector: withoutTransferPods((0, resources_1.getItemLabels)(need.service, env)) })) }]
|
|
142
157
|
: []),
|
|
143
158
|
...(proxied
|
|
144
159
|
? [
|
|
@@ -172,7 +187,7 @@ function buildProxyPolicy(env, item, network, scope, proxy = getRunProxy(item, s
|
|
|
172
187
|
policyTypes: ['Ingress'],
|
|
173
188
|
ingress: [
|
|
174
189
|
{
|
|
175
|
-
_from: [{ podSelector:
|
|
190
|
+
_from: [{ podSelector: withoutTransferPods(getItemPodLabels(item, scope)) }],
|
|
176
191
|
ports: (0, egress_proxy_1.getEgressProxyPorts)(network).map((port) => ({ protocol: 'TCP', port })),
|
|
177
192
|
},
|
|
178
193
|
],
|
|
@@ -203,7 +218,9 @@ async function ensureKubernetesItemNetwork(instance, env, item, options) {
|
|
|
203
218
|
// without the rights to manage NetworkPolicies, hammerkit never made one
|
|
204
219
|
await removeKubernetesItemNetwork(instance, env, item, { run: null }, { ignoreForbidden: true });
|
|
205
220
|
}
|
|
206
|
-
|
|
221
|
+
// on a server, the policy of its namespace limits it: it starts once that holds
|
|
222
|
+
const gate = env.server?.openGate && env.networkPolicyEnforced ? [(0, network_gate_1.getNetworkGateContainer)(env.server.openGate)] : [];
|
|
223
|
+
return { env: [], secretEnv: [], hostAliases, initContainers: gate, close() { } };
|
|
207
224
|
}
|
|
208
225
|
const secretHosts = options.secretHosts ?? [];
|
|
209
226
|
if (secretHosts.length > 0 && options.sandbox) {
|
|
@@ -285,13 +302,18 @@ async function removeKubernetesItemNetwork(instance, env, item, scope, options =
|
|
|
285
302
|
}
|
|
286
303
|
}
|
|
287
304
|
exports.removeKubernetesItemNetwork = removeKubernetesItemNetwork;
|
|
288
|
-
// Waits until no pod with the labels runs or waits to run.
|
|
289
|
-
async function awaitPodsEnded(instance, env, labels, timeout = POD_END_TIMEOUT_MS
|
|
305
|
+
// Waits until no pod with the labels (or of the label selector) runs or waits to run.
|
|
306
|
+
async function awaitPodsEnded(instance, env, labels, timeout = POD_END_TIMEOUT_MS, pollInterval = POD_END_POLL_MS,
|
|
307
|
+
// stops the wait: they count as not ended
|
|
308
|
+
signal) {
|
|
290
309
|
const deadline = Date.now() + timeout;
|
|
291
310
|
for (;;) {
|
|
311
|
+
if (signal?.aborted) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
292
314
|
const pods = await instance.coreApi.listNamespacedPod({
|
|
293
315
|
namespace: env.namespace,
|
|
294
|
-
labelSelector: toSelector(labels),
|
|
316
|
+
labelSelector: typeof labels === 'string' ? labels : toSelector(labels),
|
|
295
317
|
});
|
|
296
318
|
if (pods.items.every((pod) => pod.status?.phase === 'Succeeded' || pod.status?.phase === 'Failed')) {
|
|
297
319
|
return true;
|
|
@@ -299,7 +321,7 @@ async function awaitPodsEnded(instance, env, labels, timeout = POD_END_TIMEOUT_M
|
|
|
299
321
|
if (Date.now() >= deadline) {
|
|
300
322
|
return false;
|
|
301
323
|
}
|
|
302
|
-
await (0, sleep_1.sleep)(
|
|
324
|
+
await (0, sleep_1.sleep)(pollInterval);
|
|
303
325
|
}
|
|
304
326
|
}
|
|
305
327
|
exports.awaitPodsEnded = awaitPodsEnded;
|
|
@@ -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 };
|
|
@@ -6,6 +6,7 @@ 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");
|
|
9
10
|
// Unpacks the archive of an output that is a file to `$1`: by its content, since the name in
|
|
10
11
|
// the archive is the file's and the one in the claim may carry a hash (see getClaimSubPath)
|
|
11
12
|
exports.RESTORE_FILE = 'mkdir -p "$(dirname "$1")" && rm -rf "$1" && tar xzf - -O > "$1"';
|
|
@@ -49,13 +50,13 @@ options = {}) {
|
|
|
49
50
|
// a claim made for this run (a server removes the claims of a run when it
|
|
50
51
|
// ends) does not have the directory of the output yet
|
|
51
52
|
let failure = null;
|
|
52
|
-
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)([
|
|
53
54
|
'sh',
|
|
54
55
|
'-c',
|
|
55
56
|
files.has(generatedArchive.path) ? exports.RESTORE_FILE : 'mkdir -p "$1" && tar xzf - -C "$1"',
|
|
56
57
|
'sh',
|
|
57
58
|
targetPath,
|
|
58
|
-
], process.stdout, process.stderr, environment.file.readStream(generatedArchive.filename), false, (status) => {
|
|
59
|
+
]), process.stdout, process.stderr, environment.file.readStream(generatedArchive.filename), false, (status) => {
|
|
59
60
|
work.status.write('debug', `upload ${generatedArchive.filename} to ${name}: ${status.status}`);
|
|
60
61
|
if (status.status !== 'Success') {
|
|
61
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'];
|
|
@@ -6,6 +6,7 @@ const log_1 = require("../log");
|
|
|
6
6
|
const event_cache_1 = require("../executer/event-cache");
|
|
7
7
|
const volumes_1 = require("./volumes");
|
|
8
8
|
const ensure_persistent_data_1 = require("./ensure-persistent-data");
|
|
9
|
+
const transfer_tools_1 = require("./transfer-tools");
|
|
9
10
|
async function storeKubernetesData(work, kubernetes, instance, environment, path,
|
|
10
11
|
// the state the outputs are of: on a service run, they are in its folder (see
|
|
11
12
|
// getStateFilesDir)
|
|
@@ -22,9 +23,9 @@ stateKey) {
|
|
|
22
23
|
await (0, ensure_persistent_data_1.getPodForPersistence)(instance, kubernetes, work, persistence, 'read', signal, async (name) => {
|
|
23
24
|
for (const generatedArchive of (0, event_cache_1.getArchivePaths)(work.data, path)) {
|
|
24
25
|
const writerStream = environment.file.createWriteStream(generatedArchive.filename);
|
|
25
|
-
const res = await instance.exec.exec(kubernetes.namespace, name, 'volume', files.has(generatedArchive.path)
|
|
26
|
+
const res = await instance.exec.exec(kubernetes.namespace, name, 'volume', (0, transfer_tools_1.inTransferPod)(files.has(generatedArchive.path)
|
|
26
27
|
? ['tar', 'zcf', '-', '-C', path_1.posix.dirname(generatedArchive.path), path_1.posix.basename(generatedArchive.path)]
|
|
27
|
-
: ['tar', 'zcf', '-', '-C', generatedArchive.path, '.'], writerStream, process.stderr, null, false, (status) => {
|
|
28
|
+
: ['tar', 'zcf', '-', '-C', generatedArchive.path, '.']), writerStream, process.stderr, null, false, (status) => {
|
|
28
29
|
work.status.write('debug', `archive ${generatedArchive.path} of ${name}: ${status}`);
|
|
29
30
|
writerStream.close();
|
|
30
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,10 +1,11 @@
|
|
|
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");
|
|
7
7
|
const kept_claims_1 = require("./kept-claims");
|
|
8
|
+
const dependency_outputs_1 = require("../planner/utils/dependency-outputs");
|
|
8
9
|
const claim_layout_1 = require("./claim-layout");
|
|
9
10
|
function getVolumeName(service, kubernetes) {
|
|
10
11
|
return (0, kept_claims_1.getClaimName)(service, kubernetes);
|
|
@@ -63,20 +64,25 @@ stateKey) {
|
|
|
63
64
|
};
|
|
64
65
|
const workspace = kubernetes.server?.workspace;
|
|
65
66
|
for (const mount of work.data.mounts) {
|
|
67
|
+
const isFile = isLocalFile(mount.localPath, mount.isFile);
|
|
66
68
|
if (workspace &&
|
|
67
|
-
appendWorkspaceMount(workspace, persistence, mount.containerPath, mount.localPath,
|
|
69
|
+
appendWorkspaceMount(workspace, persistence, mount.containerPath, mount.localPath, isFile, mount.readOnly)) {
|
|
68
70
|
continue;
|
|
69
71
|
}
|
|
70
|
-
appendVolume(work, persistence, mount.containerPath, mount.localPath,
|
|
72
|
+
appendVolume(work, persistence, mount.containerPath, mount.localPath, isFile, true, kubernetes, mounted, own);
|
|
71
73
|
}
|
|
72
74
|
// its deps' src too, uploaded into its own claim: a container task sees them as it does on
|
|
73
75
|
// docker (a tsc -b of a project that references another reads the other's tsconfig)
|
|
74
|
-
for (const src of work.data.src) {
|
|
75
|
-
if (
|
|
76
|
-
|
|
76
|
+
for (const src of getMountedSources(work.data.src)) {
|
|
77
|
+
if (work.data.type === 'container-task' && (0, dependency_outputs_1.isDependencyOutput)(work.data, src.absolutePath)) {
|
|
78
|
+
// what the dependency generates there is mounted below
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const isFile = isLocalFile(src.absolutePath, src.isFile);
|
|
82
|
+
if (workspace && appendWorkspaceMount(workspace, persistence, src.absolutePath, src.absolutePath, isFile, false)) {
|
|
77
83
|
continue;
|
|
78
84
|
}
|
|
79
|
-
appendVolume(work, persistence, src.absolutePath, src.absolutePath,
|
|
85
|
+
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
86
|
}
|
|
81
87
|
if (work.data.type === 'container-task') {
|
|
82
88
|
for (const generate of work.data.generates) {
|
|
@@ -97,6 +103,39 @@ stateKey) {
|
|
|
97
103
|
return persistence;
|
|
98
104
|
}
|
|
99
105
|
exports.getKubernetesPersistence = getKubernetesPersistence;
|
|
106
|
+
// Whether the path `localPath` is a file: what it is on disk, as docker binds it, and else
|
|
107
|
+
// `guess`, which goes by its name (a `Dockerfile` or `LICENSE` has no extension, and a
|
|
108
|
+
// `conf.d` folder has one)
|
|
109
|
+
function isLocalFile(localPath, guess) {
|
|
110
|
+
try {
|
|
111
|
+
return !(0, fs_1.statSync)(localPath).isDirectory();
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return guess;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// The srcs a pod mounts, each path once: a src inside a folder of another one (`docs/Dockerfile`
|
|
118
|
+
// with `docs`) is in the upload and the mount of that folder, as on docker, and is not mounted
|
|
119
|
+
// apart. A mount of its own inside the folder, which is mounted read only, needs its place
|
|
120
|
+
// there, and two mounts of the same path are refused by Kubernetes. A task's own src is kept
|
|
121
|
+
// before the same path of a dep, so it stays where getClaimSubPath puts it.
|
|
122
|
+
function getMountedSources(sources) {
|
|
123
|
+
const unique = new Map();
|
|
124
|
+
for (const src of sources) {
|
|
125
|
+
const other = unique.get(src.absolutePath);
|
|
126
|
+
if (!other || (other.inherited && !src.inherited)) {
|
|
127
|
+
unique.set(src.absolutePath, src);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const all = [...unique.values()];
|
|
131
|
+
const folders = all.filter((src) => !isLocalFile(src.absolutePath, src.isFile));
|
|
132
|
+
return all.filter((src) => !folders.some((folder) => folder !== src && isInside(folder.absolutePath, src.absolutePath)));
|
|
133
|
+
}
|
|
134
|
+
exports.getMountedSources = getMountedSources;
|
|
135
|
+
function isInside(folder, path) {
|
|
136
|
+
const rel = (0, path_1.relative)(folder, path);
|
|
137
|
+
return rel.length > 0 && rel !== '..' && !rel.startsWith(`..${path_1.sep}`) && !(0, path_1.isAbsolute)(rel);
|
|
138
|
+
}
|
|
100
139
|
// The places in the claim `claim` of the paths mounted inside a folder that is mounted read
|
|
101
140
|
// only from it: an output of a task inside a folder of its src (pkg/coverage/lcov.info with a
|
|
102
141
|
// src pkg). The container runtime makes the place of a mount where it isn't there, which it
|
|
@@ -108,12 +147,13 @@ function getNestedMountPlaces(persistence, claim) {
|
|
|
108
147
|
const places = [];
|
|
109
148
|
for (const mount of own) {
|
|
110
149
|
const parent = folders
|
|
111
|
-
.filter((folder) => folder !== mount &&
|
|
150
|
+
.filter((folder) => folder !== mount && isInside(folder.mount.mountPath, mount.mount.mountPath))
|
|
112
151
|
.sort((a, b) => b.mount.mountPath.length - a.mount.mountPath.length)[0];
|
|
113
152
|
if (!parent) {
|
|
114
153
|
continue;
|
|
115
154
|
}
|
|
116
|
-
const
|
|
155
|
+
const inside = (0, path_1.relative)(parent.mount.mountPath, mount.mount.mountPath).split(path_1.sep).join('/');
|
|
156
|
+
const place = `${parent.mount.subPath}/${inside}`;
|
|
117
157
|
places.push(mount.cwd === mount.mount.mountPath ? `${place}/` : place);
|
|
118
158
|
}
|
|
119
159
|
return places;
|
|
@@ -154,7 +194,9 @@ claimPath = (0, claim_layout_1.getClaimSubPath)(sourceWork, containerPath)) {
|
|
|
154
194
|
if (localPath) {
|
|
155
195
|
persistence.sources.push({
|
|
156
196
|
localPath: localPath,
|
|
157
|
-
|
|
197
|
+
// TODO: a matcher that uploads less than the whole folder has to keep the srcs
|
|
198
|
+
// inside it that getMountedSources leaves out (a `docs/Dockerfile` next to `docs/**/*.md`)
|
|
199
|
+
matcher: () => true,
|
|
158
200
|
containerPath,
|
|
159
201
|
subPath: (uploadDir ? `${uploadDir}/` : '') + claimPath,
|
|
160
202
|
stateKey: '', // TODO
|
|
@@ -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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stateKeyDigest = exports.getStateKey = exports.getWorkItemCheckoutStats = exports.getWorkItemCacheStats = exports.getWorkCacheStats = void 0;
|
|
3
|
+
exports.stateKeyDigest = exports.encodeStateEntries = exports.getStateKey = exports.getWorkItemCheckoutStats = exports.getWorkItemCacheStats = exports.getWorkCacheStats = void 0;
|
|
4
4
|
const calculate_checksum_1 = require("./calculate-checksum");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
@@ -39,9 +39,11 @@ async function visitPath(cwd, path, matcher, context, root) {
|
|
|
39
39
|
if (!matcher(path)) {
|
|
40
40
|
return { type: 'none' };
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
// `l` and the digest of its target, a kind of entry of its own: no checksum of a file
|
|
43
|
+
// starts with a letter past `f`
|
|
44
|
+
const checksum = `l${(0, crypto_1.createHash)('sha256')
|
|
43
45
|
.update(`link:${await (0, promises_1.readlink)(path)}`)
|
|
44
|
-
.digest('hex')
|
|
46
|
+
.digest('hex')}`;
|
|
45
47
|
return { type: 'file', key, lastModified: link.mtimeMs, checksum };
|
|
46
48
|
}
|
|
47
49
|
}
|
|
@@ -121,20 +123,30 @@ function dependencyOutputs(item) {
|
|
|
121
123
|
return [...outputs];
|
|
122
124
|
}
|
|
123
125
|
function getStateKey(stats, cacheMethod) {
|
|
124
|
-
const
|
|
126
|
+
const entries = [];
|
|
125
127
|
// Sorted: the walk follows the filesystem's listing order, which differs
|
|
126
128
|
// between machines (ext4 and overlayfs list in hash order).
|
|
127
129
|
for (const key of Object.keys(stats.files).sort()) {
|
|
128
130
|
if (cacheMethod === 'checksum') {
|
|
129
|
-
|
|
131
|
+
entries.push([key, stats.files[key].checksum]);
|
|
130
132
|
}
|
|
131
133
|
else if (cacheMethod === 'modify-date') {
|
|
132
|
-
|
|
134
|
+
entries.push([key, `${stats.files[key].lastModified}`]);
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
|
-
return stateKeyDigest(
|
|
137
|
+
return stateKeyDigest(encodeStateEntries(entries));
|
|
136
138
|
}
|
|
137
139
|
exports.getStateKey = getStateKey;
|
|
140
|
+
// The paths and values of a tree as one text that names no other tree. `path:value,...` as
|
|
141
|
+
// before while no path holds `:` or `,` (a value is hex digits or a date), so those keys stay
|
|
142
|
+
// what they were; else JSON after a NUL, which no path holds.
|
|
143
|
+
function encodeStateEntries(entries) {
|
|
144
|
+
if (entries.some(([path]) => /[:,]/.test(path))) {
|
|
145
|
+
return `\0${JSON.stringify(entries)}`;
|
|
146
|
+
}
|
|
147
|
+
return entries.map(([path, value]) => `${path}:${value}`).join(',');
|
|
148
|
+
}
|
|
149
|
+
exports.encodeStateEntries = encodeStateEntries;
|
|
138
150
|
// A state key is also the value of the `hammerkit.dev/state` label on Kubernetes, which
|
|
139
151
|
// takes at most 63 characters: the sha256 in base 36 has 50.
|
|
140
152
|
function stateKeyDigest(content) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.storedCacheDescription = exports.getWorkServiceCacheIdentity = exports.getWorkTaskCacheDescription = void 0;
|
|
3
|
+
exports.storedCacheDescription = exports.getWorkServiceCacheIdentity = exports.getSecretSources = exports.getWorkTaskCacheDescription = void 0;
|
|
4
4
|
const os_1 = require("os");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
6
|
const replace_env_variables_1 = require("../environment/replace-env-variables");
|
|
@@ -24,6 +24,7 @@ function getWorkTaskCacheDescription(item) {
|
|
|
24
24
|
.filter((secret) => secret.cache)
|
|
25
25
|
.map((secret) => `${(0, work_secret_1.getPortableSecretName)(task.projectRoot, secret)}=${secret.digest()}`)
|
|
26
26
|
.sort();
|
|
27
|
+
const secretSources = getSecretSources(task.projectRoot, task.secrets);
|
|
27
28
|
return {
|
|
28
29
|
shell: task.shell ?? undefined,
|
|
29
30
|
platform: task.type === 'container-task' ? task.image : (0, os_1.platform)(),
|
|
@@ -31,7 +32,12 @@ function getWorkTaskCacheDescription(item) {
|
|
|
31
32
|
// architecture, so container tasks are keyed by it too; on a cluster it is the
|
|
32
33
|
// one of the nodes the task runs on
|
|
33
34
|
arch: (task.type === 'container-task' && task.arch) || process.arch,
|
|
34
|
-
generates
|
|
35
|
+
// a file a dep generates is in its task id already (`deps`), and was left out of the
|
|
36
|
+
// generates before it was handed on: ids stay as they were
|
|
37
|
+
generates: task.generates
|
|
38
|
+
.filter((g) => !(g.inherited && g.isFile))
|
|
39
|
+
.map((g) => portable(g.path))
|
|
40
|
+
.sort() ?? undefined,
|
|
35
41
|
src: task.src.map((s) => s.source).sort() ?? undefined,
|
|
36
42
|
envs: Object.keys(envs)
|
|
37
43
|
.sort()
|
|
@@ -44,11 +50,26 @@ function getWorkTaskCacheDescription(item) {
|
|
|
44
50
|
cwd: portable(task.cwd),
|
|
45
51
|
deps: item.deps.length > 0 ? item.deps.map((dep) => dep.id()).sort() : undefined,
|
|
46
52
|
secrets: cachedSecrets.length > 0 ? cachedSecrets : undefined,
|
|
53
|
+
secretSources: secretSources.length > 0 ? secretSources : undefined,
|
|
47
54
|
claimLayout: (0, claim_layout_1.hasPathsEndingAlike)(item) || (0, claim_layout_1.hasOutputsFlatteningAlike)(item) ? 2 : undefined,
|
|
48
55
|
needs: item.needs.length > 0 ? getNeedsIdentities(item) : undefined,
|
|
49
56
|
};
|
|
50
57
|
}
|
|
51
58
|
exports.getWorkTaskCacheDescription = getWorkTaskCacheDescription;
|
|
59
|
+
// The secrets without `cache: true`, by name and source: `NAME<env:VAR`, `NAME<gcp:ref as
|
|
60
|
+
// account`, `NAME<file` (a path of the machine, which differs between machines). Their values
|
|
61
|
+
// stay out of the key, as before: what a provider returns may change on every read.
|
|
62
|
+
function getSecretSources(projectRoot, secrets) {
|
|
63
|
+
return secrets
|
|
64
|
+
.filter((secret) => !secret.cache)
|
|
65
|
+
.map((secret) => {
|
|
66
|
+
const source = secret.source;
|
|
67
|
+
const from = source.type === 'file' ? 'file' : (0, work_secret_1.describeSecretSource)(secret);
|
|
68
|
+
return `${(0, work_secret_1.getPortableSecretName)(projectRoot, secret)}<${from}`;
|
|
69
|
+
})
|
|
70
|
+
.sort();
|
|
71
|
+
}
|
|
72
|
+
exports.getSecretSources = getSecretSources;
|
|
52
73
|
// `visiting` holds the services on the way here: services that need each other in a loop
|
|
53
74
|
// fail to plan (checkForLoop), the identity only has to come back to say so
|
|
54
75
|
function getNeedsIdentities(item, visiting = new Set()) {
|
|
@@ -78,6 +99,10 @@ function getWorkServiceCacheIdentity(item, visiting = new Set()) {
|
|
|
78
99
|
.filter((secret) => secret.cache)
|
|
79
100
|
.map((secret) => `${(0, work_secret_1.getPortableSecretName)(service.projectRoot, secret)}=${secret.digest()}`)
|
|
80
101
|
.sort(),
|
|
102
|
+
// left out when it reads none, so the identity of such a service stays what it was
|
|
103
|
+
...(service.secrets.some((secret) => !secret.cache)
|
|
104
|
+
? { secretSources: getSecretSources(service.projectRoot, service.secrets) }
|
|
105
|
+
: {}),
|
|
81
106
|
// as declared: arguments after -- of a run of the init leave the service as it is
|
|
82
107
|
init: service.init ? (0, work_cache_id_1.getDeclaredWorkTaskId)(service.init.task) : null,
|
|
83
108
|
}
|
|
@@ -96,16 +121,25 @@ exports.getWorkServiceCacheIdentity = getWorkServiceCacheIdentity;
|
|
|
96
121
|
// The form written to disk: description.json in a cache entry (pushed to remote
|
|
97
122
|
// backends, readable by everyone who can pull) and the local explain record.
|
|
98
123
|
// Env is where tokens get passed, so each value is stored as a digest; the task
|
|
99
|
-
// id is still hashed from the values themselves.
|
|
124
|
+
// id is still hashed from the values themselves. So are where its secrets come from: who may
|
|
125
|
+
// pull an entry need not know which secrets of which provider a task reads.
|
|
100
126
|
function storedCacheDescription(description) {
|
|
101
|
-
if (!description.envs) {
|
|
127
|
+
if (!description.envs && !description.secretSources) {
|
|
102
128
|
return description;
|
|
103
129
|
}
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
130
|
+
const digest = (value) => `sha256:${(0, crypto_1.createHash)('sha256').update(value).digest('hex')}`;
|
|
131
|
+
const stored = { ...description };
|
|
132
|
+
if (description.envs) {
|
|
133
|
+
const envs = {};
|
|
134
|
+
for (const [key, value] of Object.entries(description.envs)) {
|
|
135
|
+
envs[key] = digest(value);
|
|
136
|
+
}
|
|
137
|
+
stored.envs = envs;
|
|
138
|
+
}
|
|
139
|
+
if (description.secretSources) {
|
|
140
|
+
stored.secretSources = description.secretSources.map(digest);
|
|
107
141
|
}
|
|
108
|
-
return
|
|
142
|
+
return stored;
|
|
109
143
|
}
|
|
110
144
|
exports.storedCacheDescription = storedCacheDescription;
|
|
111
145
|
//# sourceMappingURL=work-task-cache-description.js.map
|