mejorar uso de podman

This commit is contained in:
Cat /dev/Nulo 2023-06-23 16:19:14 -03:00
parent d10ed631da
commit 74091874d7
2 changed files with 27 additions and 15 deletions

View file

@ -1,4 +1,4 @@
import { execFile as _execFile } from "node:child_process";
import { execFile as _execFile, spawn } from "node:child_process";
import { mkdir, readFile, stat, symlink, writeFile } from "node:fs/promises";
import { homedir } from "node:os";
import { join } from "node:path";
@ -52,6 +52,7 @@ apk add --initdb --root /rootfs alpine-base
};
}
const IS_DEV = process.env.NODE_ENV === "development";
/**
* Run script inside an Alpine 3.18 container with `root` mounted in /rootfs
* @param {string} root
@ -60,17 +61,24 @@ apk add --initdb --root /rootfs alpine-base
async function runInContainer(root, script) {
const cacheDir = join(homedir(), ".cache/apkit");
await mkdir(cacheDir, { recursive: true });
await execFile("podman", [
"run",
"-i",
"--rm",
"-v",
`${root}:/rootfs:Z`,
"-v",
`${cacheDir}:/var/cache/apk:Z`,
"docker.io/alpine:3.18",
"sh",
"-ec",
script,
]);
const proc = spawn(
"podman",
[
"run",
"-i",
"--rm",
"-v",
`${root}:/rootfs:Z`,
"-v",
`${cacheDir}:/var/cache/apk:Z`,
"docker.io/alpine:3.18",
"sh",
"-ec",
script,
],
{ stdio: IS_DEV ? "inherit" : "pipe" }
);
await new Promise((resolve, reject) =>
proc.on("exit", (code) => (code === 0 ? resolve(void 0) : reject(code)))
);
}

View file

@ -1,4 +1,8 @@
lockfileVersion: '6.0'
lockfileVersion: '6.1'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
devDependencies:
'@tsconfig/node16':