podman 0.1.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 +15 -0
- package/index.ts +48 -0
- package/package.json +30 -0
package/README.md
ADDED
package/index.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {execFile} from 'node:child_process'
|
|
2
|
+
import {promisify} from 'node:util'
|
|
3
|
+
|
|
4
|
+
const execFileAsync = promisify(execFile)
|
|
5
|
+
|
|
6
|
+
type PodmanMachine = {
|
|
7
|
+
Name: string
|
|
8
|
+
Default: boolean
|
|
9
|
+
Created: string
|
|
10
|
+
Running: boolean
|
|
11
|
+
Starting: boolean
|
|
12
|
+
LastUp: string
|
|
13
|
+
Stream: string
|
|
14
|
+
VMType: string
|
|
15
|
+
CPUs: number
|
|
16
|
+
Memory: string
|
|
17
|
+
Swap: string
|
|
18
|
+
DiskSize: string
|
|
19
|
+
Port: number
|
|
20
|
+
RemoteUsername: string
|
|
21
|
+
IdentityPath: string
|
|
22
|
+
UserModeNetworking: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function execPodman(args: string[]): Promise<string> {
|
|
26
|
+
const {stdout} = await execFileAsync('podman', args)
|
|
27
|
+
return stdout
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Ensures the Podman machine is running.
|
|
32
|
+
*
|
|
33
|
+
* @param machineName Name of the Podman machine to start.
|
|
34
|
+
* @returns True when a machine start was triggered, false if it's already running.
|
|
35
|
+
*/
|
|
36
|
+
export async function startMachine(machineName = 'podman-machine-default'): Promise<boolean> {
|
|
37
|
+
const out = await execPodman(['machine', 'list', '--format', 'json'])
|
|
38
|
+
const machines = JSON.parse(out || '[]') as PodmanMachine[]
|
|
39
|
+
const m = machines.find((x) => x.Name === machineName)
|
|
40
|
+
if(!m) {
|
|
41
|
+
throw new Error(`Podman machine "${machineName}" not found in list:\n${machines.map((x) => `- ${x.Name}`).join('\n')}`)
|
|
42
|
+
}
|
|
43
|
+
if(m.Running) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
await execPodman(['machine', 'start', machineName])
|
|
47
|
+
return true
|
|
48
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "podman",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Utilities for starting a Podman machine from Bun/Node.",
|
|
5
|
+
"author": "Mark Penner <npm@mpen.ca>",
|
|
6
|
+
"module": "index.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.ts"
|
|
10
|
+
},
|
|
11
|
+
"types": "./index.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"index.ts",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18",
|
|
20
|
+
"bun": ">=1.0"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/mnpenner/docker-imagestree/master/podman"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"typescript": "^5"
|
|
29
|
+
}
|
|
30
|
+
}
|