From 74091874d777efa8e69addd83a63614b5dc89d35 Mon Sep 17 00:00:00 2001 From: Nulo Date: Fri, 23 Jun 2023 16:19:14 -0300 Subject: [PATCH] mejorar uso de podman --- index.js | 36 ++++++++++++++++++++++-------------- pnpm-lock.yaml | 6 +++++- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 15a9579..233580e 100644 --- a/index.js +++ b/index.js @@ -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))) + ); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7e4ca0b..d0d95f7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,8 @@ -lockfileVersion: '6.0' +lockfileVersion: '6.1' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false devDependencies: '@tsconfig/node16':