podman 0.1.6 → 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 CHANGED
@@ -14,8 +14,11 @@ npm i podman
14
14
  ```ts
15
15
  import * as podman from 'podman'
16
16
 
17
- await podman.startMachine() // podman-machine-default
18
- await podman.startMachine('your-machine-name')
17
+ await podman.forceStartMachine() // podman-machine-default
18
+ await podman.forceStartMachine('your-machine-name')
19
+
20
+ const machines = await podman.listMachines()
21
+ console.log(machines.map((machine) => machine.Name))
19
22
 
20
23
  const imageId = await podman.build({
21
24
  context: '.',
@@ -211,7 +211,8 @@ type PodmanBuildOptions = {
211
211
  /**
212
212
  * Builds a container image using podman build.
213
213
  *
214
- * Use [`startMachine`]{@link startMachine} first when running against a Podman VM.
214
+ * Use [`forceStartMachine`]{@link forceStartMachine} (or [`isMachineRunning`]{@link isMachineRunning} + [`startMachine`]{@link startMachine})
215
+ * first when running against a Podman VM.
215
216
  *
216
217
  * @param options Build options for podman build.
217
218
  * @returns Resolves with the built image ID (sha256 hash).
@@ -226,9 +227,9 @@ type PodmanBuildOptions = {
226
227
  *
227
228
  * @example
228
229
  * ```ts
229
- * import {startMachine, build} from 'podman'
230
+ * import {forceStartMachine, build} from 'podman'
230
231
  *
231
- * await startMachine()
232
+ * await forceStartMachine()
232
233
  * const imageId = await build({file: './Containerfile', tag: 'my-app:dev'})
233
234
  * console.log(imageId)
234
235
  * ```
@@ -1,17 +1,79 @@
1
+ type PodmanMachine = {
2
+ Name: string;
3
+ Default: boolean;
4
+ Created: string;
5
+ Running: boolean;
6
+ Starting: boolean;
7
+ LastUp: string;
8
+ Stream: string;
9
+ VMType: string;
10
+ CPUs: number;
11
+ Memory: string;
12
+ Swap: string;
13
+ DiskSize: string;
14
+ Port: number;
15
+ RemoteUsername: string;
16
+ IdentityPath: string;
17
+ UserModeNetworking: boolean;
18
+ };
1
19
  /**
2
- * Ensures the Podman machine is running.
20
+ * Lists Podman machines from `podman machine list --format json`.
21
+ *
22
+ * @returns Resolves with the list of machines.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import {listMachines} from 'podman'
27
+ *
28
+ * const machines = await listMachines()
29
+ * console.log(machines.map((machine) => machine.Name))
30
+ * ```
31
+ */
32
+ export declare function listMachines(): Promise<PodmanMachine[]>;
33
+ /**
34
+ * Checks whether a Podman machine is currently running.
35
+ *
36
+ * @param machineName Name of the Podman machine to inspect.
37
+ * @returns Resolves to true when the machine is running.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import {isMachineRunning} from 'podman'
42
+ *
43
+ * const running = await isMachineRunning()
44
+ * console.log('Machine running:', running)
45
+ * ```
46
+ */
47
+ export declare function isMachineRunning(machineName?: string): Promise<boolean>;
48
+ /**
49
+ * Starts a Podman machine.
3
50
  *
4
51
  * @param machineName Name of the Podman machine to start.
5
- * @returns Resolves to true when a machine start was triggered, or false if it is already running.
52
+ * @returns Resolves when the start command completes.
6
53
  *
7
54
  * @example
8
55
  * ```ts
9
56
  * import {startMachine} from 'podman'
10
57
  *
11
- * const started = await startMachine()
58
+ * await startMachine('podman-machine-default')
59
+ * ```
60
+ */
61
+ export declare function startMachine(machineName?: string): Promise<void>;
62
+ /**
63
+ * Starts a Podman machine, ignoring the "already running" error.
64
+ *
65
+ * @param machineName Name of the Podman machine to start.
66
+ * @returns Resolves to true when a start was triggered, or false when it was already running.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import {forceStartMachine} from 'podman'
71
+ *
72
+ * const started = await forceStartMachine()
12
73
  * if (started) {
13
74
  * console.log('Podman machine booted.')
14
75
  * }
15
76
  * ```
16
77
  */
17
- export declare function startMachine(machineName?: string): Promise<boolean>;
78
+ export declare function forceStartMachine(machineName?: string): Promise<boolean>;
79
+ export {};
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { run } from './commands/run';
2
2
  export { build } from './commands/build';
3
3
  export { push } from './commands/push';
4
4
  export { tag } from './commands/tag';
5
- export { startMachine } from './commands/start-machine.ts';
5
+ export { forceStartMachine, isMachineRunning, listMachines, startMachine } from './commands/start-machine.ts';
package/dist/index.js CHANGED
@@ -449,25 +449,50 @@ async function tag(image, targetNames) {
449
449
  return execPodmanStreaming(args.toArgs());
450
450
  }
451
451
  // src/commands/start-machine.ts
452
- async function startMachine(machineName = "podman-machine-default") {
452
+ async function listMachines() {
453
453
  const out = await execPodman(["machine", "list", "--format", "json"]);
454
- const machines = JSON.parse(out || "[]");
454
+ return JSON.parse(out || "[]");
455
+ }
456
+ async function isMachineRunning(machineName = "podman-machine-default") {
457
+ const machines = await listMachines();
455
458
  const m = machines.find((x) => x.Name === machineName);
456
459
  if (!m) {
457
460
  throw new Error(`Podman machine "${machineName}" not found in list:
458
461
  ${machines.map((x) => `- ${x.Name}`).join(`
459
462
  `)}`);
460
463
  }
461
- if (m.Running) {
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") {
462
482
  return false;
463
483
  }
464
- await execPodman(["machine", "start", machineName]);
465
- return true;
484
+ const candidate = err;
485
+ const combined = [candidate.stderr, candidate.stdout, candidate.message].filter(Boolean).join(`
486
+ `);
487
+ return combined.toLowerCase().includes("already running");
466
488
  }
467
489
  export {
468
490
  tag,
469
491
  startMachine,
470
492
  run,
471
493
  push,
494
+ listMachines,
495
+ isMachineRunning,
496
+ forceStartMachine,
472
497
  build
473
498
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podman",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "description": "Utilities for starting a Podman machine from Bun/Node.",
5
5
  "author": "Mark Penner <npm@mpen.ca>",
6
6
  "module": "index.ts",