From d1bddfe3d7c959edee215f4d94bbdbd315602200 Mon Sep 17 00:00:00 2001 From: Nulo Date: Wed, 31 May 2023 11:17:19 -0300 Subject: [PATCH] cache --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 87dbf92..60526a1 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ import { execFile as _execFile } from "node:child_process"; -import { readFile, stat, symlink, writeFile } from "node:fs/promises"; +import { mkdir, readFile, stat, symlink, writeFile } from "node:fs/promises"; +import { homedir } from "node:os"; import { join } from "node:path"; import { promisify } from "node:util"; const execFile = promisify(_execFile); @@ -23,6 +24,7 @@ mkdir -p /rootfs/etc/apk cp -r /etc/apk/keys /rootfs/etc/apk/ echo https://dl-cdn.alpinelinux.org/alpine/v3.18/main >> /rootfs/etc/apk/repositories echo https://dl-cdn.alpinelinux.org/alpine/v3.18/community >> /rootfs/etc/apk/repositories +ln -s /var/cache/apk /rootfs/etc/apk/cache apk add --initdb --root /rootfs alpine-base ` ); @@ -53,12 +55,16 @@ apk add --initdb --root /rootfs alpine-base * @param {string} script */ async function runInContainer(root, script) { + const cacheDir = join(homedir(), ".cache/apkit"); + await mkdir(cacheDir, { recursive: true }); await execFile("podman", [ "run", - "-it", + "-i", "--rm", "-v", `${root}:/rootfs:Z`, + "-v", + `${cacheDir}:/var/cache/apk:Z`, "docker.io/alpine:3.18", "sh", "-ec",