-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathudocker.js
More file actions
executable file
·715 lines (679 loc) · 22 KB
/
Copy pathudocker.js
File metadata and controls
executable file
·715 lines (679 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const { pathToFileURL } = require("url");
const { LocalRepository } = require("./lib/localrepo");
const { DockerApi } = require("./lib/dockerapi");
const { ContainerStructure } = require("./lib/container");
const { LocalFileApi } = require("./lib/localfile");
const { Msg } = require("./lib/msg");
function usage() {
Msg.out("Usage:");
Msg.out(" udocker pull [--platform=os/arch[/variant]] [--registry=URL] [--pull=missing|always|never] [-q|--quiet] <repo/image:tag>");
Msg.out(" udocker build -t <container_name> [-f Dockerfile] [--build-arg KEY=VALUE] [-y|-n] [context]");
Msg.out(" udocker create [--name=NAME] [--force] <repo/image:tag>");
Msg.out(" udocker run [-e key=val] [-p port:port] [-v volume:/path] [-w workdir] [--rm] [--name=NAME] [--entrypoint <program>/json_array_dataurl ] [--isolated] <container/image>");
Msg.out(" udocker import <tar> <repo/image:tag>");
Msg.out(" udocker import - <repo/image:tag>");
Msg.out(" udocker export -o <tar> <container>");
Msg.out(" udocker export - <container>");
Msg.out(" udocker load -i <exported-image>");
Msg.out(" udocker load");
Msg.out(" udocker save -o <imagefile> <repo/image:tag>");
Msg.out(" udocker inspect [-p|-c] <repo/image:tag|container>");
Msg.out(" udocker verify <repo/image:tag>");
Msg.out(" udocker manifest inspect <repo/image:tag>");
Msg.out(" udocker ps [regexp]");
Msg.out(" udocker images [-l] [-p] [--all] [--no-trunc]");
Msg.out(" udocker rm <container-id|name>");
Msg.out(" udocker rmi <repo/image:tag>");
Msg.out(" udocker rename <container-id|name> <new-name>");
Msg.out(" udocker help");
Msg.out("");
Msg.out("Commands:");
Msg.out(" pull Download image layers and metadata");
Msg.out(" Options: --platform, --registry, --index, --pull, -q, --quiet");
Msg.out(" build Build container from Dockerfile");
Msg.out(" Options: -t, --tag, -f, --file, --build-arg, -y, -n");
Msg.out(" import Import tar file (docker export) into an image");
Msg.out(" export Export container directory tree to tar");
Msg.out(" load Load image from file or stdin (docker save format)");
Msg.out(" save Save image with layers to file (docker save format)");
Msg.out(" inspect Print image or container metadata");
Msg.out(" verify Verify a pulled image");
Msg.out(" manifest Print manifest metadata");
Msg.out(" create Create a container from a pulled image");
Msg.out(" Options: --name, --force");
Msg.out(" run Run a container through the proot runtime");
Msg.out(" Options: -p, -v/-b, -e/--env, -w, --rm, --name, --entrypoint, --isolated, --proot");
Msg.out(" images List local images");
Msg.out(" Options: -l, -p, --all, --no-trunc");
Msg.out(" ps List local containers");
Msg.out(" rm Remove a local container by id or name");
Msg.out(" rmi Remove a local image by repository and tag");
Msg.out(" rename Rename a local container");
Msg.out("");
Msg.out("Examples:");
Msg.out(" udocker pull alpine");
Msg.out(" udocker pull --platform=linux/arm64 alpine:latest");
Msg.out(" udocker build -t my_container .");
Msg.out(" udocker build -t my_container -f Dockerfile .");
Msg.out(" udocker create --name=myap alpine");
Msg.out(" udocker images -p");
Msg.out(" udocker ps [regexp]");
Msg.out(" udocker rename myap myapp");
Msg.out(" udocker rm myapp");
Msg.out(" udocker rmi alpine:latest");
}
function parseArgs(argv) {
const opts = {};
const positional = [];
const appendOpt = (k, v) => {
if (k === "build-arg") {
if (opts[k] === undefined) {
opts[k] = [v];
} else {
opts[k].push(v);
}
return;
}
opts[k] = v;
};
for (let i = 0; i < argv.length; i += 1) {
const arg = argv[i];
if (arg === "-") {
positional.push(arg);
continue;
}
if (arg.startsWith("--")) {
const eqIdx = arg.indexOf("=");
if (eqIdx !== -1) {
const k = arg.slice(2, eqIdx);
const v = arg.slice(eqIdx + 1);
appendOpt(k, v);
} else {
const k = arg.slice(2);
const next = argv[i + 1];
if (next && !next.startsWith("-")) {
appendOpt(k, next);
i += 1;
} else {
appendOpt(k, true);
}
}
} else if (arg.startsWith("-")) {
const short = arg.slice(1);
if ((short === "o" || short === "i" || short === "t" || short === "f") && argv[i + 1] && !argv[i + 1].startsWith("-")) {
appendOpt(short, argv[i + 1]);
i += 1;
} else {
appendOpt(short, true);
}
} else {
positional.push(arg);
}
}
return { opts, positional };
}
function checkImageSpec(dockerApi, imagespec) {
if (!imagespec) return [null, null];
let imagerepo = "";
let tag = "";
if (imagespec.includes("@")) {
[imagerepo, tag] = imagespec.split("@", 2);
} else if (imagespec.includes(":")) {
[imagerepo, tag] = imagespec.split(":", 2);
} else {
imagerepo = imagespec;
tag = "latest";
}
if (!imagerepo || !tag) return [null, null];
if (!(dockerApi.is_repo_name(imagespec) || dockerApi.is_layer_name(imagespec))) return [null, null];
return [imagerepo, tag];
}
function normalizePullPolicy(value) {
if (!value || value === true) return "missing";
const v = String(value).toLowerCase();
if (v === "reuse") return "missing";
if (v === "missing" || v === "always" || v === "never") return v;
return "";
}
async function main() {
const argv = process.argv.slice(2);
if (argv.length === 0) {
usage();
process.exitCode = 1;
return;
}
const cmd = argv[0];
if (cmd === "help" || cmd === "--help" || cmd === "-h") {
usage();
process.exitCode = 0;
return;
}
if (cmd === "run") {
const modPath = pathToFileURL(path.join(__dirname, "lib", "run.mjs")).href;
const runMod = await import(modPath);
process.exitCode = await runMod.runMain(argv.slice(1));
return;
}
const { opts, positional } = parseArgs(argv.slice(1));
if (opts.q || opts.quiet) {
Msg.level = Msg.ERR;
}
const localrepo = new LocalRepository();
localrepo.createRepo();
const dockerApi = new DockerApi(localrepo);
const localfile = new LocalFileApi(localrepo);
if (cmd === "pull") {
const imagespec = positional[0];
const [imagerepo, tag] = checkImageSpec(dockerApi, imagespec);
if (!imagerepo) {
Msg.err("Error: must specify image:tag or repository/image:tag");
process.exitCode = 1;
return;
}
if (opts.registry) {
const reg = String(opts.registry);
dockerApi.set_registry(reg.includes("://") ? reg : `https://${reg}`);
}
if (opts.index) {
const idx = String(opts.index);
dockerApi.set_index(idx.includes("://") ? idx : `https://${idx}`);
}
const platform = opts.platform || "";
const pullPolicy = normalizePullPolicy(opts.pull);
if (!pullPolicy) {
Msg.err("Error: invalid --pull policy (missing|always|never)");
process.exitCode = 1;
return;
}
const files = await dockerApi.get(imagerepo, tag, platform, pullPolicy);
if (!files || files.length === 0) {
Msg.err("Error: no files downloaded");
process.exitCode = 1;
return;
}
process.exitCode = 0;
return;
}
if (cmd === "build") {
const imageTag = opts.t || opts.tag||"null";
if (!imageTag || imageTag === true) {
Msg.err("Error: build requires -t/--tag <container_name>");
process.exitCode = 1;
return;
}
/*
const [imagerepo, tag] = checkImageSpec(dockerApi, String(imageTag));
if (!imagerepo) {
Msg.err("Error: invalid --tag image:tag");
process.exitCode = 1;
return;
}
*/
const contextDir = path.resolve(String(positional[0] || "."));
if (!fs.existsSync(contextDir) || !fs.statSync(contextDir).isDirectory()) {
Msg.err("Error: build context is not a directory");
process.exitCode = 1;
return;
}
let dockerfile = opts.f || opts.file || "Dockerfile";
if (dockerfile === true) {
Msg.err("Error: must specify Dockerfile path for -f/--file");
process.exitCode = 1;
return;
}
dockerfile = String(dockerfile);
const dockerfilePath = path.isAbsolute(dockerfile) ? dockerfile : path.join(contextDir, dockerfile);
if (!fs.existsSync(dockerfilePath)) {
Msg.err(`Error: Dockerfile not found: ${dockerfilePath}`);
process.exitCode = 1;
return;
}
const buildArgValues = Array.isArray(opts["build-arg"]) ? opts["build-arg"] : [];
const buildArgs = [];
for (const val of buildArgValues) {
if (val === true || !String(val).includes("=")) {
Msg.err("Error: --build-arg must be KEY=VALUE");
process.exitCode = 1;
return;
}
buildArgs.push(String(val));
}
const mode = opts.n ? "n" : (opts.y ? "y" : "i");
const modPath = pathToFileURL(path.join(__dirname, "lib", "build.mjs")).href;
const buildMod = await import(modPath);
const oldCwd = process.cwd();
process.chdir(contextDir);
try {
if (typeof buildMod.buildDockerfile === "function") {
await buildMod.buildDockerfile({
tag: `${imageTag}`,
mode,
filepath: dockerfilePath,
buildArgs,
});
} else {
if (typeof buildMod.initBuild === "function") {
buildMod.initBuild({
tag: `${imageTag}`,
mode,
buildArgs,
});
}
await buildMod.parseDockerfile(dockerfilePath);
}
} finally {
if (typeof buildMod.closeBuildSession === "function") {
buildMod.closeBuildSession();
}
process.chdir(oldCwd);
}
process.exitCode = process.exitCode || 0;
return;
}
if (cmd === "create") {
const imagespec = positional[0];
const name = opts.name || "";
const force = Boolean(opts.force);
const [imagerepo, tag] = checkImageSpec(dockerApi, imagespec);
if (!imagerepo) {
Msg.err("Error: must specify image:tag or repository/image:tag");
process.exitCode = 1;
return;
}
if (!force && name && localrepo.get_container_id(name)) {
Msg.err("Error: container name already exists");
process.exitCode = 1;
return;
}
const containerId = new ContainerStructure(localrepo).create_fromimage(imagerepo, tag);
if (!containerId) {
process.exitCode = 1;
return;
}
Msg.out(containerId);
if (name) {
const ok = localrepo.set_container_name(containerId, name);
if (!ok && !force) {
Msg.err("Error: invalid container name or wrong format");
process.exitCode = 1;
return;
}
}
process.exitCode = 0;
return;
}
if (cmd === "import") {
const tarfile = positional[0];
const imagespec = positional[1];
if (!tarfile || !imagespec) {
Msg.err("Error: must specify tar file and image:tag");
process.exitCode = 1;
return;
}
const [imagerepo, tag] = checkImageSpec(dockerApi, imagespec);
if (!imagerepo) {
Msg.err("Error: must specify image:tag or repository/image:tag");
process.exitCode = 1;
return;
}
const platform = opts.platform || "";
const ok = localfile.importToImage(tarfile, imagerepo, tag, platform);
if (!ok) {
Msg.err("Error: importing");
process.exitCode = 1;
return;
}
process.exitCode = 0;
return;
}
if (cmd === "export") {
const toFile = Boolean(opts.o);
let tarfile = toFile ? String(opts.o) : "-";
let containerName = toFile ? positional[0] : positional[0];
if (!toFile && positional[0] === "-") {
tarfile = "-";
containerName = positional[1];
}
if (!containerName) {
Msg.err("Error: must specify container id or name");
process.exitCode = 1;
return;
}
if (toFile && (tarfile === "true" || !tarfile)) {
Msg.err("Error: must specify output tar file");
process.exitCode = 1;
return;
}
const containerId = localrepo.get_container_id(containerName);
if (!containerId) {
Msg.err("Error: invalid container id or name");
process.exitCode = 1;
return;
}
const containerDir = localrepo.cd_container(containerId);
if (!containerDir) {
Msg.err("Error: container not found");
process.exitCode = 1;
return;
}
if (!tarfile) {
Msg.err("Error: invalid output file name");
process.exitCode = 1;
return;
}
const ok = localfile.exportContainer(containerDir, tarfile);
if (!ok) {
Msg.err("Error: exporting");
process.exitCode = 1;
return;
}
process.exitCode = 0;
return;
}
if (cmd === "load") {
let imagefile = opts.i || opts.input || "-";
if (imagefile === true) imagefile = "-";
if (positional[0] === "-" || opts["-"]) imagefile = "-";
const imagerepo = positional[0] && positional[0] !== "-" ? positional[0] : "";
const repos = localfile.load(imagefile, imagerepo);
if (!repos || repos.length === 0) {
Msg.err("Error: load failed");
process.exitCode = 1;
return;
}
for (const repo of repos) Msg.out(repo);
process.exitCode = 0;
return;
}
if (cmd === "save") {
const imagefile = opts.o || opts.output || "-";
const imagespec = positional[0];
if (imagefile === true) {
Msg.err("Error: must specify output file for -o/--output");
process.exitCode = 1;
return;
}
if (!imagespec) {
Msg.err("Error: must specify image:tag");
process.exitCode = 1;
return;
}
const [imagerepo, tag] = checkImageSpec(dockerApi, imagespec);
if (!imagerepo) {
Msg.err("Error: must specify image:tag or repository/image:tag");
process.exitCode = 1;
return;
}
const ok = localfile.save([[imagerepo, tag]], imagefile);
if (!ok) {
Msg.err("Error: save failed");
process.exitCode = 1;
return;
}
process.exitCode = 0;
return;
}
if (cmd === "inspect") {
const target = positional[0];
const printDir = Boolean(opts.p);
if (!target) {
Msg.err("Error: must specify container id or image:tag");
process.exitCode = 1;
return;
}
const containerId = localrepo.get_container_id(target);
if (containerId) {
const containerDir = localrepo.cd_container(containerId);
if (printDir) {
Msg.out(path.join(containerDir, "ROOT"));
process.exitCode = 0;
return;
}
const jsonPath = path.join(containerDir, "container.json");
if (fs.existsSync(jsonPath)) {
let jsonct=(fs.readFileSync(jsonPath, "utf8"));
let jsonobj = {} ;
try{
jsonobj=JSON.parse(jsonct);
}catch(e){ jsonobj={}; }
if(jsonobj.config)
{
if(opts.c)
console.log(jsonobj.config);
else
console.log(jsonobj);
}
else
{
Msg.Out(jsonct);
}
process.exitCode = 0;
return;
}
Msg.err("Error: container metadata not found");
process.exitCode = 1;
return;
}
const [imagerepo, tag] = checkImageSpec(dockerApi, target);
if (!imagerepo || !localrepo.cd_imagerepo(imagerepo, tag)) {
Msg.err("Error: image not found", imagerepo || target);
process.exitCode = 1;
return;
}
const [containerJson] = localrepo.get_image_attributes();
if (!containerJson) {
Msg.err("Error: image metadata not found");
process.exitCode = 1;
return;
}
Msg.out(JSON.stringify(containerJson, null, 2));
process.exitCode = 0;
return;
}
if (cmd === "verify") {
const imagespec = positional[0];
const [imagerepo, tag] = checkImageSpec(dockerApi, imagespec);
if (!imagerepo) {
Msg.err("Error: must specify image:tag or repository/image:tag");
process.exitCode = 1;
return;
}
Msg.out(`Info: verifying: ${imagerepo}:${tag}`, { l: Msg.INF });
if (!localrepo.cd_imagerepo(imagerepo, tag)) {
Msg.err("Error: selecting image and tag");
process.exitCode = 1;
return;
}
if (localrepo.verify_image()) {
Msg.out("Info: image Ok", { l: Msg.INF });
process.exitCode = 0;
return;
}
Msg.err("Error: image verification failure");
process.exitCode = 1;
return;
}
if (cmd === "manifest") {
const sub = positional[0];
const imagespec = positional[1];
if (sub !== "inspect") {
Msg.err("Error: manifest subcommand must be inspect");
process.exitCode = 1;
return;
}
const [imagerepo, tag] = checkImageSpec(dockerApi, imagespec);
if (!imagerepo) {
Msg.err("Error: must specify image:tag or repository/image:tag");
process.exitCode = 1;
return;
}
if (opts.registry) {
const reg = String(opts.registry);
dockerApi.set_registry(reg.includes("://") ? reg : `https://${reg}`);
}
if (opts.index) {
const idx = String(opts.index);
dockerApi.set_index(idx.includes("://") ? idx : `https://${idx}`);
}
const platform = opts.platform || "";
const { remoterepo } = dockerApi._parse_imagerepo(imagerepo);
const { manifest } = await dockerApi.get_v2_image_manifest(remoterepo, tag, platform);
if (!manifest) {
Msg.err("Error: manifest not found");
process.exitCode = 1;
return;
}
Msg.out(JSON.stringify(manifest, null, 2));
process.exitCode = 0;
return;
}
if (cmd === "ps") {
const pattern = positional[0] ? String(positional[0]) : "";
let regex = null;
if (pattern) {
try {
regex = new RegExp(pattern);
} catch {
Msg.err("Error: invalid regexp");
process.exitCode = 1;
return;
}
}
let list = localrepo.get_containers_list(false).map(([id, image, names]) => ({
id: String(id || ""),
image: String(image || ""),
names: String(names || ""),
}));
if (regex) {
list = list.filter(({ id, image, names }) => (
regex.test(names) || regex.test(image) || regex.test(id)
));
}
list.sort((a, b) => {
const nameCmp = a.names.localeCompare(b.names, undefined, { sensitivity: "base" });
if (nameCmp !== 0) return nameCmp;
const imageCmp = a.image.localeCompare(b.image, undefined, { sensitivity: "base" });
if (imageCmp !== 0) return imageCmp;
return a.id.localeCompare(b.id, undefined, { sensitivity: "base" });
});
const header = ["CONTAINER ID".padEnd(36), "NAMES".padEnd(20), "IMAGE"];
Msg.out(header.join(" "));
for (const { id, image, names } of list) {
const row = [(id || "-").padEnd(36), (names || "-").padEnd(20), image || "-"];
Msg.out(row.join(" "));
}
process.exitCode = 0;
return;
}
if (cmd === "images") {
const verbose = Boolean(opts.l);
const printPlatform = Boolean(opts.p);
opts["no-trunc"]; // accepted for compatibility
opts.all; // accepted for compatibility
const imagesList = localrepo.get_imagerepos();
Msg.out("REPOSITORY");
for (const [imagerepo, tag] of imagesList) {
const prot = localrepo.isprotected_imagerepo(imagerepo, tag) ? "P" : ".";
const imagerepoDir = localrepo.cd_imagerepo(imagerepo, tag);
if (printPlatform) {
const platform = localrepo.get_image_platform_fmt();
Msg.out(`${String(platform).padEnd(18).slice(0, 18)} ${prot} ${imagerepo}:${tag}`);
} else {
Msg.out(`${imagerepo}:${tag} ${prot}`);
}
if (verbose) {
Msg.out(` ${imagerepoDir}`);
const layersList = localrepo.get_layers(imagerepo, tag);
for (const [layerName, size] of layersList) {
let fileSizeMb = Math.floor(Number(size || 0) / (1024 * 1024));
if (!fileSizeMb && size) fileSizeMb = 1;
Msg.out(` ${layerName.replace(imagerepoDir, "")} (${fileSizeMb} MB)`);
}
}
}
process.exitCode = 0;
return;
}
if (cmd === "rm") {
const target = positional[0];
if (!target) {
Msg.err("Error: must specify container id or name");
process.exitCode = 1;
return;
}
const containerId = localrepo.get_container_id(target);
if (!containerId) {
Msg.err("Error: container id or name not found");
process.exitCode = 1;
return;
}
const ok = localrepo.del_container(containerId, false);
if (!ok) {
Msg.err("Error: removing container");
process.exitCode = 1;
return;
}
process.exitCode = 0;
return;
}
if (cmd === "rmi") {
const imagespec = positional[0];
const [imagerepo, tag] = checkImageSpec(dockerApi, imagespec);
if (!imagerepo) {
Msg.err("Error: must specify image:tag or repository/image:tag");
process.exitCode = 1;
return;
}
if (!localrepo.cd_imagerepo(imagerepo, tag)) {
Msg.err("Error: image not found");
process.exitCode = 1;
return;
}
const ok = localrepo.del_imagerepo(imagerepo, tag, false);
if (!ok) {
Msg.err("Error: removing image");
process.exitCode = 1;
return;
}
process.exitCode = 0;
return;
}
if (cmd === "rename") {
const name = positional[0];
const newName = positional[1];
if (!name || !newName) {
Msg.err("Error: invalid container id or name");
process.exitCode = 1;
return;
}
const containerId = localrepo.get_container_id(name);
if (!containerId) {
Msg.err("Error: container does not exist");
process.exitCode = 1;
return;
}
if (localrepo.get_container_id(newName)) {
Msg.err("Error: new name already exists");
process.exitCode = 1;
return;
}
localrepo.del_container_name(name);
if (!localrepo.set_container_name(containerId, newName)) {
Msg.err("Error: setting new name");
localrepo.set_container_name(containerId, name);
process.exitCode = 1;
return;
}
process.exitCode = 0;
return;
}
usage();
process.exitCode = 1;
}
main().catch((err) => {
Msg.err(String(err?.stack || err));
process.exitCode = 1;
});