@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/index.js
CHANGED
|
@@ -78,50 +78,159 @@ import { randomUUID } from "node:crypto";
|
|
|
78
78
|
import { mkdir as mkdir4, mkdtemp as mkdtemp3, readFile as readFile4, rm as rm4 } from "node:fs/promises";
|
|
79
79
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
80
80
|
import { resolve as resolve6 } from "node:path";
|
|
81
|
-
import { z as
|
|
81
|
+
import { z as z5 } from "zod";
|
|
82
82
|
|
|
83
|
-
// packages/build/src/
|
|
83
|
+
// packages/build/src/builder-image.ts
|
|
84
|
+
import { isDeepStrictEqual } from "node:util";
|
|
85
|
+
import { z as z3 } from "zod";
|
|
86
|
+
|
|
87
|
+
// packages/build/src/docker-context.ts
|
|
88
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
89
|
+
import {
|
|
90
|
+
cp as cp2,
|
|
91
|
+
mkdir,
|
|
92
|
+
mkdtemp,
|
|
93
|
+
readdir,
|
|
94
|
+
readFile as readFile2,
|
|
95
|
+
rm as rm2,
|
|
96
|
+
stat as stat2,
|
|
97
|
+
writeFile as writeFile2
|
|
98
|
+
} from "node:fs/promises";
|
|
99
|
+
import { createRequire } from "node:module";
|
|
100
|
+
import { tmpdir } from "node:os";
|
|
101
|
+
import { basename, dirname, posix, relative, resolve as resolve3, sep } from "node:path";
|
|
84
102
|
import { z as z2 } from "zod";
|
|
85
|
-
var compilerDiagnosticSchema = z2.object({
|
|
86
|
-
category: z2.string(),
|
|
87
|
-
text: z2.string(),
|
|
88
|
-
severity: z2.string().nullable(),
|
|
89
|
-
project: z2.string().nullable(),
|
|
90
|
-
object: z2.object({
|
|
91
|
-
name: z2.string(),
|
|
92
|
-
guid: z2.string(),
|
|
93
|
-
path: z2.array(z2.string()),
|
|
94
|
-
isApplicationChild: z2.boolean().nullable()
|
|
95
|
-
}).passthrough().nullable(),
|
|
96
|
-
position: z2.string().nullable(),
|
|
97
|
-
positionText: z2.string().nullable(),
|
|
98
|
-
positionOffset: z2.int().nullable(),
|
|
99
|
-
length: z2.int().nullable(),
|
|
100
|
-
prefix: z2.string().nullable(),
|
|
101
|
-
number: z2.int().nullable()
|
|
102
|
-
}).passthrough();
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
// packages/build/src/package-path.ts
|
|
105
|
+
import { resolve as resolve2 } from "node:path";
|
|
106
|
+
import { fileURLToPath } from "node:url";
|
|
107
|
+
var packageDirectory = resolve2(fileURLToPath(new URL("..", import.meta.url)));
|
|
108
|
+
|
|
109
|
+
// packages/build/src/docker-context.ts
|
|
110
|
+
var includeSource = (source) => {
|
|
111
|
+
const name = basename(source);
|
|
112
|
+
return name !== "__pycache__" && name !== ".DS_Store" && !name.endsWith(".pyc") && !name.endsWith(".test.ts") && !name.endsWith(".fixtures.ts") && !(name.startsWith("test_") && name.endsWith(".py"));
|
|
113
|
+
};
|
|
114
|
+
var containerPackages = [
|
|
115
|
+
{
|
|
116
|
+
entry: "@tsplc/config/build",
|
|
117
|
+
directory: "shared-config",
|
|
118
|
+
image: "/opt/tsplc-config",
|
|
119
|
+
files: ["src", "templates", "package.json"]
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
entry: "@tsplc/iec",
|
|
123
|
+
directory: "shared-iec",
|
|
124
|
+
image: "/opt/tsplc-iec",
|
|
125
|
+
files: ["src", "package.json"]
|
|
110
126
|
}
|
|
111
|
-
|
|
112
|
-
var
|
|
113
|
-
var
|
|
114
|
-
var
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
127
|
+
];
|
|
128
|
+
var imagePackage = "/opt/codesys-build";
|
|
129
|
+
var packageCode = ["src", "python", "docker/runner.ts", "docker/config.ts"];
|
|
130
|
+
var packageRoot = (entry) => resolve3(dirname(createRequire(import.meta.url).resolve(entry)), "..");
|
|
131
|
+
var containerCode = () => [
|
|
132
|
+
...packageCode.map((path) => ({
|
|
133
|
+
source: resolve3(packageDirectory, path),
|
|
134
|
+
target: posix.join(imagePackage, path)
|
|
135
|
+
})),
|
|
136
|
+
...containerPackages.flatMap(({ entry, image, files }) => files.map((file) => ({
|
|
137
|
+
source: resolve3(packageRoot(entry), file),
|
|
138
|
+
target: posix.join(image, file)
|
|
139
|
+
})))
|
|
140
|
+
];
|
|
141
|
+
var listFiles = async (root, path, include) => {
|
|
142
|
+
const name = relative(root, path).split(sep).join("/");
|
|
143
|
+
if (!include(name)) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
if (!(await stat2(path)).isDirectory()) {
|
|
147
|
+
return [name];
|
|
148
|
+
}
|
|
149
|
+
const entries = await readdir(path);
|
|
150
|
+
return (await Promise.all(entries.map((entry) => listFiles(root, resolve3(path, entry), include)))).flat();
|
|
151
|
+
};
|
|
152
|
+
var digestFiles = async (files, texts) => {
|
|
153
|
+
const hash = createHash2("sha256");
|
|
154
|
+
for (const [name, text] of Object.entries(texts)) {
|
|
155
|
+
hash.update(`${name}\x00${text}\x00`);
|
|
156
|
+
}
|
|
157
|
+
for (const file of [...files].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
158
|
+
hash.update(`${file.name}\x00`);
|
|
159
|
+
hash.update(await readFile2(file.path));
|
|
160
|
+
hash.update("\x00");
|
|
161
|
+
}
|
|
162
|
+
return hash.digest("hex");
|
|
163
|
+
};
|
|
164
|
+
var containerCodeDigest = async () => digestFiles((await Promise.all(containerCode().map(async ({ source, target }) => (await listFiles(dirname(source), source, (path) => includeSource(basename(path)))).map((name) => ({
|
|
165
|
+
name: posix.join(posix.dirname(target), name),
|
|
166
|
+
path: resolve3(dirname(source), name)
|
|
167
|
+
}))))).flat(), {});
|
|
168
|
+
var manifestDependencies = z2.object({
|
|
169
|
+
name: z2.string(),
|
|
170
|
+
dependencies: z2.record(z2.string(), z2.string()).default({})
|
|
118
171
|
});
|
|
172
|
+
function containerDependencies(manifests) {
|
|
173
|
+
const selected = new Map;
|
|
174
|
+
for (const manifest of manifests) {
|
|
175
|
+
for (const [name, version] of Object.entries(manifest.dependencies)) {
|
|
176
|
+
if (name.startsWith("@tsplc/")) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const existing = selected.get(name);
|
|
180
|
+
if (existing && existing.version !== version) {
|
|
181
|
+
throw new Error(`The builder image cannot install ${name}: ${existing.owner} pins ${existing.version} and ${manifest.name} pins ${version}.`);
|
|
182
|
+
}
|
|
183
|
+
selected.set(name, { version, owner: manifest.name });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return Object.fromEntries([...selected].map(([name, { version }]) => [name, version]));
|
|
187
|
+
}
|
|
188
|
+
var readManifest = async (directory) => manifestDependencies.parse(JSON.parse(await readFile2(resolve3(directory, "package.json"), "utf8")));
|
|
189
|
+
var containerManifest = async () => {
|
|
190
|
+
const manifests = [await readManifest(packageDirectory)];
|
|
191
|
+
for (const { entry } of containerPackages) {
|
|
192
|
+
manifests.push(await readManifest(packageRoot(entry)));
|
|
193
|
+
}
|
|
194
|
+
return { type: "module", dependencies: containerDependencies(manifests) };
|
|
195
|
+
};
|
|
196
|
+
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";
|
|
197
|
+
var builderRecipe = async () => digestFiles((await recipeFiles()).map((name) => ({
|
|
198
|
+
name,
|
|
199
|
+
path: resolve3(packageDirectory, name)
|
|
200
|
+
})), { manifest: JSON.stringify(await containerManifest()) });
|
|
201
|
+
var recipeFiles = () => listFiles(packageDirectory, resolve3(packageDirectory, "docker"), recipeFile);
|
|
202
|
+
async function prepareDockerContext() {
|
|
203
|
+
const context = await mkdtemp(resolve3(tmpdir(), "tsplc-docker-"));
|
|
204
|
+
try {
|
|
205
|
+
for (const directory of ["src", "python", "docker", "runtime"]) {
|
|
206
|
+
await cp2(resolve3(packageDirectory, directory), resolve3(context, directory), {
|
|
207
|
+
recursive: true,
|
|
208
|
+
filter: includeSource
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
for (const { entry, directory, files } of containerPackages) {
|
|
212
|
+
const root = packageRoot(entry);
|
|
213
|
+
await mkdir(resolve3(context, directory));
|
|
214
|
+
for (const file of files) {
|
|
215
|
+
await cp2(resolve3(root, file), resolve3(context, directory, file), {
|
|
216
|
+
recursive: true,
|
|
217
|
+
filter: includeSource
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
await writeFile2(resolve3(context, "package.json"), JSON.stringify(await containerManifest()));
|
|
222
|
+
return context;
|
|
223
|
+
} catch (cause) {
|
|
224
|
+
await rm2(context, { recursive: true, force: true });
|
|
225
|
+
throw cause;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
119
228
|
|
|
120
229
|
// packages/build/src/docker-run.ts
|
|
121
230
|
import { execFile, spawn } from "node:child_process";
|
|
122
|
-
import { createHash as
|
|
123
|
-
import { copyFile as copyFile2, cp as
|
|
124
|
-
import { basename, posix, relative, resolve as
|
|
231
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
232
|
+
import { copyFile as copyFile2, cp as cp3, mkdir as mkdir2, readFile as readFile3, writeFile as writeFile3 } from "node:fs/promises";
|
|
233
|
+
import { basename as basename2, posix as posix2, relative as relative2, resolve as resolve4, sep as sep2 } from "node:path";
|
|
125
234
|
import { promisify } from "node:util";
|
|
126
235
|
var execute = promisify(execFile);
|
|
127
236
|
var progressLog = (stream) => stream === "stderr" ? console.error : console.log;
|
|
@@ -184,14 +293,14 @@ async function mountLibraries(libraries, directory, root = "/input") {
|
|
|
184
293
|
if (!libraries?.length) {
|
|
185
294
|
return;
|
|
186
295
|
}
|
|
187
|
-
await
|
|
296
|
+
await mkdir2(resolve4(directory, "libraries"), { recursive: true });
|
|
188
297
|
return Promise.all(libraries.map(async (library) => {
|
|
189
|
-
const data = await
|
|
190
|
-
if (
|
|
298
|
+
const data = await readFile3(library.path);
|
|
299
|
+
if (createHash3("sha256").update(data).digest("hex") !== library.sha256) {
|
|
191
300
|
throw new Error(`Library changed after installation: ${library.title}`);
|
|
192
301
|
}
|
|
193
|
-
const filename = `${library.sha256}-${
|
|
194
|
-
await
|
|
302
|
+
const filename = `${library.sha256}-${basename2(library.path)}`;
|
|
303
|
+
await writeFile3(resolve4(directory, "libraries", filename), data);
|
|
195
304
|
return { ...library, path: `${root}/libraries/${filename}` };
|
|
196
305
|
}));
|
|
197
306
|
}
|
|
@@ -202,22 +311,22 @@ var containerConfig = (config, paths, libraries) => ({
|
|
|
202
311
|
docker: undefined,
|
|
203
312
|
codesys: undefined,
|
|
204
313
|
sourceDir: paths.sourceDir,
|
|
205
|
-
entry:
|
|
314
|
+
entry: posix2.resolve(paths.sourceDir, relative2(config.sourceDir, config.entry).split(sep2).join("/")),
|
|
206
315
|
template: paths.template,
|
|
207
316
|
outDir: "/output",
|
|
208
317
|
runtime: undefined
|
|
209
318
|
});
|
|
210
319
|
var writeOperationRequest = async (config, directory, root) => {
|
|
211
|
-
await
|
|
212
|
-
await
|
|
320
|
+
await mkdir2(directory, { recursive: true });
|
|
321
|
+
await cp3(config.sourceDir, resolve4(directory, "sources"), {
|
|
213
322
|
recursive: true
|
|
214
323
|
});
|
|
215
|
-
await copyFile2(config.template,
|
|
216
|
-
await
|
|
324
|
+
await copyFile2(config.template, resolve4(directory, "template.project"));
|
|
325
|
+
await writeFile3(resolve4(directory, "config.json"), JSON.stringify(containerConfig(config, { sourceDir: `${root}/sources`, template: `${root}/template.project` }, await mountLibraries(config.libraries, directory, root))));
|
|
217
326
|
return `${root}/config.json`;
|
|
218
327
|
};
|
|
219
328
|
var prepareContainerRun = async (config, requestDirectory, options) => {
|
|
220
|
-
await
|
|
329
|
+
await writeFile3(resolve4(requestDirectory, "config.json"), JSON.stringify(containerConfig(config, { sourceDir: "/sources", template: "/template.project" }, options.sources ? await mountLibraries(config.libraries, requestDirectory) : [])));
|
|
221
330
|
return [
|
|
222
331
|
"--init",
|
|
223
332
|
...config.docker?.cpuSet ? ["--cpuset-cpus", config.docker.cpuSet] : [],
|
|
@@ -231,7 +340,11 @@ var prepareContainerRun = async (config, requestDirectory, options) => {
|
|
|
231
340
|
"--mount",
|
|
232
341
|
bindMount(config.template, "/template.project", true),
|
|
233
342
|
"--mount",
|
|
234
|
-
bindMount(config.outDir, "/output")
|
|
343
|
+
bindMount(config.outDir, "/output"),
|
|
344
|
+
...containerCode().flatMap(({ source, target }) => [
|
|
345
|
+
"--mount",
|
|
346
|
+
bindMount(source, target, true)
|
|
347
|
+
])
|
|
235
348
|
];
|
|
236
349
|
};
|
|
237
350
|
|
|
@@ -240,90 +353,6 @@ import { copyFile as copyFile3, cp as cp4, mkdir as mkdir3, mkdtemp as mkdtemp2,
|
|
|
240
353
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
241
354
|
import { resolve as resolve5 } from "node:path";
|
|
242
355
|
import { dockerImage } from "@tsplc/config/build";
|
|
243
|
-
|
|
244
|
-
// packages/build/src/docker-context.ts
|
|
245
|
-
import { cp as cp3, mkdir as mkdir2, mkdtemp, readFile as readFile3, rm as rm2, writeFile as writeFile3 } from "node:fs/promises";
|
|
246
|
-
import { createRequire } from "node:module";
|
|
247
|
-
import { tmpdir } from "node:os";
|
|
248
|
-
import { basename as basename2, dirname, resolve as resolve4 } from "node:path";
|
|
249
|
-
import { z as z3 } from "zod";
|
|
250
|
-
|
|
251
|
-
// packages/build/src/package-path.ts
|
|
252
|
-
import { resolve as resolve3 } from "node:path";
|
|
253
|
-
import { fileURLToPath } from "node:url";
|
|
254
|
-
var packageDirectory = resolve3(fileURLToPath(new URL("..", import.meta.url)));
|
|
255
|
-
|
|
256
|
-
// packages/build/src/docker-context.ts
|
|
257
|
-
var includeSource = (source) => {
|
|
258
|
-
const name = basename2(source);
|
|
259
|
-
return name !== "__pycache__" && !name.endsWith(".pyc") && !name.endsWith(".test.ts") && !name.endsWith(".fixtures.ts") && !(name.startsWith("test_") && name.endsWith(".py"));
|
|
260
|
-
};
|
|
261
|
-
var containerPackages = [
|
|
262
|
-
{
|
|
263
|
-
entry: "@tsplc/config/build",
|
|
264
|
-
directory: "shared-config",
|
|
265
|
-
files: ["src", "templates", "package.json"]
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
entry: "@tsplc/iec",
|
|
269
|
-
directory: "shared-iec",
|
|
270
|
-
files: ["src", "package.json"]
|
|
271
|
-
}
|
|
272
|
-
];
|
|
273
|
-
var manifestDependencies = z3.object({
|
|
274
|
-
name: z3.string(),
|
|
275
|
-
dependencies: z3.record(z3.string(), z3.string()).default({})
|
|
276
|
-
});
|
|
277
|
-
function containerDependencies(manifests) {
|
|
278
|
-
const selected = new Map;
|
|
279
|
-
for (const manifest of manifests) {
|
|
280
|
-
for (const [name, version] of Object.entries(manifest.dependencies)) {
|
|
281
|
-
if (name.startsWith("@tsplc/")) {
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
const existing = selected.get(name);
|
|
285
|
-
if (existing && existing.version !== version) {
|
|
286
|
-
throw new Error(`The builder image cannot install ${name}: ${existing.owner} pins ${existing.version} and ${manifest.name} pins ${version}.`);
|
|
287
|
-
}
|
|
288
|
-
selected.set(name, { version, owner: manifest.name });
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return Object.fromEntries([...selected].map(([name, { version }]) => [name, version]));
|
|
292
|
-
}
|
|
293
|
-
var readManifest = async (directory) => manifestDependencies.parse(JSON.parse(await readFile3(resolve4(directory, "package.json"), "utf8")));
|
|
294
|
-
async function prepareDockerContext() {
|
|
295
|
-
const context = await mkdtemp(resolve4(tmpdir(), "tsplc-docker-"));
|
|
296
|
-
try {
|
|
297
|
-
for (const directory of ["src", "python", "docker", "runtime"]) {
|
|
298
|
-
await cp3(resolve4(packageDirectory, directory), resolve4(context, directory), {
|
|
299
|
-
recursive: true,
|
|
300
|
-
filter: includeSource
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
const manifests = [await readManifest(packageDirectory)];
|
|
304
|
-
for (const { entry, directory, files } of containerPackages) {
|
|
305
|
-
const root = resolve4(dirname(createRequire(import.meta.url).resolve(entry)), "..");
|
|
306
|
-
manifests.push(await readManifest(root));
|
|
307
|
-
await mkdir2(resolve4(context, directory));
|
|
308
|
-
for (const file of files) {
|
|
309
|
-
await cp3(resolve4(root, file), resolve4(context, directory, file), {
|
|
310
|
-
recursive: true,
|
|
311
|
-
filter: includeSource
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
await writeFile3(resolve4(context, "package.json"), JSON.stringify({
|
|
316
|
-
type: "module",
|
|
317
|
-
dependencies: containerDependencies(manifests)
|
|
318
|
-
}));
|
|
319
|
-
return context;
|
|
320
|
-
} catch (cause) {
|
|
321
|
-
await rm2(context, { recursive: true, force: true });
|
|
322
|
-
throw cause;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// packages/build/src/images.ts
|
|
327
356
|
var builderImage = dockerImage;
|
|
328
357
|
var gatewayImage = "tsplc-edge-gateway:4.22.0.0";
|
|
329
358
|
var runtimeImage = "tsplc-control-linux-sl:4.22.0.0";
|
|
@@ -337,6 +366,7 @@ var setupPlatformFor = (server) => {
|
|
|
337
366
|
}
|
|
338
367
|
return null;
|
|
339
368
|
};
|
|
369
|
+
var recipeLabel = "tsplc.recipe";
|
|
340
370
|
async function buildBuilderImage(options) {
|
|
341
371
|
const installerContext = await mkdtemp2(resolve5(tmpdir2(), "codesys-installer-"));
|
|
342
372
|
let context;
|
|
@@ -361,6 +391,8 @@ async function buildBuilderImage(options) {
|
|
|
361
391
|
`SETUP_PLATFORM=${options.setupPlatform}`,
|
|
362
392
|
"--build-arg",
|
|
363
393
|
`INSTALLER_SOURCE=${options.installer ? "installer-local" : "installer-download"}`,
|
|
394
|
+
"--label",
|
|
395
|
+
`${recipeLabel}=${await builderRecipe()}`,
|
|
364
396
|
"--progress",
|
|
365
397
|
"plain",
|
|
366
398
|
"--build-context",
|
|
@@ -378,6 +410,16 @@ async function buildBuilderImage(options) {
|
|
|
378
410
|
]);
|
|
379
411
|
}
|
|
380
412
|
}
|
|
413
|
+
var buildRuntimeImage = (options) => options.docker([
|
|
414
|
+
"build",
|
|
415
|
+
"--platform",
|
|
416
|
+
"linux/amd64",
|
|
417
|
+
"--progress",
|
|
418
|
+
"plain",
|
|
419
|
+
"-t",
|
|
420
|
+
options.tag,
|
|
421
|
+
resolve5(packageDirectory, "docker/control-linux-sl")
|
|
422
|
+
]);
|
|
381
423
|
var buildGatewayImage = (options) => options.docker([
|
|
382
424
|
"build",
|
|
383
425
|
"--platform",
|
|
@@ -389,8 +431,86 @@ var buildGatewayImage = (options) => options.docker([
|
|
|
389
431
|
resolve5(packageDirectory, "docker/edge-gateway")
|
|
390
432
|
]);
|
|
391
433
|
|
|
434
|
+
// packages/build/src/builder-image.ts
|
|
435
|
+
var imageManifest = "/opt/codesys-build/package.json";
|
|
436
|
+
var dockerTimeout = 60000;
|
|
437
|
+
var labelsSchema = z3.record(z3.string(), z3.string()).nullable();
|
|
438
|
+
var setupReason = (status) => {
|
|
439
|
+
switch (status.kind) {
|
|
440
|
+
case "missing":
|
|
441
|
+
return `the CODESYS builder image ${builderImage} is missing`;
|
|
442
|
+
case "outdated":
|
|
443
|
+
return status.reason;
|
|
444
|
+
case "current":
|
|
445
|
+
case "unverified":
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
var builderImageStatus = async (image = builderImage) => {
|
|
450
|
+
const docker = async (...args) => (await captureDocker(args, dockerTimeout)).stdout.trim();
|
|
451
|
+
if (!await docker("image", "ls", "--quiet", image)) {
|
|
452
|
+
return { kind: "missing" };
|
|
453
|
+
}
|
|
454
|
+
const labels = labelsSchema.parse(JSON.parse(await docker("image", "inspect", "--format", "{{json .Config.Labels}}", image)));
|
|
455
|
+
const recipe = labels?.[recipeLabel];
|
|
456
|
+
if (recipe !== undefined) {
|
|
457
|
+
return recipe === await builderRecipe() ? { kind: "current" } : {
|
|
458
|
+
kind: "outdated",
|
|
459
|
+
reason: `the CODESYS builder image ${image} was built from another recipe: another CODESYS installation, Bun or third-party packages`
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
const installed = JSON.parse(await docker("run", "--rm", "--network", "none", "--entrypoint", "cat", image, imageManifest));
|
|
463
|
+
if (!isDeepStrictEqual(installed, await containerManifest())) {
|
|
464
|
+
return {
|
|
465
|
+
kind: "outdated",
|
|
466
|
+
reason: `the CODESYS builder image ${image} installed other third-party packages than this tsPLC needs`
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
kind: "unverified",
|
|
471
|
+
reason: `the CODESYS builder image ${image} predates recipe labels, so whether its CODESYS installation is this tsPLC's can't be checked; its third-party packages match`
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
// packages/build/src/diagnostics.ts
|
|
476
|
+
import { z as z4 } from "zod";
|
|
477
|
+
var compilerDiagnosticSchema = z4.object({
|
|
478
|
+
category: z4.string(),
|
|
479
|
+
text: z4.string(),
|
|
480
|
+
severity: z4.string().nullable(),
|
|
481
|
+
project: z4.string().nullable(),
|
|
482
|
+
object: z4.object({
|
|
483
|
+
name: z4.string(),
|
|
484
|
+
guid: z4.string(),
|
|
485
|
+
path: z4.array(z4.string()),
|
|
486
|
+
isApplicationChild: z4.boolean().nullable()
|
|
487
|
+
}).passthrough().nullable(),
|
|
488
|
+
position: z4.string().nullable(),
|
|
489
|
+
positionText: z4.string().nullable(),
|
|
490
|
+
positionOffset: z4.int().nullable(),
|
|
491
|
+
length: z4.int().nullable(),
|
|
492
|
+
prefix: z4.string().nullable(),
|
|
493
|
+
number: z4.int().nullable()
|
|
494
|
+
}).passthrough();
|
|
495
|
+
|
|
496
|
+
class CodesysCompilerError extends Error {
|
|
497
|
+
diagnostics;
|
|
498
|
+
constructor(message, diagnostics) {
|
|
499
|
+
super(message);
|
|
500
|
+
this.diagnostics = diagnostics;
|
|
501
|
+
this.name = "CodesysCompilerError";
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
var buildFailureFile = ".codesys/docker/failure.json";
|
|
505
|
+
var controllerFailureFile = ".codesys/controller/failure.txt";
|
|
506
|
+
var buildFailureSchema = z4.strictObject({
|
|
507
|
+
operationId: z4.uuid(),
|
|
508
|
+
message: z4.string(),
|
|
509
|
+
diagnostics: z4.array(compilerDiagnosticSchema)
|
|
510
|
+
});
|
|
511
|
+
|
|
392
512
|
// packages/build/src/docker-build.ts
|
|
393
|
-
var packageVersion = async () =>
|
|
513
|
+
var packageVersion = async () => z5.object({ version: z5.string() }).parse(JSON.parse(await readFile4(resolve6(packageDirectory, "package.json"), "utf8"))).version;
|
|
394
514
|
var pullPublished = async (image, progress) => {
|
|
395
515
|
const published = publishedImage(image, await packageVersion());
|
|
396
516
|
const output = { progress, environment: {} };
|
|
@@ -405,7 +525,8 @@ var pullPublished = async (image, progress) => {
|
|
|
405
525
|
return true;
|
|
406
526
|
};
|
|
407
527
|
var configureDocker = async ({
|
|
408
|
-
progress = "stdout"
|
|
528
|
+
progress = "stdout",
|
|
529
|
+
keepUnverified = false
|
|
409
530
|
} = {}) => {
|
|
410
531
|
const image = builderImage;
|
|
411
532
|
const { stdout } = await captureDocker(["info", "--format", "{{.OSType}}/{{.Architecture}}"], 30000).catch((cause) => {
|
|
@@ -417,7 +538,17 @@ var configureDocker = async ({
|
|
|
417
538
|
if (!setupPlatform) {
|
|
418
539
|
throw new Error("The builder requires a Linux Docker server on ARM64 or AMD64");
|
|
419
540
|
}
|
|
420
|
-
|
|
541
|
+
const status = await builderImageStatus(image);
|
|
542
|
+
if (status.kind === "current") {
|
|
543
|
+
progressLog(progress)(`The Docker builder (${image}) was built from this tsPLC's recipe; keeping it.`);
|
|
544
|
+
return image;
|
|
545
|
+
}
|
|
546
|
+
if (status.kind === "unverified" && keepUnverified) {
|
|
547
|
+
progressLog(progress)(`Keeping the Docker builder: ${status.reason}.`);
|
|
548
|
+
return image;
|
|
549
|
+
}
|
|
550
|
+
progressLog(progress)(`Rebuilding the Docker builder: ${status.kind === "unverified" ? status.reason : setupReason(status)}.`);
|
|
551
|
+
if (await pullPublished(image, progress) && (await builderImageStatus(image)).kind === "current") {
|
|
421
552
|
return image;
|
|
422
553
|
}
|
|
423
554
|
progressLog(progress)(`Preparing Docker builder (${image}). Downloading and installing CODESYS 3.5.22.30 and prerequisites.`);
|
|
@@ -433,23 +564,20 @@ var configureDocker = async ({
|
|
|
433
564
|
var configureRuntime = async ({
|
|
434
565
|
progress = "stdout"
|
|
435
566
|
} = {}) => {
|
|
436
|
-
const context = resolve6(packageDirectory, "docker/control-linux-sl");
|
|
437
567
|
progressLog(progress)(`Preparing the local PLC runtime (${runtimeImage}).`);
|
|
438
|
-
await
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
"--progress",
|
|
443
|
-
"plain",
|
|
444
|
-
"-t",
|
|
445
|
-
runtimeImage,
|
|
446
|
-
context
|
|
447
|
-
], (status) => `Runtime image build failed (${status}). Review the image-build output`, { progress, environment: {} });
|
|
568
|
+
await buildRuntimeImage({
|
|
569
|
+
tag: runtimeImage,
|
|
570
|
+
docker: (args) => runDocker(args, (status) => `Runtime image build failed (${status}). Review the image-build output`, { progress, environment: {} })
|
|
571
|
+
});
|
|
448
572
|
return runtimeImage;
|
|
449
573
|
};
|
|
450
574
|
var configureGateway = async ({
|
|
451
575
|
progress = "stdout"
|
|
452
576
|
} = {}) => {
|
|
577
|
+
if ((await captureDocker(["image", "ls", "--quiet", gatewayImage], 60000)).stdout.trim()) {
|
|
578
|
+
progressLog(progress)(`The CODESYS gateway (${gatewayImage}) is present.`);
|
|
579
|
+
return gatewayImage;
|
|
580
|
+
}
|
|
453
581
|
if (await pullPublished(gatewayImage, progress)) {
|
|
454
582
|
return gatewayImage;
|
|
455
583
|
}
|
|
@@ -515,7 +643,7 @@ ${failure.message}`;
|
|
|
515
643
|
};
|
|
516
644
|
|
|
517
645
|
// packages/build/src/host/codesys-worker.ts
|
|
518
|
-
import { createHash as
|
|
646
|
+
import { createHash as createHash4, randomUUID as randomUUID2 } from "node:crypto";
|
|
519
647
|
import {
|
|
520
648
|
access,
|
|
521
649
|
copyFile as copyFile4,
|
|
@@ -529,7 +657,7 @@ import {
|
|
|
529
657
|
} from "node:fs/promises";
|
|
530
658
|
import { resolve as resolve7 } from "node:path";
|
|
531
659
|
import { setTimeout as delay } from "node:timers/promises";
|
|
532
|
-
import { z as
|
|
660
|
+
import { z as z8 } from "zod";
|
|
533
661
|
|
|
534
662
|
// packages/build/src/controller-protocol.ts
|
|
535
663
|
import {
|
|
@@ -537,44 +665,44 @@ import {
|
|
|
537
665
|
sha256Digest,
|
|
538
666
|
tcpPort
|
|
539
667
|
} from "@tsplc/config/build";
|
|
540
|
-
import { z as
|
|
541
|
-
var imageIdSchema =
|
|
542
|
-
var endpointSchema =
|
|
543
|
-
host:
|
|
668
|
+
import { z as z6 } from "zod";
|
|
669
|
+
var imageIdSchema = z6.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
670
|
+
var endpointSchema = z6.strictObject({
|
|
671
|
+
host: z6.string().nonempty(),
|
|
544
672
|
port: tcpPort
|
|
545
673
|
});
|
|
546
|
-
var controllerResultSchema =
|
|
547
|
-
schemaVersion:
|
|
548
|
-
operationId:
|
|
549
|
-
operation:
|
|
674
|
+
var controllerResultSchema = z6.strictObject({
|
|
675
|
+
schemaVersion: z6.literal(1),
|
|
676
|
+
operationId: z6.uuid(),
|
|
677
|
+
operation: z6.enum(["download", "online-change", "inspect"]),
|
|
550
678
|
imageId: imageIdSchema,
|
|
551
679
|
templateHash: sha256Digest,
|
|
552
|
-
target:
|
|
553
|
-
network:
|
|
680
|
+
target: z6.strictObject({
|
|
681
|
+
network: z6.string().nonempty(),
|
|
554
682
|
gateway: endpointSchema,
|
|
555
683
|
device: endpointSchema,
|
|
556
684
|
controller: controllerSchema.optional(),
|
|
557
685
|
deviceTree: sha256Digest.optional()
|
|
558
686
|
}),
|
|
559
|
-
generation:
|
|
560
|
-
application:
|
|
561
|
-
applicationGuid:
|
|
562
|
-
controllerIds:
|
|
563
|
-
codeId:
|
|
564
|
-
dataId:
|
|
687
|
+
generation: z6.string().nonempty(),
|
|
688
|
+
application: z6.string().nonempty(),
|
|
689
|
+
applicationGuid: z6.string().nonempty(),
|
|
690
|
+
controllerIds: z6.strictObject({
|
|
691
|
+
codeId: z6.string().nonempty(),
|
|
692
|
+
dataId: z6.string().nonempty()
|
|
565
693
|
}),
|
|
566
|
-
state:
|
|
567
|
-
values:
|
|
694
|
+
state: z6.string().nonempty(),
|
|
695
|
+
values: z6.record(z6.string(), z6.string())
|
|
568
696
|
});
|
|
569
|
-
var controllerCredentialsSchema =
|
|
570
|
-
username:
|
|
571
|
-
password:
|
|
697
|
+
var controllerCredentialsSchema = z6.strictObject({
|
|
698
|
+
username: z6.string().nonempty(),
|
|
699
|
+
password: z6.string().nonempty()
|
|
572
700
|
});
|
|
573
|
-
var warmOperationSchema =
|
|
574
|
-
operation:
|
|
575
|
-
operationId:
|
|
576
|
-
request:
|
|
577
|
-
initializeUser:
|
|
701
|
+
var warmOperationSchema = z6.strictObject({
|
|
702
|
+
operation: z6.enum(["download", "online-change"]),
|
|
703
|
+
operationId: z6.uuid(),
|
|
704
|
+
request: z6.string().nonempty(),
|
|
705
|
+
initializeUser: z6.boolean(),
|
|
578
706
|
credentials: controllerCredentialsSchema.optional()
|
|
579
707
|
});
|
|
580
708
|
var tracebackFailure = (traceback) => {
|
|
@@ -605,7 +733,7 @@ var explicitDownload = "use an explicit download";
|
|
|
605
733
|
class DownloadRequiredError extends Error {
|
|
606
734
|
downloadRequired = true;
|
|
607
735
|
}
|
|
608
|
-
var rollbackSchema =
|
|
736
|
+
var rollbackSchema = z6.enum([
|
|
609
737
|
"intact",
|
|
610
738
|
"restored",
|
|
611
739
|
"failed",
|
|
@@ -626,30 +754,30 @@ var transferRollback = (error) => {
|
|
|
626
754
|
return rollbackSchema.safeParse(error.rollback).data;
|
|
627
755
|
};
|
|
628
756
|
var requiresDownload = (error) => error instanceof Error && ("downloadRequired" in error) && error.downloadRequired === true;
|
|
629
|
-
var loginCommandSchema =
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
command:
|
|
633
|
-
expressions:
|
|
757
|
+
var loginCommandSchema = z6.discriminatedUnion("command", [
|
|
758
|
+
z6.strictObject({ command: z6.literal("state") }),
|
|
759
|
+
z6.strictObject({
|
|
760
|
+
command: z6.literal("read"),
|
|
761
|
+
expressions: z6.array(z6.string().nonempty()).nonempty()
|
|
634
762
|
}),
|
|
635
|
-
|
|
636
|
-
command:
|
|
637
|
-
values:
|
|
763
|
+
z6.strictObject({
|
|
764
|
+
command: z6.enum(["write", "force"]),
|
|
765
|
+
values: z6.record(z6.string().nonempty(), z6.string().nonempty())
|
|
638
766
|
}),
|
|
639
|
-
|
|
640
|
-
command:
|
|
641
|
-
expressions:
|
|
642
|
-
restore:
|
|
767
|
+
z6.strictObject({
|
|
768
|
+
command: z6.literal("unforce"),
|
|
769
|
+
expressions: z6.array(z6.string().nonempty()),
|
|
770
|
+
restore: z6.boolean()
|
|
643
771
|
}),
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
command:
|
|
647
|
-
kind:
|
|
772
|
+
z6.strictObject({ command: z6.enum(["start", "stop"]) }),
|
|
773
|
+
z6.strictObject({
|
|
774
|
+
command: z6.literal("reset"),
|
|
775
|
+
kind: z6.enum(["Warm", "Cold"])
|
|
648
776
|
})
|
|
649
777
|
]);
|
|
650
|
-
var loginResultSchema =
|
|
651
|
-
|
|
652
|
-
|
|
778
|
+
var loginResultSchema = z6.union([
|
|
779
|
+
z6.strictObject({ values: z6.record(z6.string(), z6.string()) }),
|
|
780
|
+
z6.strictObject({ state: z6.string(), forced: z6.array(z6.string()) })
|
|
653
781
|
]);
|
|
654
782
|
|
|
655
783
|
// packages/build/src/host/codesys-command.ts
|
|
@@ -667,7 +795,7 @@ var codesysCommand = [
|
|
|
667
795
|
// packages/build/src/host/codesys-host.ts
|
|
668
796
|
import { execFile as execFile3, spawn as spawn2 } from "node:child_process";
|
|
669
797
|
import { promisify as promisify3 } from "node:util";
|
|
670
|
-
import { z as
|
|
798
|
+
import { z as z7 } from "zod";
|
|
671
799
|
|
|
672
800
|
// packages/build/src/host/windows-path.ts
|
|
673
801
|
import { execFile as execFile2 } from "node:child_process";
|
|
@@ -680,10 +808,10 @@ var execute2 = promisify2(execFile2);
|
|
|
680
808
|
|
|
681
809
|
// packages/build/src/host/codesys-host.ts
|
|
682
810
|
var execute3 = promisify3(execFile3);
|
|
683
|
-
var exitSchema =
|
|
684
|
-
pid:
|
|
685
|
-
code:
|
|
686
|
-
signal:
|
|
811
|
+
var exitSchema = z7.object({
|
|
812
|
+
pid: z7.int().positive(),
|
|
813
|
+
code: z7.int().nullable(),
|
|
814
|
+
signal: z7.string().nullable()
|
|
687
815
|
});
|
|
688
816
|
|
|
689
817
|
// packages/build/src/host/codesys-worker.ts
|
|
@@ -695,13 +823,13 @@ var workerScripts = [
|
|
|
695
823
|
"codesys_online.py",
|
|
696
824
|
"codesys_login.py"
|
|
697
825
|
];
|
|
698
|
-
var workerScriptsDigest = async () =>
|
|
699
|
-
var sessionSchema =
|
|
700
|
-
directory:
|
|
701
|
-
fingerprint:
|
|
702
|
-
pid:
|
|
826
|
+
var workerScriptsDigest = async () => createHash4("sha256").update(JSON.stringify(await Promise.all(workerScripts.map((script) => readFile5(resolve7(pythonDirectory, script), "utf8"))))).digest("hex");
|
|
827
|
+
var sessionSchema = z8.object({
|
|
828
|
+
directory: z8.string(),
|
|
829
|
+
fingerprint: z8.string(),
|
|
830
|
+
pid: z8.int().positive()
|
|
703
831
|
});
|
|
704
|
-
var phaseSchema =
|
|
832
|
+
var phaseSchema = z8.enum(["prepare", "transfer"]);
|
|
705
833
|
var hasCode = (error, code) => error instanceof Error && ("code" in error) && error.code === code;
|
|
706
834
|
var isProcessAlive = (pid) => {
|
|
707
835
|
try {
|
|
@@ -751,7 +879,7 @@ var withWorkerLock = async (config, run) => {
|
|
|
751
879
|
};
|
|
752
880
|
|
|
753
881
|
// packages/build/src/sources.ts
|
|
754
|
-
import { readdir, readFile as readFile6 } from "node:fs/promises";
|
|
882
|
+
import { readdir as readdir2, readFile as readFile6 } from "node:fs/promises";
|
|
755
883
|
import { basename as basename4, resolve as resolve8 } from "node:path";
|
|
756
884
|
import { identifierPattern as identifierPattern3 } from "@tsplc/iec/st";
|
|
757
885
|
|
|
@@ -1434,7 +1562,7 @@ END_METHOD`, {
|
|
|
1434
1562
|
var loadSources = async (config) => {
|
|
1435
1563
|
const objects = [];
|
|
1436
1564
|
const visit = async (directory, folder, parent, role) => {
|
|
1437
|
-
const entries = (await
|
|
1565
|
+
const entries = (await readdir2(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name, "en"));
|
|
1438
1566
|
const groups = new Map;
|
|
1439
1567
|
for (const entry of entries) {
|
|
1440
1568
|
if (entry.isSymbolicLink()) {
|
|
@@ -1533,31 +1661,31 @@ var buildProject = async (config, { progress = "stdout" } = {}) => {
|
|
|
1533
1661
|
return buildInDocker(config, builderImage, progress);
|
|
1534
1662
|
};
|
|
1535
1663
|
// packages/build/src/controller-online.ts
|
|
1536
|
-
import { createHash as
|
|
1664
|
+
import { createHash as createHash5, randomUUID as randomUUID3 } from "node:crypto";
|
|
1537
1665
|
import { existsSync } from "node:fs";
|
|
1538
1666
|
import { mkdir as mkdir7, mkdtemp as mkdtemp4, readFile as readFile8, rm as rm7 } from "node:fs/promises";
|
|
1539
1667
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
1540
|
-
import { posix as
|
|
1668
|
+
import { posix as posix3, resolve as resolve10 } from "node:path";
|
|
1541
1669
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
1542
1670
|
import { controllerBudgets as controllerBudgets2 } from "@tsplc/config/build";
|
|
1543
|
-
import { z as
|
|
1671
|
+
import { z as z10 } from "zod";
|
|
1544
1672
|
|
|
1545
1673
|
// packages/build/src/controller-session.ts
|
|
1546
|
-
import { cp as cp5, mkdir as mkdir6, readdir as
|
|
1674
|
+
import { cp as cp5, mkdir as mkdir6, readdir as readdir3, readFile as readFile7, rm as rm6, writeFile as writeFile5 } from "node:fs/promises";
|
|
1547
1675
|
import { resolve as resolve9 } from "node:path";
|
|
1548
1676
|
import {
|
|
1549
1677
|
controllerBudgets,
|
|
1550
1678
|
sha256Digest as sha256Digest2
|
|
1551
1679
|
} from "@tsplc/config/build";
|
|
1552
|
-
import { z as
|
|
1553
|
-
var guid =
|
|
1554
|
-
var pointerSchema =
|
|
1555
|
-
schemaVersion:
|
|
1556
|
-
generation:
|
|
1680
|
+
import { z as z9 } from "zod";
|
|
1681
|
+
var guid = z9.string().regex(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i);
|
|
1682
|
+
var pointerSchema = z9.strictObject({
|
|
1683
|
+
schemaVersion: z9.literal(1),
|
|
1684
|
+
generation: z9.uuid()
|
|
1557
1685
|
});
|
|
1558
1686
|
var baselineSchema = controllerResultSchema.extend({
|
|
1559
|
-
objects:
|
|
1560
|
-
files:
|
|
1687
|
+
objects: z9.array(z9.record(z9.string(), z9.unknown())),
|
|
1688
|
+
files: z9.record(z9.string(), sha256Digest2),
|
|
1561
1689
|
deviceSettings: sha256Digest2.optional()
|
|
1562
1690
|
});
|
|
1563
1691
|
var controllerDirectory = (outDir) => resolve9(outDir, ".codesys/controller");
|
|
@@ -1578,10 +1706,10 @@ var controllerBaseline = async (outDir) => {
|
|
|
1578
1706
|
return "malformed";
|
|
1579
1707
|
}
|
|
1580
1708
|
};
|
|
1581
|
-
var restoreResultSchema =
|
|
1582
|
-
restored:
|
|
1583
|
-
controllerIds:
|
|
1584
|
-
state:
|
|
1709
|
+
var restoreResultSchema = z9.object({
|
|
1710
|
+
restored: z9.boolean(),
|
|
1711
|
+
controllerIds: z9.strictObject({ codeId: guid, dataId: guid }),
|
|
1712
|
+
state: z9.string()
|
|
1585
1713
|
});
|
|
1586
1714
|
|
|
1587
1715
|
// packages/build/src/controller-online.ts
|
|
@@ -1607,7 +1735,7 @@ var controllerConnection = async (config) => {
|
|
|
1607
1735
|
});
|
|
1608
1736
|
return {
|
|
1609
1737
|
imageId: imageIdSchema.parse(stdout.trim()),
|
|
1610
|
-
templateHash:
|
|
1738
|
+
templateHash: createHash5("sha256").update(await readFile8(config.template)).digest("hex"),
|
|
1611
1739
|
target: controllerTarget(config, config.online)
|
|
1612
1740
|
};
|
|
1613
1741
|
};
|
|
@@ -1664,12 +1792,12 @@ var controllerOperation = async (config, operation, options) => {
|
|
|
1664
1792
|
};
|
|
1665
1793
|
var updateController = (config, operation, options = {}) => controllerOperation(config, operation, options);
|
|
1666
1794
|
var inspectController = (config, read, options = {}) => controllerOperation(config, "inspect", { ...options, read });
|
|
1667
|
-
var loginReplySchema =
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
ok:
|
|
1671
|
-
error:
|
|
1672
|
-
downloadRequired:
|
|
1795
|
+
var loginReplySchema = z10.discriminatedUnion("ok", [
|
|
1796
|
+
z10.strictObject({ ok: z10.literal(true), result: z10.unknown() }),
|
|
1797
|
+
z10.strictObject({
|
|
1798
|
+
ok: z10.literal(false),
|
|
1799
|
+
error: z10.string(),
|
|
1800
|
+
downloadRequired: z10.literal(true).optional(),
|
|
1673
1801
|
rollback: rollbackSchema.optional()
|
|
1674
1802
|
})
|
|
1675
1803
|
]);
|
|
@@ -1713,7 +1841,7 @@ var callContainer = async (name, port, method, body) => {
|
|
|
1713
1841
|
return reply.result;
|
|
1714
1842
|
};
|
|
1715
1843
|
var answers = (name, port) => callContainer(name, port, "GET").then(() => true, () => false);
|
|
1716
|
-
var warmStateSchema =
|
|
1844
|
+
var warmStateSchema = z10.object({ finishing: z10.boolean() });
|
|
1717
1845
|
var finishing = (name) => callContainer(name, warmPort, "GET").then((state) => warmStateSchema.safeParse(state).data?.finishing === true, () => false);
|
|
1718
1846
|
var settleWarmController = async (config, name) => {
|
|
1719
1847
|
const deadline = Date.now() + 2 * controllerBudgets2(config.timeouts).prepare;
|
|
@@ -1789,7 +1917,12 @@ ${await recentLogs(name, timeout)}`);
|
|
|
1789
1917
|
var warmController = async (config, name, connection, report) => {
|
|
1790
1918
|
const timeout = config.timeouts.hostCommand;
|
|
1791
1919
|
const { imageId, target } = connection;
|
|
1792
|
-
const settings =
|
|
1920
|
+
const settings = createHash5("sha256").update(JSON.stringify({
|
|
1921
|
+
imageId,
|
|
1922
|
+
target,
|
|
1923
|
+
docker: config.docker,
|
|
1924
|
+
code: await containerCodeDigest()
|
|
1925
|
+
})).digest("hex");
|
|
1793
1926
|
const label = `tsplc.warm=${settings}`;
|
|
1794
1927
|
const running = async () => await docker([
|
|
1795
1928
|
"container",
|
|
@@ -1801,7 +1934,7 @@ var warmController = async (config, name, connection, report) => {
|
|
|
1801
1934
|
`label=${label}`
|
|
1802
1935
|
], timeout) !== "";
|
|
1803
1936
|
if (!await running() || !await answers(name, warmPort)) {
|
|
1804
|
-
report("Starting CODESYS: no running builder matches this image, controller and Docker settings, which takes minutes");
|
|
1937
|
+
report("Starting CODESYS: no running builder matches this image, tsPLC, controller and Docker settings, which takes minutes");
|
|
1805
1938
|
await settleWarmController(config, name);
|
|
1806
1939
|
await docker(["rm", "--force", name], timeout);
|
|
1807
1940
|
const requestDirectory = resolve10(config.outDir, ".codesys/warm-request");
|
|
@@ -1874,7 +2007,7 @@ var updateWarmController = async (config, name, operation, options = {}) => {
|
|
|
1874
2007
|
const directory = resolve10(config.outDir, ".codesys/requests", operationId);
|
|
1875
2008
|
report("Copying the release for CODESYS");
|
|
1876
2009
|
const [request] = await Promise.all([
|
|
1877
|
-
writeOperationRequest(config, directory,
|
|
2010
|
+
writeOperationRequest(config, directory, posix3.join("/output/.codesys/requests", operationId)),
|
|
1878
2011
|
warmController(config, name, connection, report)
|
|
1879
2012
|
]).catch(async (error) => {
|
|
1880
2013
|
await rm7(directory, { recursive: true, force: true });
|
|
@@ -1919,26 +2052,26 @@ import { deviceTree } from "@tsplc/typegen";
|
|
|
1919
2052
|
import { loadHardware, resolveIo } from "@tsplc/typegen/hardware";
|
|
1920
2053
|
|
|
1921
2054
|
// packages/build/src/libraries.ts
|
|
1922
|
-
import { createHash as
|
|
2055
|
+
import { createHash as createHash6, randomUUID as randomUUID4 } from "node:crypto";
|
|
1923
2056
|
import { mkdir as mkdir8, readFile as readFile9, rename as rename3, writeFile as writeFile6 } from "node:fs/promises";
|
|
1924
|
-
import { basename as basename5, relative as
|
|
2057
|
+
import { basename as basename5, relative as relative3, resolve as resolve11 } from "node:path";
|
|
1925
2058
|
import { sha256Digest as sha256Digest3 } from "@tsplc/config/build";
|
|
1926
2059
|
import { generatedDirectory } from "@tsplc/config/project-files";
|
|
1927
|
-
import { z as
|
|
2060
|
+
import { z as z11 } from "zod";
|
|
1928
2061
|
var libraryRegistry = "https://store-archive.codesys.com/CODESYSLibs";
|
|
1929
2062
|
var libraryFile = /\.(?:compiled-library(?:-v\d+)?|library)$/i;
|
|
1930
|
-
var installedLibrarySchema =
|
|
1931
|
-
title:
|
|
1932
|
-
company:
|
|
1933
|
-
version:
|
|
1934
|
-
namespace:
|
|
1935
|
-
path:
|
|
2063
|
+
var installedLibrarySchema = z11.object({
|
|
2064
|
+
title: z11.string(),
|
|
2065
|
+
company: z11.string().optional(),
|
|
2066
|
+
version: z11.string().optional(),
|
|
2067
|
+
namespace: z11.string().optional(),
|
|
2068
|
+
path: z11.string(),
|
|
1936
2069
|
sha256: sha256Digest3,
|
|
1937
|
-
url:
|
|
2070
|
+
url: z11.string().optional()
|
|
1938
2071
|
});
|
|
1939
|
-
var libraryLockSchema =
|
|
1940
|
-
version:
|
|
1941
|
-
dependencies:
|
|
2072
|
+
var libraryLockSchema = z11.object({
|
|
2073
|
+
version: z11.literal(1),
|
|
2074
|
+
dependencies: z11.record(z11.string(), installedLibrarySchema)
|
|
1942
2075
|
});
|
|
1943
2076
|
var readLock = async (file) => {
|
|
1944
2077
|
const text = await readFile9(file, "utf8").catch((cause) => {
|
|
@@ -1956,7 +2089,7 @@ var readLock = async (file) => {
|
|
|
1956
2089
|
}
|
|
1957
2090
|
return lock.data;
|
|
1958
2091
|
};
|
|
1959
|
-
var hash = (data) =>
|
|
2092
|
+
var hash = (data) => createHash6("sha256").update(data).digest("hex");
|
|
1960
2093
|
var component = (name) => {
|
|
1961
2094
|
if (!name.trim() || /[/\\\0\r\n]/.test(name) || name === "." || name === "..") {
|
|
1962
2095
|
throw new Error(`Invalid library registry component: ${name}.`);
|
|
@@ -2070,7 +2203,7 @@ async function installLibraries(dependencies, root, options = {}) {
|
|
|
2070
2203
|
title,
|
|
2071
2204
|
{
|
|
2072
2205
|
...library,
|
|
2073
|
-
path:
|
|
2206
|
+
path: relative3(root, library.path).replaceAll("\\", "/")
|
|
2074
2207
|
}
|
|
2075
2208
|
]));
|
|
2076
2209
|
await writeFile6(temp, `${JSON.stringify({ version: 1, dependencies: portable }, null, 2)}
|
|
@@ -2122,7 +2255,7 @@ import { mkdtemp as mkdtemp5, readFile as readFile10, rm as rm8, writeFile as wr
|
|
|
2122
2255
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
2123
2256
|
import { basename as basename6, dirname as dirname2, join } from "node:path";
|
|
2124
2257
|
import { setTimeout as delay3 } from "node:timers/promises";
|
|
2125
|
-
import { z as
|
|
2258
|
+
import { z as z12 } from "zod";
|
|
2126
2259
|
|
|
2127
2260
|
// packages/build/src/runtime-status.ts
|
|
2128
2261
|
var getApplicationStatus = (log, application, startedAt) => {
|
|
@@ -2140,9 +2273,9 @@ var getApplicationStatus = (log, application, startedAt) => {
|
|
|
2140
2273
|
};
|
|
2141
2274
|
|
|
2142
2275
|
// packages/build/src/run.ts
|
|
2143
|
-
var stateSchema =
|
|
2144
|
-
Running:
|
|
2145
|
-
StartedAt:
|
|
2276
|
+
var stateSchema = z12.object({
|
|
2277
|
+
Running: z12.boolean(),
|
|
2278
|
+
StartedAt: z12.iso.datetime({ offset: true })
|
|
2146
2279
|
});
|
|
2147
2280
|
var service = "plc";
|
|
2148
2281
|
var runtimeProject = (name) => name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9_-]+/g, "-");
|
|
@@ -2215,6 +2348,7 @@ export {
|
|
|
2215
2348
|
StSyntaxError,
|
|
2216
2349
|
TransferFailedError,
|
|
2217
2350
|
buildProject,
|
|
2351
|
+
builderImageStatus,
|
|
2218
2352
|
captureDocker,
|
|
2219
2353
|
checkRawSources,
|
|
2220
2354
|
configSchema,
|
|
@@ -2244,6 +2378,7 @@ export {
|
|
|
2244
2378
|
rollbackSchema,
|
|
2245
2379
|
runProject,
|
|
2246
2380
|
settleWarmController,
|
|
2381
|
+
setupReason,
|
|
2247
2382
|
startWarmController,
|
|
2248
2383
|
transferRollback,
|
|
2249
2384
|
updateController,
|
|
@@ -2252,5 +2387,5 @@ export {
|
|
|
2252
2387
|
workerScriptsDigest
|
|
2253
2388
|
};
|
|
2254
2389
|
|
|
2255
|
-
//# debugId=
|
|
2390
|
+
//# debugId=86BB7E15A6DD5A5B64756E2164756E21
|
|
2256
2391
|
//# sourceMappingURL=index.js.map
|