podman 0.1.5 → 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/README.md +8 -5
- package/dist/commands/build.d.ts +238 -0
- package/dist/commands/push.d.ts +45 -0
- package/dist/commands/run.d.ts +322 -0
- package/dist/commands/start-machine.d.ts +79 -0
- package/dist/commands/tag.d.ts +29 -0
- package/dist/index.d.ts +5 -732
- package/dist/index.js +207 -170
- package/dist/lib/spawn.d.ts +122 -0
- package/package.json +1 -1
- /package/dist/{arg-builder.d.ts → lib/arg-builder.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// src/
|
|
3
|
-
import { execFile, spawn } from "child_process";
|
|
4
|
-
import { createInterface } from "readline";
|
|
5
|
-
import { promisify } from "util";
|
|
6
|
-
|
|
7
|
-
// src/arg-builder.ts
|
|
2
|
+
// src/lib/arg-builder.ts
|
|
8
3
|
class ArgBuilder {
|
|
9
4
|
args;
|
|
10
5
|
constructor(command) {
|
|
@@ -42,7 +37,13 @@ class ArgBuilder {
|
|
|
42
37
|
}
|
|
43
38
|
}
|
|
44
39
|
|
|
45
|
-
// src/
|
|
40
|
+
// src/commands/run.ts
|
|
41
|
+
import { spawn as spawn2 } from "child_process";
|
|
42
|
+
|
|
43
|
+
// src/lib/spawn.ts
|
|
44
|
+
import { promisify } from "util";
|
|
45
|
+
import { execFile, spawn } from "child_process";
|
|
46
|
+
import { createInterface } from "readline";
|
|
46
47
|
var execFileAsync = promisify(execFile);
|
|
47
48
|
async function execPodman(args) {
|
|
48
49
|
const { stdout } = await execFileAsync("podman", args);
|
|
@@ -85,13 +86,6 @@ async function execPodmanStreamingWithStdoutLines(args, onLine) {
|
|
|
85
86
|
});
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
|
-
var ProcessOutput;
|
|
89
|
-
((ProcessOutput2) => {
|
|
90
|
-
ProcessOutput2["Pipe"] = "pipe";
|
|
91
|
-
ProcessOutput2["Ignore"] = "ignore";
|
|
92
|
-
ProcessOutput2["Inherit"] = "inherit";
|
|
93
|
-
ProcessOutput2["Tee"] = "tee";
|
|
94
|
-
})(ProcessOutput ||= {});
|
|
95
89
|
function resolveProcessOutput(mode) {
|
|
96
90
|
switch (mode) {
|
|
97
91
|
case "pipe" /* Pipe */:
|
|
@@ -105,159 +99,8 @@ function resolveProcessOutput(mode) {
|
|
|
105
99
|
return { stdio: "inherit", tee: false };
|
|
106
100
|
}
|
|
107
101
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const machines = JSON.parse(out || "[]");
|
|
111
|
-
const m = machines.find((x) => x.Name === machineName);
|
|
112
|
-
if (!m) {
|
|
113
|
-
throw new Error(`Podman machine "${machineName}" not found in list:
|
|
114
|
-
${machines.map((x) => `- ${x.Name}`).join(`
|
|
115
|
-
`)}`);
|
|
116
|
-
}
|
|
117
|
-
if (m.Running) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
await execPodman(["machine", "start", machineName]);
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
async function build(options = {}) {
|
|
124
|
-
const args = new ArgBuilder("build");
|
|
125
|
-
args.addValues("--add-host", options.addHost);
|
|
126
|
-
args.addBool("--all-platforms", options.allPlatforms);
|
|
127
|
-
args.addValues("--annotation", options.annotation);
|
|
128
|
-
args.addValue("--arch", options.arch);
|
|
129
|
-
args.addValue("--authfile", options.authfile);
|
|
130
|
-
args.addValues("--build-arg", options.buildArg);
|
|
131
|
-
args.addValue("--build-arg-file", options.buildArgFile);
|
|
132
|
-
args.addValues("--build-context", options.buildContext);
|
|
133
|
-
args.addValues("--cache-from", options.cacheFrom);
|
|
134
|
-
args.addValues("--cache-to", options.cacheTo);
|
|
135
|
-
args.addValue("--cache-ttl", options.cacheTtl);
|
|
136
|
-
args.addValues("--cap-add", options.capAdd);
|
|
137
|
-
args.addValues("--cap-drop", options.capDrop);
|
|
138
|
-
args.addValue("--cert-dir", options.certDir);
|
|
139
|
-
args.addValue("--cgroup-parent", options.cgroupParent);
|
|
140
|
-
args.addValue("--cgroupns", options.cgroupns);
|
|
141
|
-
args.addBool("--compat-volumes", options.compatVolumes);
|
|
142
|
-
args.addValues("--cpp-flag", options.cppFlag);
|
|
143
|
-
args.addValue("--cpu-period", options.cpuPeriod);
|
|
144
|
-
args.addValue("--cpu-quota", options.cpuQuota);
|
|
145
|
-
args.addValue("--cpu-shares", options.cpuShares);
|
|
146
|
-
args.addValue("--cpuset-cpus", options.cpusetCpus);
|
|
147
|
-
args.addValue("--cpuset-mems", options.cpusetMems);
|
|
148
|
-
args.addBool("--created-annotation", options.createdAnnotation);
|
|
149
|
-
args.addValue("--creds", options.creds);
|
|
150
|
-
args.addValues("--decryption-key", options.decryptionKey);
|
|
151
|
-
args.addValues("--device", options.device);
|
|
152
|
-
args.addBool("--disable-compression", options.disableCompression);
|
|
153
|
-
args.addValue("--dns", options.dns);
|
|
154
|
-
args.addValues("--dns-option", options.dnsOption);
|
|
155
|
-
args.addValues("--dns-search", options.dnsSearch);
|
|
156
|
-
args.addValues("--env", options.env);
|
|
157
|
-
args.addValue("--file", options.file);
|
|
158
|
-
args.addBool("--force-rm", options.forceRm);
|
|
159
|
-
args.addValue("--format", options.format);
|
|
160
|
-
args.addValue("--from", options.from);
|
|
161
|
-
args.addValues("--group-add", options.groupAdd);
|
|
162
|
-
args.addValues("--hooks-dir", options.hooksDir);
|
|
163
|
-
args.addBool("--http-proxy", options.httpProxy);
|
|
164
|
-
args.addBool("--identity-label", options.identityLabel);
|
|
165
|
-
args.addValue("--ignorefile", options.ignorefile);
|
|
166
|
-
args.addValue("--iidfile", options.iidfile);
|
|
167
|
-
args.addBool("--inherit-annotations", options.inheritAnnotations);
|
|
168
|
-
args.addBool("--inherit-labels", options.inheritLabels);
|
|
169
|
-
args.addValue("--ipc", options.ipc);
|
|
170
|
-
args.addValue("--isolation", options.isolation);
|
|
171
|
-
args.addValue("--jobs", options.jobs);
|
|
172
|
-
args.addValues("--label", options.label);
|
|
173
|
-
args.addValues("--layer-label", options.layerLabel);
|
|
174
|
-
args.addBool("--layers", options.layers);
|
|
175
|
-
args.addValue("--logfile", options.logfile);
|
|
176
|
-
args.addValue("--manifest", options.manifest);
|
|
177
|
-
args.addValue("--memory", options.memory);
|
|
178
|
-
args.addValue("--memory-swap", options.memorySwap);
|
|
179
|
-
args.addValue("--network", options.network);
|
|
180
|
-
args.addBool("--no-cache", options.noCache);
|
|
181
|
-
args.addBool("--no-hostname", options.noHostname);
|
|
182
|
-
args.addBool("--no-hosts", options.noHosts);
|
|
183
|
-
args.addBool("--omit-history", options.omitHistory);
|
|
184
|
-
args.addValue("--os", options.os);
|
|
185
|
-
args.addValue("--os-feature", options.osFeature);
|
|
186
|
-
args.addValue("--os-version", options.osVersion);
|
|
187
|
-
args.addValue("--pid", options.pid);
|
|
188
|
-
args.addValue("--platform", options.platform);
|
|
189
|
-
args.addValue("--pull", options.pull);
|
|
190
|
-
args.addBool("--quiet", options.quiet);
|
|
191
|
-
args.addValue("--retry", options.retry);
|
|
192
|
-
args.addValue("--retry-delay", options.retryDelay);
|
|
193
|
-
args.addBool("--rewrite-timestamp", options.rewriteTimestamp);
|
|
194
|
-
args.addBool("--rm", options.rm);
|
|
195
|
-
args.addValues("--runtime-flag", options.runtimeFlag);
|
|
196
|
-
args.addValue("--sbom", options.sbom);
|
|
197
|
-
args.addValue("--sbom-image-output", options.sbomImageOutput);
|
|
198
|
-
args.addValue("--sbom-image-purl-output", options.sbomImagePurlOutput);
|
|
199
|
-
args.addValue("--sbom-merge-strategy", options.sbomMergeStrategy);
|
|
200
|
-
args.addValue("--sbom-output", options.sbomOutput);
|
|
201
|
-
args.addValue("--sbom-purl-output", options.sbomPurlOutput);
|
|
202
|
-
args.addValue("--sbom-scanner-command", options.sbomScannerCommand);
|
|
203
|
-
args.addValue("--sbom-scanner-image", options.sbomScannerImage);
|
|
204
|
-
args.addValues("--secret", options.secret);
|
|
205
|
-
args.addValues("--security-opt", options.securityOpt);
|
|
206
|
-
args.addValue("--shm-size", options.shmSize);
|
|
207
|
-
args.addBool("--skip-unused-stages", options.skipUnusedStages);
|
|
208
|
-
args.addValue("--source-date-epoch", options.sourceDateEpoch);
|
|
209
|
-
args.addBool("--squash", options.squash);
|
|
210
|
-
args.addBool("--squash-all", options.squashAll);
|
|
211
|
-
args.addValues("--ssh", options.ssh);
|
|
212
|
-
args.addBool("--stdin", options.stdin);
|
|
213
|
-
args.addValues("--tag", options.tag);
|
|
214
|
-
args.addValue("--target", options.target);
|
|
215
|
-
args.addValue("--timestamp", options.timestamp);
|
|
216
|
-
args.addValues("--ulimit", options.ulimit);
|
|
217
|
-
args.addValues("--unsetannotation", options.unsetannotation);
|
|
218
|
-
args.addValues("--unsetenv", options.unsetenv);
|
|
219
|
-
args.addValues("--unsetlabel", options.unsetlabel);
|
|
220
|
-
args.addValue("--userns", options.userns);
|
|
221
|
-
args.addValue("--userns-gid-map", options.usernsGidMap);
|
|
222
|
-
args.addValue("--userns-gid-map-group", options.usernsGidMapGroup);
|
|
223
|
-
args.addValue("--userns-uid-map", options.usernsUidMap);
|
|
224
|
-
args.addValue("--userns-uid-map-user", options.usernsUidMapUser);
|
|
225
|
-
args.addValue("--uts", options.uts);
|
|
226
|
-
args.addValue("--variant", options.variant);
|
|
227
|
-
args.addValues("--volume", options.volume);
|
|
228
|
-
args.add(options.context ?? ".");
|
|
229
|
-
let imageId;
|
|
230
|
-
await execPodmanStreamingWithStdoutLines(args.toArgs(), (line) => {
|
|
231
|
-
const trimmed = line.trim();
|
|
232
|
-
if (/^[a-f0-9]{64}$/.test(trimmed)) {
|
|
233
|
-
imageId = trimmed;
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
if (!imageId) {
|
|
237
|
-
throw new Error("Unable to determine built image ID from podman output.");
|
|
238
|
-
}
|
|
239
|
-
return imageId;
|
|
240
|
-
}
|
|
241
|
-
async function push(options) {
|
|
242
|
-
const args = new ArgBuilder("push");
|
|
243
|
-
args.addValue("--authfile", options.authfile);
|
|
244
|
-
args.addValue("--compression-format", options.compressionFormat);
|
|
245
|
-
args.addValue("--compression-level", options.compressionLevel);
|
|
246
|
-
args.addValue("--creds", options.creds);
|
|
247
|
-
args.addValue("--digestfile", options.digestfile);
|
|
248
|
-
args.addBool("--disable-content-trust", options.disableContentTrust);
|
|
249
|
-
args.addBool("--force-compression", options.forceCompression);
|
|
250
|
-
args.addValue("--format", options.format);
|
|
251
|
-
args.addBool("--remove-signatures", options.removeSignatures);
|
|
252
|
-
args.addValue("--retry", options.retry);
|
|
253
|
-
args.addValue("--retry-delay", options.retryDelay);
|
|
254
|
-
args.addBool("--tls-verify", options.tlsVerify);
|
|
255
|
-
args.add(options.image);
|
|
256
|
-
if (options.destination) {
|
|
257
|
-
args.add(options.destination);
|
|
258
|
-
}
|
|
259
|
-
return execPodmanStreaming(args.toArgs());
|
|
260
|
-
}
|
|
102
|
+
|
|
103
|
+
// src/commands/run.ts
|
|
261
104
|
function run(options, processOptions = {}) {
|
|
262
105
|
const args = new ArgBuilder("run");
|
|
263
106
|
args.addValues("--add-host", options.addHost);
|
|
@@ -416,7 +259,7 @@ function run(options, processOptions = {}) {
|
|
|
416
259
|
}
|
|
417
260
|
const stdoutConfig = resolveProcessOutput(processOptions.stdout);
|
|
418
261
|
const stderrConfig = resolveProcessOutput(processOptions.stderr);
|
|
419
|
-
const child =
|
|
262
|
+
const child = spawn2("podman", args.toArgs(), {
|
|
420
263
|
stdio: ["inherit", stdoutConfig.stdio, stderrConfig.stdio]
|
|
421
264
|
});
|
|
422
265
|
const stdout = child.stdout ?? null;
|
|
@@ -452,10 +295,204 @@ function run(options, processOptions = {}) {
|
|
|
452
295
|
stderr
|
|
453
296
|
};
|
|
454
297
|
}
|
|
298
|
+
// src/commands/build.ts
|
|
299
|
+
async function build(options = {}) {
|
|
300
|
+
const args = new ArgBuilder("build");
|
|
301
|
+
args.addValues("--add-host", options.addHost);
|
|
302
|
+
args.addBool("--all-platforms", options.allPlatforms);
|
|
303
|
+
args.addValues("--annotation", options.annotation);
|
|
304
|
+
args.addValue("--arch", options.arch);
|
|
305
|
+
args.addValue("--authfile", options.authfile);
|
|
306
|
+
args.addValues("--build-arg", options.buildArg);
|
|
307
|
+
args.addValue("--build-arg-file", options.buildArgFile);
|
|
308
|
+
args.addValues("--build-context", options.buildContext);
|
|
309
|
+
args.addValues("--cache-from", options.cacheFrom);
|
|
310
|
+
args.addValues("--cache-to", options.cacheTo);
|
|
311
|
+
args.addValue("--cache-ttl", options.cacheTtl);
|
|
312
|
+
args.addValues("--cap-add", options.capAdd);
|
|
313
|
+
args.addValues("--cap-drop", options.capDrop);
|
|
314
|
+
args.addValue("--cert-dir", options.certDir);
|
|
315
|
+
args.addValue("--cgroup-parent", options.cgroupParent);
|
|
316
|
+
args.addValue("--cgroupns", options.cgroupns);
|
|
317
|
+
args.addBool("--compat-volumes", options.compatVolumes);
|
|
318
|
+
args.addValues("--cpp-flag", options.cppFlag);
|
|
319
|
+
args.addValue("--cpu-period", options.cpuPeriod);
|
|
320
|
+
args.addValue("--cpu-quota", options.cpuQuota);
|
|
321
|
+
args.addValue("--cpu-shares", options.cpuShares);
|
|
322
|
+
args.addValue("--cpuset-cpus", options.cpusetCpus);
|
|
323
|
+
args.addValue("--cpuset-mems", options.cpusetMems);
|
|
324
|
+
args.addBool("--created-annotation", options.createdAnnotation);
|
|
325
|
+
args.addValue("--creds", options.creds);
|
|
326
|
+
args.addValues("--decryption-key", options.decryptionKey);
|
|
327
|
+
args.addValues("--device", options.device);
|
|
328
|
+
args.addBool("--disable-compression", options.disableCompression);
|
|
329
|
+
args.addValue("--dns", options.dns);
|
|
330
|
+
args.addValues("--dns-option", options.dnsOption);
|
|
331
|
+
args.addValues("--dns-search", options.dnsSearch);
|
|
332
|
+
args.addValues("--env", options.env);
|
|
333
|
+
args.addValue("--file", options.file);
|
|
334
|
+
args.addBool("--force-rm", options.forceRm);
|
|
335
|
+
args.addValue("--format", options.format);
|
|
336
|
+
args.addValue("--from", options.from);
|
|
337
|
+
args.addValues("--group-add", options.groupAdd);
|
|
338
|
+
args.addValues("--hooks-dir", options.hooksDir);
|
|
339
|
+
args.addBool("--http-proxy", options.httpProxy);
|
|
340
|
+
args.addBool("--identity-label", options.identityLabel);
|
|
341
|
+
args.addValue("--ignorefile", options.ignorefile);
|
|
342
|
+
args.addValue("--iidfile", options.iidfile);
|
|
343
|
+
args.addBool("--inherit-annotations", options.inheritAnnotations);
|
|
344
|
+
args.addBool("--inherit-labels", options.inheritLabels);
|
|
345
|
+
args.addValue("--ipc", options.ipc);
|
|
346
|
+
args.addValue("--isolation", options.isolation);
|
|
347
|
+
args.addValue("--jobs", options.jobs);
|
|
348
|
+
args.addValues("--label", options.label);
|
|
349
|
+
args.addValues("--layer-label", options.layerLabel);
|
|
350
|
+
args.addBool("--layers", options.layers);
|
|
351
|
+
args.addValue("--logfile", options.logfile);
|
|
352
|
+
args.addValue("--manifest", options.manifest);
|
|
353
|
+
args.addValue("--memory", options.memory);
|
|
354
|
+
args.addValue("--memory-swap", options.memorySwap);
|
|
355
|
+
args.addValue("--network", options.network);
|
|
356
|
+
args.addBool("--no-cache", options.noCache);
|
|
357
|
+
args.addBool("--no-hostname", options.noHostname);
|
|
358
|
+
args.addBool("--no-hosts", options.noHosts);
|
|
359
|
+
args.addBool("--omit-history", options.omitHistory);
|
|
360
|
+
args.addValue("--os", options.os);
|
|
361
|
+
args.addValue("--os-feature", options.osFeature);
|
|
362
|
+
args.addValue("--os-version", options.osVersion);
|
|
363
|
+
args.addValue("--pid", options.pid);
|
|
364
|
+
args.addValue("--platform", options.platform);
|
|
365
|
+
args.addValue("--pull", options.pull);
|
|
366
|
+
args.addBool("--quiet", options.quiet);
|
|
367
|
+
args.addValue("--retry", options.retry);
|
|
368
|
+
args.addValue("--retry-delay", options.retryDelay);
|
|
369
|
+
args.addBool("--rewrite-timestamp", options.rewriteTimestamp);
|
|
370
|
+
args.addBool("--rm", options.rm);
|
|
371
|
+
args.addValues("--runtime-flag", options.runtimeFlag);
|
|
372
|
+
args.addValue("--sbom", options.sbom);
|
|
373
|
+
args.addValue("--sbom-image-output", options.sbomImageOutput);
|
|
374
|
+
args.addValue("--sbom-image-purl-output", options.sbomImagePurlOutput);
|
|
375
|
+
args.addValue("--sbom-merge-strategy", options.sbomMergeStrategy);
|
|
376
|
+
args.addValue("--sbom-output", options.sbomOutput);
|
|
377
|
+
args.addValue("--sbom-purl-output", options.sbomPurlOutput);
|
|
378
|
+
args.addValue("--sbom-scanner-command", options.sbomScannerCommand);
|
|
379
|
+
args.addValue("--sbom-scanner-image", options.sbomScannerImage);
|
|
380
|
+
args.addValues("--secret", options.secret);
|
|
381
|
+
args.addValues("--security-opt", options.securityOpt);
|
|
382
|
+
args.addValue("--shm-size", options.shmSize);
|
|
383
|
+
args.addBool("--skip-unused-stages", options.skipUnusedStages);
|
|
384
|
+
args.addValue("--source-date-epoch", options.sourceDateEpoch);
|
|
385
|
+
args.addBool("--squash", options.squash);
|
|
386
|
+
args.addBool("--squash-all", options.squashAll);
|
|
387
|
+
args.addValues("--ssh", options.ssh);
|
|
388
|
+
args.addBool("--stdin", options.stdin);
|
|
389
|
+
args.addValues("--tag", options.tag);
|
|
390
|
+
args.addValue("--target", options.target);
|
|
391
|
+
args.addValue("--timestamp", options.timestamp);
|
|
392
|
+
args.addValues("--ulimit", options.ulimit);
|
|
393
|
+
args.addValues("--unsetannotation", options.unsetannotation);
|
|
394
|
+
args.addValues("--unsetenv", options.unsetenv);
|
|
395
|
+
args.addValues("--unsetlabel", options.unsetlabel);
|
|
396
|
+
args.addValue("--userns", options.userns);
|
|
397
|
+
args.addValue("--userns-gid-map", options.usernsGidMap);
|
|
398
|
+
args.addValue("--userns-gid-map-group", options.usernsGidMapGroup);
|
|
399
|
+
args.addValue("--userns-uid-map", options.usernsUidMap);
|
|
400
|
+
args.addValue("--userns-uid-map-user", options.usernsUidMapUser);
|
|
401
|
+
args.addValue("--uts", options.uts);
|
|
402
|
+
args.addValue("--variant", options.variant);
|
|
403
|
+
args.addValues("--volume", options.volume);
|
|
404
|
+
args.add(options.context ?? ".");
|
|
405
|
+
let imageId;
|
|
406
|
+
await execPodmanStreamingWithStdoutLines(args.toArgs(), (line) => {
|
|
407
|
+
const trimmed = line.trim();
|
|
408
|
+
if (/^[a-f0-9]{64}$/.test(trimmed)) {
|
|
409
|
+
imageId = trimmed;
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
if (!imageId) {
|
|
413
|
+
throw new Error("Unable to determine built image ID from podman output.");
|
|
414
|
+
}
|
|
415
|
+
return imageId;
|
|
416
|
+
}
|
|
417
|
+
// src/commands/push.ts
|
|
418
|
+
async function push(options) {
|
|
419
|
+
const args = new ArgBuilder("push");
|
|
420
|
+
args.addValue("--authfile", options.authfile);
|
|
421
|
+
args.addValue("--compression-format", options.compressionFormat);
|
|
422
|
+
args.addValue("--compression-level", options.compressionLevel);
|
|
423
|
+
args.addValue("--creds", options.creds);
|
|
424
|
+
args.addValue("--digestfile", options.digestfile);
|
|
425
|
+
args.addBool("--disable-content-trust", options.disableContentTrust);
|
|
426
|
+
args.addBool("--force-compression", options.forceCompression);
|
|
427
|
+
args.addValue("--format", options.format);
|
|
428
|
+
args.addBool("--remove-signatures", options.removeSignatures);
|
|
429
|
+
args.addValue("--retry", options.retry);
|
|
430
|
+
args.addValue("--retry-delay", options.retryDelay);
|
|
431
|
+
args.addBool("--tls-verify", options.tlsVerify);
|
|
432
|
+
args.add(options.image);
|
|
433
|
+
if (options.destination) {
|
|
434
|
+
args.add(options.destination);
|
|
435
|
+
}
|
|
436
|
+
return execPodmanStreaming(args.toArgs());
|
|
437
|
+
}
|
|
438
|
+
// src/commands/tag.ts
|
|
439
|
+
async function tag(image, targetNames) {
|
|
440
|
+
const args = new ArgBuilder("tag");
|
|
441
|
+
const targets = Array.isArray(targetNames) ? targetNames : [targetNames];
|
|
442
|
+
if (targets.length === 0) {
|
|
443
|
+
throw new Error("podman tag requires at least one target name.");
|
|
444
|
+
}
|
|
445
|
+
args.add(image);
|
|
446
|
+
for (const target of targets) {
|
|
447
|
+
args.add(target);
|
|
448
|
+
}
|
|
449
|
+
return execPodmanStreaming(args.toArgs());
|
|
450
|
+
}
|
|
451
|
+
// src/commands/start-machine.ts
|
|
452
|
+
async function listMachines() {
|
|
453
|
+
const out = await execPodman(["machine", "list", "--format", "json"]);
|
|
454
|
+
return JSON.parse(out || "[]");
|
|
455
|
+
}
|
|
456
|
+
async function isMachineRunning(machineName = "podman-machine-default") {
|
|
457
|
+
const machines = await listMachines();
|
|
458
|
+
const m = machines.find((x) => x.Name === machineName);
|
|
459
|
+
if (!m) {
|
|
460
|
+
throw new Error(`Podman machine "${machineName}" not found in list:
|
|
461
|
+
${machines.map((x) => `- ${x.Name}`).join(`
|
|
462
|
+
`)}`);
|
|
463
|
+
}
|
|
464
|
+
return m.Running;
|
|
465
|
+
}
|
|
466
|
+
async function startMachine(machineName = "podman-machine-default") {
|
|
467
|
+
await execPodman(["machine", "start", machineName]);
|
|
468
|
+
}
|
|
469
|
+
async function forceStartMachine(machineName = "podman-machine-default") {
|
|
470
|
+
try {
|
|
471
|
+
await startMachine(machineName);
|
|
472
|
+
return true;
|
|
473
|
+
} catch (err) {
|
|
474
|
+
if (isAlreadyRunningError(err)) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
throw err;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
function isAlreadyRunningError(err) {
|
|
481
|
+
if (!err || typeof err !== "object") {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
const candidate = err;
|
|
485
|
+
const combined = [candidate.stderr, candidate.stdout, candidate.message].filter(Boolean).join(`
|
|
486
|
+
`);
|
|
487
|
+
return combined.toLowerCase().includes("already running");
|
|
488
|
+
}
|
|
455
489
|
export {
|
|
490
|
+
tag,
|
|
456
491
|
startMachine,
|
|
457
492
|
run,
|
|
458
493
|
push,
|
|
459
|
-
|
|
460
|
-
|
|
494
|
+
listMachines,
|
|
495
|
+
isMachineRunning,
|
|
496
|
+
forceStartMachine,
|
|
497
|
+
build
|
|
461
498
|
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
export declare function execPodman(args: string[]): Promise<string>;
|
|
3
|
+
export declare function execPodmanStreaming(args: string[]): Promise<void>;
|
|
4
|
+
export declare function execPodmanStreamingWithStdoutLines(args: string[], onLine: (line: string) => void): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Output handling strategy for spawned processes.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {ProcessOutput} from 'podman'
|
|
11
|
+
*
|
|
12
|
+
* const mode = ProcessOutput.Tee
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare enum ProcessOutput {
|
|
16
|
+
/** Capture output in a stream. */
|
|
17
|
+
Pipe = "pipe",
|
|
18
|
+
/** Discard output. */
|
|
19
|
+
Ignore = "ignore",
|
|
20
|
+
/** Forward output to the parent process. */
|
|
21
|
+
Inherit = "inherit",
|
|
22
|
+
/** Capture output and also forward it to the parent process. */
|
|
23
|
+
Tee = "tee"
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Process output configuration for podman run.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import {ProcessOutput} from 'podman'
|
|
31
|
+
*
|
|
32
|
+
* const options = {stdout: ProcessOutput.Tee, stderr: ProcessOutput.Pipe}
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export type ProcessOptions = {
|
|
36
|
+
/** How stdout is handled. Defaults to [`ProcessOutput.Inherit`]{@link ProcessOutput.Inherit}. */
|
|
37
|
+
stdout?: ProcessOutput;
|
|
38
|
+
/** How stderr is handled. Defaults to [`ProcessOutput.Inherit`]{@link ProcessOutput.Inherit}. */
|
|
39
|
+
stderr?: ProcessOutput;
|
|
40
|
+
};
|
|
41
|
+
export declare function resolveProcessOutput(mode: ProcessOutput | undefined): ProcessOutputConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Handle returned by [`run`]{@link run} to control the podman process.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import {run, ProcessOutput} from 'podman'
|
|
48
|
+
*
|
|
49
|
+
* const proc = run(
|
|
50
|
+
* {image: 'alpine:latest', command: 'echo', commandArgs: ['hello']},
|
|
51
|
+
* {stdout: ProcessOutput.Tee},
|
|
52
|
+
* )
|
|
53
|
+
* await proc.waitThrow()
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export type PodmanRunHandle = {
|
|
57
|
+
/**
|
|
58
|
+
* Sends SIGKILL to the podman process.
|
|
59
|
+
*
|
|
60
|
+
* @returns True if the signal was sent, false otherwise.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import {run} from 'podman'
|
|
65
|
+
*
|
|
66
|
+
* const proc = await run({image: 'alpine:latest', command: 'sleep', commandArgs: ['60']})
|
|
67
|
+
* proc.kill()
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
kill: () => boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Sends SIGTERM to the podman process.
|
|
73
|
+
*
|
|
74
|
+
* @returns True if the signal was sent, false otherwise.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import {run} from 'podman'
|
|
79
|
+
*
|
|
80
|
+
* const proc = await run({image: 'alpine:latest', command: 'sleep', commandArgs: ['60']})
|
|
81
|
+
* proc.term()
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
term: () => boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Waits for the podman process to exit.
|
|
87
|
+
*
|
|
88
|
+
* @returns Resolves with the exit code of the podman process.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import {run} from 'podman'
|
|
93
|
+
*
|
|
94
|
+
* const proc = await run({image: 'alpine:latest', command: 'true'})
|
|
95
|
+
* const code = await proc.wait()
|
|
96
|
+
* console.log(code)
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
wait: () => Promise<number>;
|
|
100
|
+
/**
|
|
101
|
+
* Waits for the podman process to exit and rejects on non-zero exit codes.
|
|
102
|
+
*
|
|
103
|
+
* @returns Resolves with the exit code when it is zero.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import {run} from 'podman'
|
|
108
|
+
*
|
|
109
|
+
* const proc = await run({image: 'alpine:latest', command: 'false'})
|
|
110
|
+
* await proc.waitThrow()
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
waitThrow: () => Promise<number>;
|
|
114
|
+
/** Stdout stream when configured with [`ProcessOutput.Pipe`]{@link ProcessOutput.Pipe} or [`ProcessOutput.Tee`]{@link ProcessOutput.Tee}. */
|
|
115
|
+
stdout: Readable | null;
|
|
116
|
+
/** Stderr stream when configured with [`ProcessOutput.Pipe`]{@link ProcessOutput.Pipe} or [`ProcessOutput.Tee`]{@link ProcessOutput.Tee}. */
|
|
117
|
+
stderr: Readable | null;
|
|
118
|
+
};
|
|
119
|
+
export type ProcessOutputConfig = {
|
|
120
|
+
stdio: 'pipe' | 'ignore' | 'inherit';
|
|
121
|
+
tee: boolean;
|
|
122
|
+
};
|
package/package.json
CHANGED
|
File without changes
|