@tsplc/build 0.2.8 → 0.2.9
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 +51 -33
- package/dist/cli.js.map +5 -5
- package/dist/index.js +187 -63
- package/dist/index.js.map +5 -5
- package/docker/runner.ts +29 -9
- package/package.json +3 -3
- package/python/build.py +4 -1
- package/python/codesys_online.py +38 -12
- package/python/test_codesys_online.py +31 -1
- package/python/worker.py +16 -7
- package/src/controller-online.ts +248 -65
- package/src/controller-session.ts +157 -28
- package/src/docker-run.ts +60 -17
- package/src/host/codesys-worker.ts +1 -0
- package/src/index.ts +2 -0
package/dist/cli.js
CHANGED
|
@@ -62,7 +62,7 @@ var readBuild = async (directory) => {
|
|
|
62
62
|
// packages/build/src/docker-build.ts
|
|
63
63
|
import { execFile } from "node:child_process";
|
|
64
64
|
import { randomUUID } from "node:crypto";
|
|
65
|
-
import { cp as
|
|
65
|
+
import { cp as cp4, mkdir as mkdir3, mkdtemp as mkdtemp2, readFile as readFile3, rm as rm3 } from "node:fs/promises";
|
|
66
66
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
67
67
|
import { resolve as resolve5 } from "node:path";
|
|
68
68
|
import { promisify } from "node:util";
|
|
@@ -143,7 +143,7 @@ var buildFailureSchema = z2.strictObject({
|
|
|
143
143
|
// packages/build/src/docker-run.ts
|
|
144
144
|
import { spawn } from "node:child_process";
|
|
145
145
|
import { createHash } from "node:crypto";
|
|
146
|
-
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile3 } from "node:fs/promises";
|
|
146
|
+
import { copyFile as copyFile2, cp as cp3, mkdir as mkdir2, readFile as readFile2, writeFile as writeFile3 } from "node:fs/promises";
|
|
147
147
|
import { basename, posix, relative, resolve as resolve4, sep } from "node:path";
|
|
148
148
|
var runDocker = (args, failure) => new Promise((accept, reject) => {
|
|
149
149
|
const child = spawn("docker", args, {
|
|
@@ -173,7 +173,7 @@ var runDocker = (args, failure) => new Promise((accept, reject) => {
|
|
|
173
173
|
});
|
|
174
174
|
});
|
|
175
175
|
var bindMount = (source, target, readonly = false) => `type=bind,"source=${source.replaceAll('"', '""')}",target=${target}${readonly ? ",readonly" : ""}`;
|
|
176
|
-
async function mountLibraries(libraries, directory) {
|
|
176
|
+
async function mountLibraries(libraries, directory, root = "/input") {
|
|
177
177
|
if (!libraries?.length)
|
|
178
178
|
return;
|
|
179
179
|
await mkdir2(resolve4(directory, "libraries"), { recursive: true });
|
|
@@ -183,22 +183,23 @@ async function mountLibraries(libraries, directory) {
|
|
|
183
183
|
throw new Error(`Library changed after installation: ${library.title}`);
|
|
184
184
|
const filename = `${library.sha256}-${basename(library.path)}`;
|
|
185
185
|
await writeFile3(resolve4(directory, "libraries", filename), data);
|
|
186
|
-
return { ...library, path:
|
|
186
|
+
return { ...library, path: `${root}/libraries/${filename}` };
|
|
187
187
|
}));
|
|
188
188
|
}
|
|
189
|
+
var containerConfig = (config, paths, libraries) => ({
|
|
190
|
+
...config,
|
|
191
|
+
libraries,
|
|
192
|
+
configFile: undefined,
|
|
193
|
+
docker: undefined,
|
|
194
|
+
codesys: undefined,
|
|
195
|
+
sourceDir: paths.sourceDir,
|
|
196
|
+
entry: posix.resolve(paths.sourceDir, relative(config.sourceDir, config.entry).split(sep).join("/")),
|
|
197
|
+
template: paths.template,
|
|
198
|
+
outDir: "/output",
|
|
199
|
+
runtime: undefined
|
|
200
|
+
});
|
|
189
201
|
var prepareContainerRun = async (config, requestDirectory, options) => {
|
|
190
|
-
await writeFile3(resolve4(requestDirectory, "config.json"), JSON.stringify({
|
|
191
|
-
...config,
|
|
192
|
-
libraries: options.sources ? await mountLibraries(config.libraries, requestDirectory) : [],
|
|
193
|
-
configFile: undefined,
|
|
194
|
-
docker: undefined,
|
|
195
|
-
codesys: undefined,
|
|
196
|
-
sourceDir: "/sources",
|
|
197
|
-
entry: posix.resolve("/sources", relative(config.sourceDir, config.entry).split(sep).join("/")),
|
|
198
|
-
template: "/template.project",
|
|
199
|
-
outDir: "/output",
|
|
200
|
-
runtime: undefined
|
|
201
|
-
}));
|
|
202
|
+
await writeFile3(resolve4(requestDirectory, "config.json"), JSON.stringify(containerConfig(config, { sourceDir: "/sources", template: "/template.project" }, options.sources ? await mountLibraries(config.libraries, requestDirectory) : [])));
|
|
202
203
|
return [
|
|
203
204
|
"--init",
|
|
204
205
|
...config.docker?.cpuSet ? ["--cpuset-cpus", config.docker.cpuSet] : [],
|
|
@@ -269,7 +270,7 @@ ${failure.message}`;
|
|
|
269
270
|
// packages/build/src/host/codesys-worker.ts
|
|
270
271
|
import {
|
|
271
272
|
access,
|
|
272
|
-
copyFile as
|
|
273
|
+
copyFile as copyFile3,
|
|
273
274
|
mkdir as mkdir4,
|
|
274
275
|
open,
|
|
275
276
|
readFile as readFile4,
|
|
@@ -980,7 +981,7 @@ import { existsSync } from "node:fs";
|
|
|
980
981
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
981
982
|
import { mkdir as mkdir5, mkdtemp as mkdtemp3, readFile as readFile5, rm as rm5 } from "node:fs/promises";
|
|
982
983
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
983
|
-
import { resolve as resolve7 } from "node:path";
|
|
984
|
+
import { posix as posix2, resolve as resolve7 } from "node:path";
|
|
984
985
|
import { promisify as promisify4 } from "node:util";
|
|
985
986
|
import { z as z5 } from "zod";
|
|
986
987
|
var execute4 = promisify4(execFile4);
|
|
@@ -1012,6 +1013,17 @@ var controllerResultSchema = z5.strictObject({
|
|
|
1012
1013
|
state: z5.string().nonempty(),
|
|
1013
1014
|
values: z5.record(z5.string(), z5.string())
|
|
1014
1015
|
});
|
|
1016
|
+
var controllerCredentialsSchema = z5.strictObject({
|
|
1017
|
+
username: z5.string().nonempty(),
|
|
1018
|
+
password: z5.string().nonempty()
|
|
1019
|
+
});
|
|
1020
|
+
var warmOperationSchema = z5.strictObject({
|
|
1021
|
+
operation: z5.enum(["download", "online-change"]),
|
|
1022
|
+
operationId: z5.uuid(),
|
|
1023
|
+
request: z5.string().nonempty(),
|
|
1024
|
+
initializeUser: z5.boolean(),
|
|
1025
|
+
credentials: controllerCredentialsSchema.optional()
|
|
1026
|
+
});
|
|
1015
1027
|
var controllerTarget = (config, online) => ({
|
|
1016
1028
|
network: online.network,
|
|
1017
1029
|
gateway: online.gateway,
|
|
@@ -1021,28 +1033,37 @@ var controllerTarget = (config, online) => ({
|
|
|
1021
1033
|
deviceTree: createHash2("sha256").update(JSON.stringify(config.deviceTree)).digest("hex")
|
|
1022
1034
|
}
|
|
1023
1035
|
});
|
|
1024
|
-
var
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
}
|
|
1028
|
-
const environmentNames = config.online.credentials ? [config.online.credentials.usernameEnv, config.online.credentials.passwordEnv] : [];
|
|
1029
|
-
for (const name of environmentNames) {
|
|
1036
|
+
var credentialEnvironment = (config) => {
|
|
1037
|
+
const names = config.online?.credentials ? [config.online.credentials.usernameEnv, config.online.credentials.passwordEnv] : [];
|
|
1038
|
+
for (const name of names) {
|
|
1030
1039
|
if (process.env[name] === undefined) {
|
|
1031
1040
|
throw new Error(`Controller credential environment variable ${name} is not set`);
|
|
1032
1041
|
}
|
|
1033
1042
|
}
|
|
1043
|
+
return names;
|
|
1044
|
+
};
|
|
1045
|
+
var controllerConnection = async (config) => {
|
|
1046
|
+
if (!config.docker || !config.online) {
|
|
1047
|
+
throw new Error("Docker image and online gateway/device configuration are required for controller operations");
|
|
1048
|
+
}
|
|
1034
1049
|
const { stdout } = await execute4("docker", ["image", "inspect", "--format", "{{.Id}}", dockerImage], { timeout: config.timeouts.hostCommand }).catch((cause) => {
|
|
1035
1050
|
throw new Error(`Cannot inspect Docker builder image ${dockerImage}. Install and start Docker, then run tsplc-build configure if the image is missing`, { cause });
|
|
1036
1051
|
});
|
|
1037
1052
|
return {
|
|
1038
|
-
environmentNames,
|
|
1039
1053
|
imageId: imageIdSchema.parse(stdout.trim()),
|
|
1040
1054
|
templateHash: createHash2("sha256").update(await readFile5(config.template)).digest("hex"),
|
|
1041
1055
|
target: controllerTarget(config, config.online)
|
|
1042
1056
|
};
|
|
1043
1057
|
};
|
|
1058
|
+
var checkReceipt = (result, expected, diagnostics) => {
|
|
1059
|
+
if (result.operationId !== expected.operationId || result.operation !== expected.operation || result.imageId !== expected.imageId || result.templateHash !== expected.templateHash || JSON.stringify(result.target) !== JSON.stringify(expected.target)) {
|
|
1060
|
+
throw new Error(`Controller receipt does not match this operation's image, template or target. Inspect ${diagnostics} for diagnostics`);
|
|
1061
|
+
}
|
|
1062
|
+
return result;
|
|
1063
|
+
};
|
|
1044
1064
|
var controllerOperation = async (config, operation, options) => {
|
|
1045
|
-
const
|
|
1065
|
+
const environmentNames = credentialEnvironment(config);
|
|
1066
|
+
const { imageId, templateHash, target } = await controllerConnection(config);
|
|
1046
1067
|
const operationId = randomUUID2();
|
|
1047
1068
|
const requestDirectory = await mkdtemp3(resolve7(tmpdir3(), "codesys-controller-"));
|
|
1048
1069
|
const diagnostics = resolve7(config.outDir, ".codesys/controller");
|
|
@@ -1078,10 +1099,7 @@ var controllerOperation = async (config, operation, options) => {
|
|
|
1078
1099
|
const result = await readFile5(resolve7(diagnostics, "result.json"), "utf8").then((content) => controllerResultSchema.parse(JSON.parse(content))).catch((cause) => {
|
|
1079
1100
|
throw new Error(`Docker did not produce a valid controller receipt. Inspect ${diagnostics} for diagnostics`, { cause });
|
|
1080
1101
|
});
|
|
1081
|
-
|
|
1082
|
-
throw new Error(`Controller receipt does not match this operation's image, template or target. Inspect ${diagnostics} for diagnostics`);
|
|
1083
|
-
}
|
|
1084
|
-
return result;
|
|
1102
|
+
return checkReceipt(result, { operationId, operation, imageId, templateHash, target }, diagnostics);
|
|
1085
1103
|
} finally {
|
|
1086
1104
|
await rm5(requestDirectory, { recursive: true, force: true });
|
|
1087
1105
|
}
|
|
@@ -1117,7 +1135,7 @@ var loginReplySchema = z5.discriminatedUnion("ok", [
|
|
|
1117
1135
|
|
|
1118
1136
|
// packages/build/src/docker-build.ts
|
|
1119
1137
|
import { execFile as execFile5 } from "node:child_process";
|
|
1120
|
-
import { cp as
|
|
1138
|
+
import { cp as cp5, mkdir as mkdir6, mkdtemp as mkdtemp4, readFile as readFile6, rm as rm6 } from "node:fs/promises";
|
|
1121
1139
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
1122
1140
|
import { resolve as resolve8 } from "node:path";
|
|
1123
1141
|
import { promisify as promisify5 } from "node:util";
|
|
@@ -1159,7 +1177,7 @@ var configureDocker = async () => {
|
|
|
1159
1177
|
const cache = resolve8(context, "winetricks");
|
|
1160
1178
|
await mkdir6(cache);
|
|
1161
1179
|
if (process.env["CODESYS_WINETRICKS_CACHE"]) {
|
|
1162
|
-
await
|
|
1180
|
+
await cp5(process.env["CODESYS_WINETRICKS_CACHE"], cache, {
|
|
1163
1181
|
recursive: true
|
|
1164
1182
|
});
|
|
1165
1183
|
}
|
|
@@ -1715,5 +1733,5 @@ try {
|
|
|
1715
1733
|
process.exitCode = 1;
|
|
1716
1734
|
}
|
|
1717
1735
|
|
|
1718
|
-
//# debugId=
|
|
1736
|
+
//# debugId=4ED16E2EF93604DB64756E2164756E21
|
|
1719
1737
|
//# sourceMappingURL=cli.js.map
|