hammerkit 2.0.0-next.11 → 2.0.0-next.12
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/kubernetes/volumes.js +47 -10
- package/package.json +1 -1
|
@@ -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");
|
|
@@ -63,20 +63,21 @@ stateKey) {
|
|
|
63
63
|
};
|
|
64
64
|
const workspace = kubernetes.server?.workspace;
|
|
65
65
|
for (const mount of work.data.mounts) {
|
|
66
|
+
const isFile = isLocalFile(mount.localPath, mount.isFile);
|
|
66
67
|
if (workspace &&
|
|
67
|
-
appendWorkspaceMount(workspace, persistence, mount.containerPath, mount.localPath,
|
|
68
|
+
appendWorkspaceMount(workspace, persistence, mount.containerPath, mount.localPath, isFile, mount.readOnly)) {
|
|
68
69
|
continue;
|
|
69
70
|
}
|
|
70
|
-
appendVolume(work, persistence, mount.containerPath, mount.localPath,
|
|
71
|
+
appendVolume(work, persistence, mount.containerPath, mount.localPath, isFile, true, kubernetes, mounted, own);
|
|
71
72
|
}
|
|
72
73
|
// its deps' src too, uploaded into its own claim: a container task sees them as it does on
|
|
73
74
|
// docker (a tsc -b of a project that references another reads the other's tsconfig)
|
|
74
|
-
for (const src of work.data.src) {
|
|
75
|
-
|
|
76
|
-
|
|
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)) {
|
|
77
78
|
continue;
|
|
78
79
|
}
|
|
79
|
-
appendVolume(work, persistence, src.absolutePath, src.absolutePath,
|
|
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) {
|
|
@@ -97,6 +98,39 @@ stateKey) {
|
|
|
97
98
|
return persistence;
|
|
98
99
|
}
|
|
99
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
|
+
}
|
|
100
134
|
// The places in the claim `claim` of the paths mounted inside a folder that is mounted read
|
|
101
135
|
// only from it: an output of a task inside a folder of its src (pkg/coverage/lcov.info with a
|
|
102
136
|
// src pkg). The container runtime makes the place of a mount where it isn't there, which it
|
|
@@ -108,12 +142,13 @@ function getNestedMountPlaces(persistence, claim) {
|
|
|
108
142
|
const places = [];
|
|
109
143
|
for (const mount of own) {
|
|
110
144
|
const parent = folders
|
|
111
|
-
.filter((folder) => folder !== mount &&
|
|
145
|
+
.filter((folder) => folder !== mount && isInside(folder.mount.mountPath, mount.mount.mountPath))
|
|
112
146
|
.sort((a, b) => b.mount.mountPath.length - a.mount.mountPath.length)[0];
|
|
113
147
|
if (!parent) {
|
|
114
148
|
continue;
|
|
115
149
|
}
|
|
116
|
-
const
|
|
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}`;
|
|
117
152
|
places.push(mount.cwd === mount.mount.mountPath ? `${place}/` : place);
|
|
118
153
|
}
|
|
119
154
|
return places;
|
|
@@ -154,7 +189,9 @@ claimPath = (0, claim_layout_1.getClaimSubPath)(sourceWork, containerPath)) {
|
|
|
154
189
|
if (localPath) {
|
|
155
190
|
persistence.sources.push({
|
|
156
191
|
localPath: localPath,
|
|
157
|
-
|
|
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,
|
|
158
195
|
containerPath,
|
|
159
196
|
subPath: (uploadDir ? `${uploadDir}/` : '') + claimPath,
|
|
160
197
|
stateKey: '', // TODO
|
package/package.json
CHANGED