@tsplc/build 0.1.0 → 0.2.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 +57 -13
- package/dist/cli.js.map +8 -8
- package/dist/index.js +146 -15
- package/dist/index.js.map +7 -7
- package/docker/Dockerfile.dockerignore +1 -0
- package/docker/edge-gateway/Dockerfile +17 -0
- package/docker/runner.ts +31 -6
- package/package.json +3 -3
- package/python/build.py +6 -1
- package/python/codesys_login.py +100 -0
- package/python/codesys_online.py +47 -20
- package/python/test_codesys_login.py +120 -0
- package/python/test_codesys_online.py +14 -0
- package/python/worker.py +13 -0
- package/src/controller-online.ts +170 -16
- package/src/controller-session.ts +72 -3
- package/src/diagnostics.ts +2 -0
- package/src/docker-build.ts +15 -0
- package/src/docker-run.ts +3 -4
- package/src/host/codesys-worker.ts +9 -6
- package/src/index.ts +19 -2
package/dist/cli.js
CHANGED
|
@@ -133,6 +133,7 @@ class CodesysCompilerError extends Error {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
var buildFailureFile = ".codesys/docker/failure.json";
|
|
136
|
+
var controllerFailureFile = ".codesys/controller/failure.txt";
|
|
136
137
|
var buildFailureSchema = z2.strictObject({
|
|
137
138
|
operationId: z2.uuid(),
|
|
138
139
|
message: z2.string(),
|
|
@@ -199,8 +200,6 @@ var prepareContainerRun = async (config, requestDirectory, options) => {
|
|
|
199
200
|
runtime: undefined
|
|
200
201
|
}));
|
|
201
202
|
return [
|
|
202
|
-
"run",
|
|
203
|
-
"--rm",
|
|
204
203
|
"--init",
|
|
205
204
|
...config.docker?.cpuSet ? ["--cpuset-cpus", config.docker.cpuSet] : [],
|
|
206
205
|
"--network",
|
|
@@ -228,6 +227,8 @@ var buildInDocker = async (config, image) => {
|
|
|
228
227
|
const failurePath = resolve5(config.outDir, buildFailureFile);
|
|
229
228
|
await rm3(failurePath, { force: true });
|
|
230
229
|
const args = [
|
|
230
|
+
"run",
|
|
231
|
+
"--rm",
|
|
231
232
|
...await prepareContainerRun(config, requestDirectory, { network: "none", sources: true }),
|
|
232
233
|
image,
|
|
233
234
|
"--request",
|
|
@@ -975,6 +976,7 @@ import {
|
|
|
975
976
|
|
|
976
977
|
// packages/build/src/controller-online.ts
|
|
977
978
|
import { execFile as execFile4 } from "node:child_process";
|
|
979
|
+
import { existsSync } from "node:fs";
|
|
978
980
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
979
981
|
import { mkdir as mkdir5, mkdtemp as mkdtemp3, readFile as readFile5, rm as rm5 } from "node:fs/promises";
|
|
980
982
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
@@ -1009,7 +1011,7 @@ var controllerResultSchema = z5.strictObject({
|
|
|
1009
1011
|
state: z5.string().nonempty(),
|
|
1010
1012
|
values: z5.record(z5.string(), z5.string())
|
|
1011
1013
|
});
|
|
1012
|
-
var
|
|
1014
|
+
var controllerConnection = async (config) => {
|
|
1013
1015
|
if (!config.docker || !config.online) {
|
|
1014
1016
|
throw new Error("Docker image and online gateway/device configuration are required for controller operations");
|
|
1015
1017
|
}
|
|
@@ -1022,20 +1024,30 @@ var controllerOperation = async (config, operation, options) => {
|
|
|
1022
1024
|
const { stdout } = await execute4("docker", ["image", "inspect", "--format", "{{.Id}}", dockerImage], { timeout: config.timeouts.hostCommand }).catch((cause) => {
|
|
1023
1025
|
throw new Error(`Cannot inspect Docker builder image ${dockerImage}. Install and start Docker, then run tsplc-build configure if the image is missing`, { cause });
|
|
1024
1026
|
});
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1027
|
+
return {
|
|
1028
|
+
environmentNames,
|
|
1029
|
+
imageId: imageIdSchema.parse(stdout.trim()),
|
|
1030
|
+
templateHash: createHash2("sha256").update(await readFile5(config.template)).digest("hex"),
|
|
1031
|
+
target: {
|
|
1032
|
+
network: config.online.network,
|
|
1033
|
+
gateway: config.online.gateway,
|
|
1034
|
+
device: config.online.device,
|
|
1035
|
+
controller: config.controller
|
|
1036
|
+
}
|
|
1033
1037
|
};
|
|
1038
|
+
};
|
|
1039
|
+
var controllerOperation = async (config, operation, options) => {
|
|
1040
|
+
const { environmentNames, imageId, templateHash, target } = await controllerConnection(config);
|
|
1041
|
+
const operationId = randomUUID2();
|
|
1034
1042
|
const requestDirectory = await mkdtemp3(resolve7(tmpdir3(), "codesys-controller-"));
|
|
1035
1043
|
const diagnostics = resolve7(config.outDir, ".codesys/controller");
|
|
1044
|
+
const failure = resolve7(config.outDir, controllerFailureFile);
|
|
1036
1045
|
try {
|
|
1037
1046
|
await mkdir5(config.outDir, { recursive: true });
|
|
1047
|
+
await rm5(failure, { force: true });
|
|
1038
1048
|
await runDocker([
|
|
1049
|
+
"run",
|
|
1050
|
+
"--rm",
|
|
1039
1051
|
...await prepareContainerRun(config, requestDirectory, {
|
|
1040
1052
|
network: target.network,
|
|
1041
1053
|
environment: environmentNames,
|
|
@@ -1051,7 +1063,13 @@ var controllerOperation = async (config, operation, options) => {
|
|
|
1051
1063
|
imageId,
|
|
1052
1064
|
...options.initializeUser ? ["--initialize-user"] : [],
|
|
1053
1065
|
...options.read ? ["--read", JSON.stringify(options.read)] : []
|
|
1054
|
-
], (status) => `Docker controller operation failed (${status}). Inspect ${diagnostics} for diagnostics`)
|
|
1066
|
+
], (status) => `Docker controller operation failed (${status}). Inspect ${diagnostics} for diagnostics`).catch(async (cause) => {
|
|
1067
|
+
if (!existsSync(failure))
|
|
1068
|
+
throw cause;
|
|
1069
|
+
const reason = (await readFile5(failure, "utf8")).trim().split(`
|
|
1070
|
+
`).at(-1);
|
|
1071
|
+
throw new Error(`${reason}. Inspect ${diagnostics} for diagnostics`, { cause });
|
|
1072
|
+
});
|
|
1055
1073
|
const result = await readFile5(resolve7(diagnostics, "result.json"), "utf8").then((content) => controllerResultSchema.parse(JSON.parse(content))).catch((cause) => {
|
|
1056
1074
|
throw new Error(`Docker did not produce a valid controller receipt. Inspect ${diagnostics} for diagnostics`, { cause });
|
|
1057
1075
|
});
|
|
@@ -1065,6 +1083,32 @@ var controllerOperation = async (config, operation, options) => {
|
|
|
1065
1083
|
};
|
|
1066
1084
|
var updateController = (config, operation, options = {}) => controllerOperation(config, operation, options);
|
|
1067
1085
|
var inspectController = (config, read) => controllerOperation(config, "inspect", { read });
|
|
1086
|
+
var loginCommandSchema = z5.discriminatedUnion("command", [
|
|
1087
|
+
z5.strictObject({ command: z5.literal("state") }),
|
|
1088
|
+
z5.strictObject({
|
|
1089
|
+
command: z5.literal("read"),
|
|
1090
|
+
expressions: z5.array(z5.string().nonempty()).nonempty()
|
|
1091
|
+
}),
|
|
1092
|
+
z5.strictObject({
|
|
1093
|
+
command: z5.enum(["write", "force"]),
|
|
1094
|
+
values: z5.record(z5.string().nonempty(), z5.string().nonempty())
|
|
1095
|
+
}),
|
|
1096
|
+
z5.strictObject({
|
|
1097
|
+
command: z5.literal("unforce"),
|
|
1098
|
+
expressions: z5.array(z5.string().nonempty()),
|
|
1099
|
+
restore: z5.boolean()
|
|
1100
|
+
}),
|
|
1101
|
+
z5.strictObject({ command: z5.enum(["start", "stop"]) }),
|
|
1102
|
+
z5.strictObject({ command: z5.literal("reset"), kind: z5.enum(["Warm", "Cold"]) })
|
|
1103
|
+
]);
|
|
1104
|
+
var loginResultSchema = z5.union([
|
|
1105
|
+
z5.strictObject({ values: z5.record(z5.string(), z5.string()) }),
|
|
1106
|
+
z5.strictObject({ state: z5.string(), forced: z5.array(z5.string()) })
|
|
1107
|
+
]);
|
|
1108
|
+
var loginReplySchema = z5.discriminatedUnion("ok", [
|
|
1109
|
+
z5.strictObject({ ok: z5.literal(true), result: z5.unknown() }),
|
|
1110
|
+
z5.strictObject({ ok: z5.literal(false), error: z5.string() })
|
|
1111
|
+
]);
|
|
1068
1112
|
|
|
1069
1113
|
// packages/build/src/docker-build.ts
|
|
1070
1114
|
import { execFile as execFile5 } from "node:child_process";
|
|
@@ -1648,5 +1692,5 @@ try {
|
|
|
1648
1692
|
process.exitCode = 1;
|
|
1649
1693
|
}
|
|
1650
1694
|
|
|
1651
|
-
//# debugId=
|
|
1695
|
+
//# debugId=C865C1ABFC6D750A64756E2164756E21
|
|
1652
1696
|
//# sourceMappingURL=cli.js.map
|