@tsplc/build 0.4.4 → 0.5.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/dist/cli.js +392 -272
- package/dist/cli.js.map +12 -11
- package/dist/images.js +70 -11
- package/dist/images.js.map +4 -4
- package/dist/index.js +388 -253
- package/dist/index.js.map +11 -10
- package/package.json +4 -4
- package/src/builder-image.ts +94 -0
- package/src/controller-online.ts +13 -4
- package/src/docker-build.ts +50 -20
- package/src/docker-context.ts +158 -13
- package/src/docker-run.ts +7 -1
- package/src/images.ts +23 -2
- package/src/index.ts +5 -0
package/dist/images.js
CHANGED
|
@@ -5,10 +5,20 @@ import { resolve as resolve3 } from "node:path";
|
|
|
5
5
|
import { dockerImage } from "@tsplc/config/build";
|
|
6
6
|
|
|
7
7
|
// packages/build/src/docker-context.ts
|
|
8
|
-
import {
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import {
|
|
10
|
+
cp,
|
|
11
|
+
mkdir,
|
|
12
|
+
mkdtemp,
|
|
13
|
+
readdir,
|
|
14
|
+
readFile,
|
|
15
|
+
rm,
|
|
16
|
+
stat,
|
|
17
|
+
writeFile
|
|
18
|
+
} from "node:fs/promises";
|
|
9
19
|
import { createRequire } from "node:module";
|
|
10
20
|
import { tmpdir } from "node:os";
|
|
11
|
-
import { basename, dirname, resolve as resolve2 } from "node:path";
|
|
21
|
+
import { basename, dirname, posix, relative, resolve as resolve2, sep } from "node:path";
|
|
12
22
|
import { z } from "zod";
|
|
13
23
|
|
|
14
24
|
// packages/build/src/package-path.ts
|
|
@@ -19,20 +29,46 @@ var packageDirectory = resolve(fileURLToPath(new URL("..", import.meta.url)));
|
|
|
19
29
|
// packages/build/src/docker-context.ts
|
|
20
30
|
var includeSource = (source) => {
|
|
21
31
|
const name = basename(source);
|
|
22
|
-
return name !== "__pycache__" && !name.endsWith(".pyc") && !name.endsWith(".test.ts") && !name.endsWith(".fixtures.ts") && !(name.startsWith("test_") && name.endsWith(".py"));
|
|
32
|
+
return name !== "__pycache__" && name !== ".DS_Store" && !name.endsWith(".pyc") && !name.endsWith(".test.ts") && !name.endsWith(".fixtures.ts") && !(name.startsWith("test_") && name.endsWith(".py"));
|
|
23
33
|
};
|
|
24
34
|
var containerPackages = [
|
|
25
35
|
{
|
|
26
36
|
entry: "@tsplc/config/build",
|
|
27
37
|
directory: "shared-config",
|
|
38
|
+
image: "/opt/tsplc-config",
|
|
28
39
|
files: ["src", "templates", "package.json"]
|
|
29
40
|
},
|
|
30
41
|
{
|
|
31
42
|
entry: "@tsplc/iec",
|
|
32
43
|
directory: "shared-iec",
|
|
44
|
+
image: "/opt/tsplc-iec",
|
|
33
45
|
files: ["src", "package.json"]
|
|
34
46
|
}
|
|
35
47
|
];
|
|
48
|
+
var packageRoot = (entry) => resolve2(dirname(createRequire(import.meta.url).resolve(entry)), "..");
|
|
49
|
+
var listFiles = async (root, path, include) => {
|
|
50
|
+
const name = relative(root, path).split(sep).join("/");
|
|
51
|
+
if (!include(name)) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
if (!(await stat(path)).isDirectory()) {
|
|
55
|
+
return [name];
|
|
56
|
+
}
|
|
57
|
+
const entries = await readdir(path);
|
|
58
|
+
return (await Promise.all(entries.map((entry) => listFiles(root, resolve2(path, entry), include)))).flat();
|
|
59
|
+
};
|
|
60
|
+
var digestFiles = async (files, texts) => {
|
|
61
|
+
const hash = createHash("sha256");
|
|
62
|
+
for (const [name, text] of Object.entries(texts)) {
|
|
63
|
+
hash.update(`${name}\x00${text}\x00`);
|
|
64
|
+
}
|
|
65
|
+
for (const file of [...files].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
66
|
+
hash.update(`${file.name}\x00`);
|
|
67
|
+
hash.update(await readFile(file.path));
|
|
68
|
+
hash.update("\x00");
|
|
69
|
+
}
|
|
70
|
+
return hash.digest("hex");
|
|
71
|
+
};
|
|
36
72
|
var manifestDependencies = z.object({
|
|
37
73
|
name: z.string(),
|
|
38
74
|
dependencies: z.record(z.string(), z.string()).default({})
|
|
@@ -54,6 +90,19 @@ function containerDependencies(manifests) {
|
|
|
54
90
|
return Object.fromEntries([...selected].map(([name, { version }]) => [name, version]));
|
|
55
91
|
}
|
|
56
92
|
var readManifest = async (directory) => manifestDependencies.parse(JSON.parse(await readFile(resolve2(directory, "package.json"), "utf8")));
|
|
93
|
+
var containerManifest = async () => {
|
|
94
|
+
const manifests = [await readManifest(packageDirectory)];
|
|
95
|
+
for (const { entry } of containerPackages) {
|
|
96
|
+
manifests.push(await readManifest(packageRoot(entry)));
|
|
97
|
+
}
|
|
98
|
+
return { type: "module", dependencies: containerDependencies(manifests) };
|
|
99
|
+
};
|
|
100
|
+
var recipeFile = (path) => path === "docker" || path === "docker/Dockerfile" || path === "docker/entrypoint.sh" || (path === "docker/install" || path.startsWith("docker/install/")) && includeSource(basename(path)) && !path.split("/").includes("tests") && path !== "docker/install/wine-signal/check.sh";
|
|
101
|
+
var builderRecipe = async () => digestFiles((await recipeFiles()).map((name) => ({
|
|
102
|
+
name,
|
|
103
|
+
path: resolve2(packageDirectory, name)
|
|
104
|
+
})), { manifest: JSON.stringify(await containerManifest()) });
|
|
105
|
+
var recipeFiles = () => listFiles(packageDirectory, resolve2(packageDirectory, "docker"), recipeFile);
|
|
57
106
|
async function prepareDockerContext() {
|
|
58
107
|
const context = await mkdtemp(resolve2(tmpdir(), "tsplc-docker-"));
|
|
59
108
|
try {
|
|
@@ -63,10 +112,8 @@ async function prepareDockerContext() {
|
|
|
63
112
|
filter: includeSource
|
|
64
113
|
});
|
|
65
114
|
}
|
|
66
|
-
const manifests = [await readManifest(packageDirectory)];
|
|
67
115
|
for (const { entry, directory, files } of containerPackages) {
|
|
68
|
-
const root =
|
|
69
|
-
manifests.push(await readManifest(root));
|
|
116
|
+
const root = packageRoot(entry);
|
|
70
117
|
await mkdir(resolve2(context, directory));
|
|
71
118
|
for (const file of files) {
|
|
72
119
|
await cp(resolve2(root, file), resolve2(context, directory, file), {
|
|
@@ -75,10 +122,7 @@ async function prepareDockerContext() {
|
|
|
75
122
|
});
|
|
76
123
|
}
|
|
77
124
|
}
|
|
78
|
-
await writeFile(resolve2(context, "package.json"), JSON.stringify(
|
|
79
|
-
type: "module",
|
|
80
|
-
dependencies: containerDependencies(manifests)
|
|
81
|
-
}));
|
|
125
|
+
await writeFile(resolve2(context, "package.json"), JSON.stringify(await containerManifest()));
|
|
82
126
|
return context;
|
|
83
127
|
} catch (cause) {
|
|
84
128
|
await rm(context, { recursive: true, force: true });
|
|
@@ -100,6 +144,7 @@ var setupPlatformFor = (server) => {
|
|
|
100
144
|
}
|
|
101
145
|
return null;
|
|
102
146
|
};
|
|
147
|
+
var recipeLabel = "tsplc.recipe";
|
|
103
148
|
async function buildBuilderImage(options) {
|
|
104
149
|
const installerContext = await mkdtemp2(resolve3(tmpdir2(), "codesys-installer-"));
|
|
105
150
|
let context;
|
|
@@ -124,6 +169,8 @@ async function buildBuilderImage(options) {
|
|
|
124
169
|
`SETUP_PLATFORM=${options.setupPlatform}`,
|
|
125
170
|
"--build-arg",
|
|
126
171
|
`INSTALLER_SOURCE=${options.installer ? "installer-local" : "installer-download"}`,
|
|
172
|
+
"--label",
|
|
173
|
+
`${recipeLabel}=${await builderRecipe()}`,
|
|
127
174
|
"--progress",
|
|
128
175
|
"plain",
|
|
129
176
|
"--build-context",
|
|
@@ -141,6 +188,16 @@ async function buildBuilderImage(options) {
|
|
|
141
188
|
]);
|
|
142
189
|
}
|
|
143
190
|
}
|
|
191
|
+
var buildRuntimeImage = (options) => options.docker([
|
|
192
|
+
"build",
|
|
193
|
+
"--platform",
|
|
194
|
+
"linux/amd64",
|
|
195
|
+
"--progress",
|
|
196
|
+
"plain",
|
|
197
|
+
"-t",
|
|
198
|
+
options.tag,
|
|
199
|
+
resolve3(packageDirectory, "docker/control-linux-sl")
|
|
200
|
+
]);
|
|
144
201
|
var buildGatewayImage = (options) => options.docker([
|
|
145
202
|
"build",
|
|
146
203
|
"--platform",
|
|
@@ -154,12 +211,14 @@ var buildGatewayImage = (options) => options.docker([
|
|
|
154
211
|
export {
|
|
155
212
|
buildBuilderImage,
|
|
156
213
|
buildGatewayImage,
|
|
214
|
+
buildRuntimeImage,
|
|
157
215
|
builderImage,
|
|
158
216
|
gatewayImage,
|
|
159
217
|
publishedImage,
|
|
218
|
+
recipeLabel,
|
|
160
219
|
runtimeImage,
|
|
161
220
|
setupPlatformFor
|
|
162
221
|
};
|
|
163
222
|
|
|
164
|
-
//# debugId=
|
|
223
|
+
//# debugId=C04CB7D81098D9E964756E2164756E21
|
|
165
224
|
//# sourceMappingURL=images.js.map
|
package/dist/images.js.map
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/images.ts", "../src/docker-context.ts", "../src/package-path.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { copyFile, cp, mkdir, mkdtemp, rm } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { resolve } from \"node:path\";\nimport { dockerImage } from \"@tsplc/config/build\";\nimport { prepareDockerContext } from \"./docker-context.ts\";\nimport { packageDirectory } from \"./package-path.ts\";\n\nexport const builderImage = dockerImage;\n\nexport const gatewayImage = \"tsplc-edge-gateway:4.22.0.0\";\n\n/** The local CODESYS Control for Linux SL runtime; it is always built here, never published. */\nexport const runtimeImage = \"tsplc-control-linux-sl:4.22.0.0\";\n\n/** The registry name each tsPLC version's copy of a local image is published under. */\nexport const publishedImage = (image: string, version: string) =>\n\t`ghcr.io/livingforjesus/${image.split(\":\")[0]}:${version}`;\n\n/** The platform the vendor installer runs on; the compiler image itself is always AMD64. */\nexport type SetupPlatform = \"linux/amd64\" | \"linux/arm64\";\n\n/** The setup platform for a Docker server's `{{.OSType}}/{{.Architecture}}`, or null when it has none. */\nexport const setupPlatformFor = (server: string): SetupPlatform | null => {\n\tif (server === \"linux/aarch64\" || server === \"linux/arm64\") {\n\t\treturn \"linux/arm64\";\n\t}\n\tif (server === \"linux/x86_64\" || server === \"linux/amd64\") {\n\t\treturn \"linux/amd64\";\n\t}\n\treturn null;\n};\n\n/**\n * Builds the builder image from the full recipe. `installer` is a local CODESYS installer,\n * or null to download the official one; `winetricksCache` seeds the prerequisite downloads.\n * `docker` runs one Docker client command, so each caller keeps its own terminal handling.\n */\nexport async function buildBuilderImage(options: {\n\ttag: string;\n\tsetupPlatform: SetupPlatform;\n\tinstaller: string | null;\n\twinetricksCache: string | null;\n\tdocker: (args: string[]) => Promise<void>;\n}) {\n\tconst installerContext = await mkdtemp(\n\t\tresolve(tmpdir(), \"codesys-installer-\"),\n\t);\n\tlet context: string | undefined;\n\ttry {\n\t\tcontext = await prepareDockerContext();\n\t\tconst cache = resolve(installerContext, \"winetricks\");\n\t\tawait mkdir(cache);\n\t\tif (options.winetricksCache) {\n\t\t\tawait cp(options.winetricksCache, cache, { recursive: true });\n\t\t}\n\t\tif (options.installer) {\n\t\t\tawait copyFile(\n\t\t\t\toptions.installer,\n\t\t\t\tresolve(installerContext, \"codesys.exe\"),\n\t\t\t);\n\t\t}\n\t\tconst arm = options.setupPlatform === \"linux/arm64\";\n\t\t// FEX handles ARM setup's 32-bit prerequisites; the compiler runtime stays AMD64.\n\t\tawait options.docker([\n\t\t\t\"build\",\n\t\t\t\"--platform\",\n\t\t\t\"linux/amd64\",\n\t\t\t\"--build-arg\",\n\t\t\t`SETUP_BASE=${arm ? \"arm-setup\" : \"base\"}`,\n\t\t\t\"--build-arg\",\n\t\t\t`SETUP_PLATFORM=${options.setupPlatform}`,\n\t\t\t\"--build-arg\",\n\t\t\t`INSTALLER_SOURCE=${options.installer ? \"installer-local\" : \"installer-download\"}`,\n\t\t\t\"--progress\",\n\t\t\t\"plain\",\n\t\t\t\"--build-context\",\n\t\t\t`installer=${installerContext}`,\n\t\t\t\"-f\",\n\t\t\tresolve(context, \"docker/Dockerfile\"),\n\t\t\t\"-t\",\n\t\t\toptions.tag,\n\t\t\tcontext,\n\t\t]);\n\t} finally {\n\t\tawait Promise.all([\n\t\t\trm(installerContext, { recursive: true, force: true }),\n\t\t\t...(context ? [rm(context, { recursive: true, force: true })] : []),\n\t\t]);\n\t}\n}\n\nexport const buildGatewayImage = (options: {\n\ttag: string;\n\tdocker: (args: string[]) => Promise<void>;\n}) =>\n\toptions.docker([\n\t\t\"build\",\n\t\t\"--platform\",\n\t\t\"linux/amd64\",\n\t\t\"--progress\",\n\t\t\"plain\",\n\t\t\"-t\",\n\t\toptions.tag,\n\t\tresolve(packageDirectory, \"docker/edge-gateway\"),\n\t]);\n",
|
|
6
|
-
"import {
|
|
5
|
+
"import { copyFile, cp, mkdir, mkdtemp, rm } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { resolve } from \"node:path\";\nimport { dockerImage } from \"@tsplc/config/build\";\nimport { builderRecipe, prepareDockerContext } from \"./docker-context.ts\";\nimport { packageDirectory } from \"./package-path.ts\";\n\nexport const builderImage = dockerImage;\n\nexport const gatewayImage = \"tsplc-edge-gateway:4.22.0.0\";\n\n/** The local CODESYS Control for Linux SL runtime; it is always built here, never published. */\nexport const runtimeImage = \"tsplc-control-linux-sl:4.22.0.0\";\n\n/** The registry name each tsPLC version's copy of a local image is published under. */\nexport const publishedImage = (image: string, version: string) =>\n\t`ghcr.io/livingforjesus/${image.split(\":\")[0]}:${version}`;\n\n/** The platform the vendor installer runs on; the compiler image itself is always AMD64. */\nexport type SetupPlatform = \"linux/amd64\" | \"linux/arm64\";\n\n/** The setup platform for a Docker server's `{{.OSType}}/{{.Architecture}}`, or null when it has none. */\nexport const setupPlatformFor = (server: string): SetupPlatform | null => {\n\tif (server === \"linux/aarch64\" || server === \"linux/arm64\") {\n\t\treturn \"linux/arm64\";\n\t}\n\tif (server === \"linux/x86_64\" || server === \"linux/amd64\") {\n\t\treturn \"linux/amd64\";\n\t}\n\treturn null;\n};\n\n/** The label an image built by `buildBuilderImage` carries its `builderRecipe` in. */\nexport const recipeLabel = \"tsplc.recipe\";\n\n/**\n * Builds the builder image from the full recipe, labelled with it. `installer` is a local CODESYS installer,\n * or null to download the official one; `winetricksCache` seeds the prerequisite downloads.\n * `docker` runs one Docker client command, so each caller keeps its own terminal handling.\n */\nexport async function buildBuilderImage(options: {\n\ttag: string;\n\tsetupPlatform: SetupPlatform;\n\tinstaller: string | null;\n\twinetricksCache: string | null;\n\tdocker: (args: string[]) => Promise<void>;\n}) {\n\tconst installerContext = await mkdtemp(\n\t\tresolve(tmpdir(), \"codesys-installer-\"),\n\t);\n\tlet context: string | undefined;\n\ttry {\n\t\tcontext = await prepareDockerContext();\n\t\tconst cache = resolve(installerContext, \"winetricks\");\n\t\tawait mkdir(cache);\n\t\tif (options.winetricksCache) {\n\t\t\tawait cp(options.winetricksCache, cache, { recursive: true });\n\t\t}\n\t\tif (options.installer) {\n\t\t\tawait copyFile(\n\t\t\t\toptions.installer,\n\t\t\t\tresolve(installerContext, \"codesys.exe\"),\n\t\t\t);\n\t\t}\n\t\tconst arm = options.setupPlatform === \"linux/arm64\";\n\t\t// FEX handles ARM setup's 32-bit prerequisites; the compiler runtime stays AMD64.\n\t\tawait options.docker([\n\t\t\t\"build\",\n\t\t\t\"--platform\",\n\t\t\t\"linux/amd64\",\n\t\t\t\"--build-arg\",\n\t\t\t`SETUP_BASE=${arm ? \"arm-setup\" : \"base\"}`,\n\t\t\t\"--build-arg\",\n\t\t\t`SETUP_PLATFORM=${options.setupPlatform}`,\n\t\t\t\"--build-arg\",\n\t\t\t`INSTALLER_SOURCE=${options.installer ? \"installer-local\" : \"installer-download\"}`,\n\t\t\t\"--label\",\n\t\t\t`${recipeLabel}=${await builderRecipe()}`,\n\t\t\t\"--progress\",\n\t\t\t\"plain\",\n\t\t\t\"--build-context\",\n\t\t\t`installer=${installerContext}`,\n\t\t\t\"-f\",\n\t\t\tresolve(context, \"docker/Dockerfile\"),\n\t\t\t\"-t\",\n\t\t\toptions.tag,\n\t\t\tcontext,\n\t\t]);\n\t} finally {\n\t\tawait Promise.all([\n\t\t\trm(installerContext, { recursive: true, force: true }),\n\t\t\t...(context ? [rm(context, { recursive: true, force: true })] : []),\n\t\t]);\n\t}\n}\n\n/** Builds the local CODESYS Control for Linux SL runtime, the device a production build targets. */\nexport const buildRuntimeImage = (options: {\n\ttag: string;\n\tdocker: (args: string[]) => Promise<void>;\n}) =>\n\toptions.docker([\n\t\t\"build\",\n\t\t\"--platform\",\n\t\t\"linux/amd64\",\n\t\t\"--progress\",\n\t\t\"plain\",\n\t\t\"-t\",\n\t\toptions.tag,\n\t\tresolve(packageDirectory, \"docker/control-linux-sl\"),\n\t]);\n\nexport const buildGatewayImage = (options: {\n\ttag: string;\n\tdocker: (args: string[]) => Promise<void>;\n}) =>\n\toptions.docker([\n\t\t\"build\",\n\t\t\"--platform\",\n\t\t\"linux/amd64\",\n\t\t\"--progress\",\n\t\t\"plain\",\n\t\t\"-t\",\n\t\toptions.tag,\n\t\tresolve(packageDirectory, \"docker/edge-gateway\"),\n\t]);\n",
|
|
6
|
+
"import { createHash } from \"node:crypto\";\nimport {\n\tcp,\n\tmkdir,\n\tmkdtemp,\n\treaddir,\n\treadFile,\n\trm,\n\tstat,\n\twriteFile,\n} from \"node:fs/promises\";\nimport { createRequire } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { basename, dirname, posix, relative, resolve, sep } from \"node:path\";\nimport { z } from \"zod\";\nimport { packageDirectory } from \"./package-path.ts\";\n\nconst includeSource = (source: string) => {\n\tconst name = basename(source);\n\treturn (\n\t\tname !== \"__pycache__\" &&\n\t\tname !== \".DS_Store\" &&\n\t\t!name.endsWith(\".pyc\") &&\n\t\t!name.endsWith(\".test.ts\") &&\n\t\t!name.endsWith(\".fixtures.ts\") &&\n\t\t!(name.startsWith(\"test_\") && name.endsWith(\".py\"))\n\t);\n};\n\n/**\n * The workspace packages container code imports, each copied with the files Bun runs it from,\n * to `directory` in the context and `image` in the image.\n */\nconst containerPackages = [\n\t{\n\t\tentry: \"@tsplc/config/build\",\n\t\tdirectory: \"shared-config\",\n\t\timage: \"/opt/tsplc-config\",\n\t\tfiles: [\"src\", \"templates\", \"package.json\"],\n\t},\n\t{\n\t\tentry: \"@tsplc/iec\",\n\t\tdirectory: \"shared-iec\",\n\t\timage: \"/opt/tsplc-iec\",\n\t\tfiles: [\"src\", \"package.json\"],\n\t},\n];\n\n/** Where the image keeps this package. */\nconst imagePackage = \"/opt/codesys-build\";\n/**\n * This package's files that the image runs and a container may take from the installed package\n * instead: everything the runner imports and the CODESYS scripts. The entrypoint stays the image's.\n */\nconst packageCode = [\"src\", \"python\", \"docker/runner.ts\", \"docker/config.ts\"];\n\nconst packageRoot = (entry: string) =>\n\tresolve(dirname(createRequire(import.meta.url).resolve(entry)), \"..\");\n\n/** A host file or directory and the path in the image it replaces. */\nexport interface ContainerMount {\n\tsource: string;\n\ttarget: string;\n}\n\n/**\n * The code a builder container runs, as this installation has it, and where the image keeps its\n * own copy. Mounted over the image's, it makes a container run this installation's tsPLC whatever\n * tsPLC built the image, so only a change of the image's recipe needs a new image.\n */\nexport const containerCode = (): ContainerMount[] => [\n\t...packageCode.map((path) => ({\n\t\tsource: resolve(packageDirectory, path),\n\t\ttarget: posix.join(imagePackage, path),\n\t})),\n\t...containerPackages.flatMap(({ entry, image, files }) =>\n\t\tfiles.map((file) => ({\n\t\t\tsource: resolve(packageRoot(entry), file),\n\t\t\ttarget: posix.join(image, file),\n\t\t})),\n\t),\n];\n\n/** Every file under `path`, or `path` itself, that `include` keeps, by its path relative to `root`. */\nconst listFiles = async (\n\troot: string,\n\tpath: string,\n\tinclude: (relativePath: string) => boolean,\n): Promise<string[]> => {\n\tconst name = relative(root, path).split(sep).join(\"/\");\n\tif (!include(name)) {\n\t\treturn [];\n\t}\n\tif (!(await stat(path)).isDirectory()) {\n\t\treturn [name];\n\t}\n\tconst entries = await readdir(path);\n\treturn (\n\t\tawait Promise.all(\n\t\t\tentries.map((entry) => listFiles(root, resolve(path, entry), include)),\n\t\t)\n\t).flat();\n};\n\n/** A digest of named texts and files, which changes when a name or a file's content does. */\nconst digestFiles = async (\n\tfiles: { name: string; path: string }[],\n\ttexts: Record<string, string>,\n) => {\n\tconst hash = createHash(\"sha256\");\n\tfor (const [name, text] of Object.entries(texts)) {\n\t\thash.update(`${name}\\0${text}\\0`);\n\t}\n\tfor (const file of [...files].sort((a, b) => a.name.localeCompare(b.name))) {\n\t\thash.update(`${file.name}\\0`);\n\t\thash.update(await readFile(file.path));\n\t\thash.update(\"\\0\");\n\t}\n\treturn hash.digest(\"hex\");\n};\n\n/**\n * A digest of the code `containerCode` mounts, which a long-running container is labelled with so\n * that one running other code is replaced.\n */\nexport const containerCodeDigest = async () =>\n\tdigestFiles(\n\t\t(\n\t\t\tawait Promise.all(\n\t\t\t\tcontainerCode().map(async ({ source, target }) =>\n\t\t\t\t\t(\n\t\t\t\t\t\tawait listFiles(dirname(source), source, (path) =>\n\t\t\t\t\t\t\tincludeSource(basename(path)),\n\t\t\t\t\t\t)\n\t\t\t\t\t).map((name) => ({\n\t\t\t\t\t\tname: posix.join(posix.dirname(target), name),\n\t\t\t\t\t\tpath: resolve(dirname(source), name),\n\t\t\t\t\t})),\n\t\t\t\t),\n\t\t\t)\n\t\t).flat(),\n\t\t{},\n\t);\n\nconst manifestDependencies = z.object({\n\tname: z.string(),\n\tdependencies: z.record(z.string(), z.string()).default({}),\n});\n\n/**\n * The third-party packages the image installs: what this package and each package the\n * context carries depend on, at the versions their manifests pin.\n */\nexport function containerDependencies(\n\tmanifests: z.infer<typeof manifestDependencies>[],\n) {\n\tconst selected = new Map<string, { version: string; owner: string }>();\n\tfor (const manifest of manifests) {\n\t\tfor (const [name, version] of Object.entries(manifest.dependencies)) {\n\t\t\tif (name.startsWith(\"@tsplc/\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst existing = selected.get(name);\n\t\t\tif (existing && existing.version !== version) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`The builder image cannot install ${name}: ${existing.owner} pins ${existing.version} and ${manifest.name} pins ${version}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tselected.set(name, { version, owner: manifest.name });\n\t\t}\n\t}\n\treturn Object.fromEntries(\n\t\t[...selected].map(([name, { version }]) => [name, version]),\n\t);\n}\n\nconst readManifest = async (directory: string) =>\n\tmanifestDependencies.parse(\n\t\tJSON.parse(await readFile(resolve(directory, \"package.json\"), \"utf8\")),\n\t);\n\n/** The manifest of the third-party packages the image installs, as its recipe writes it. */\nexport const containerManifest = async () => {\n\tconst manifests = [await readManifest(packageDirectory)];\n\tfor (const { entry } of containerPackages) {\n\t\tmanifests.push(await readManifest(packageRoot(entry)));\n\t}\n\treturn { type: \"module\", dependencies: containerDependencies(manifests) };\n};\n\n/**\n * The files of the image's recipe that its containers can't take from the installed package: the\n * Dockerfile, the entrypoint and the installation's scripts and data. Tests and checks of the\n * installation's own tools stay out, as the published package leaves them out.\n */\nconst recipeFile = (path: string) =>\n\tpath === \"docker\" ||\n\tpath === \"docker/Dockerfile\" ||\n\tpath === \"docker/entrypoint.sh\" ||\n\t((path === \"docker/install\" || path.startsWith(\"docker/install/\")) &&\n\t\tincludeSource(basename(path)) &&\n\t\t!path.split(\"/\").includes(\"tests\") &&\n\t\tpath !== \"docker/install/wine-signal/check.sh\");\n\n/**\n * The builder image's recipe: what it installs and how. An image built from another recipe has\n * another vendor installation or other third-party packages, so its containers can't run this\n * installation's code, while one built from this recipe runs any tsPLC with this recipe.\n */\nexport const builderRecipe = async () =>\n\tdigestFiles(\n\t\t(await recipeFiles()).map((name) => ({\n\t\t\tname,\n\t\t\tpath: resolve(packageDirectory, name),\n\t\t})),\n\t\t{ manifest: JSON.stringify(await containerManifest()) },\n\t);\n\n/** The package's files `builderRecipe` covers, beside the third-party manifest. */\nexport const recipeFiles = () =>\n\tlistFiles(packageDirectory, resolve(packageDirectory, \"docker\"), recipeFile);\n\nexport async function prepareDockerContext() {\n\tconst context = await mkdtemp(resolve(tmpdir(), \"tsplc-docker-\"));\n\ttry {\n\t\tfor (const directory of [\"src\", \"python\", \"docker\", \"runtime\"]) {\n\t\t\tawait cp(\n\t\t\t\tresolve(packageDirectory, directory),\n\t\t\t\tresolve(context, directory),\n\t\t\t\t{\n\t\t\t\t\trecursive: true,\n\t\t\t\t\tfilter: includeSource,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tfor (const { entry, directory, files } of containerPackages) {\n\t\t\tconst root = packageRoot(entry);\n\t\t\tawait mkdir(resolve(context, directory));\n\t\t\tfor (const file of files) {\n\t\t\t\tawait cp(resolve(root, file), resolve(context, directory, file), {\n\t\t\t\t\trecursive: true,\n\t\t\t\t\tfilter: includeSource,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tawait writeFile(\n\t\t\tresolve(context, \"package.json\"),\n\t\t\tJSON.stringify(await containerManifest()),\n\t\t);\n\t\treturn context;\n\t} catch (cause) {\n\t\tawait rm(context, { recursive: true, force: true });\n\t\tthrow cause;\n\t}\n}\n",
|
|
7
7
|
"import { resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n// Both source modules and published bundles live one directory below the package root.\nexport const packageDirectory = resolve(\n\tfileURLToPath(new URL(\"..\", import.meta.url)),\n);\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": ";AAAA,yBAAmB,cAAI,mBAAO,gBAAS;AACvC,mBAAS;AACT,oBAAS;AACT;;;ACHA;AACA;AACA;AACA,
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";AAAA,yBAAmB,cAAI,mBAAO,gBAAS;AACvC,mBAAS;AACT,oBAAS;AACT;;;ACHA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AACA;AACA,wDAA6C;AAC7C;;;ACdA;AACA;AAGO,IAAM,mBAAmB,QAC/B,cAAc,IAAI,IAAI,MAAM,YAAY,GAAG,CAAC,CAC7C;;;ADWA,IAAM,gBAAgB,CAAC,WAAmB;AAAA,EACzC,MAAM,OAAO,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