diff --git a/src/tasks/buildkit.ts b/src/tasks/buildkit.ts index 5640d43..c09e2e7 100644 --- a/src/tasks/buildkit.ts +++ b/src/tasks/buildkit.ts @@ -27,19 +27,22 @@ export async function startBuildKit(message: RegisterMachineResponse, task: Regi } catch {} } + let rootDir = '/var/lib/buildkit' + let useCeph = false for (const mount of task.mounts) { + rootDir = mount.path await ensureMounted(mount.device, mount.path, mount.fsType, mount.cephVolume, mount.options) if (mount.cephVolume) useCeph = true } if (!useCeph) { - await mountExecutor() + await mountExecutor(rootDir) } // Attempt to delete old snapshotter data try { - execa('rm', ['-rf', '/var/lib/buildkit/runc-overlayfs'], {stdio: 'inherit'}).catch((err) => { + execa('rm', ['-rf', `${rootDir}/runc-overlayfs`], {stdio: 'inherit'}).catch((err) => { console.error(err) }) } catch {} @@ -55,7 +58,7 @@ export async function startBuildKit(message: RegisterMachineResponse, task: Regi const maxParallelism = task.maxParallelism > 0 ? task.maxParallelism : 12 const config = ` -root = "/var/lib/buildkit" +root = "${rootDir}" [grpc] address = ["tcp://0.0.0.0:443", "unix:///run/buildkit/buildkitd.sock"] @@ -230,7 +233,7 @@ keepBytes = ${cacheSizeBytes} } // Remove estargz cache because we will rely on the buildkit layer cache instead. - await execa('rm', ['-rf', '/var/lib/buildkit/runc-stargz/snapshots/stargz'], {stdio: 'inherit'}).catch((err) => { + await execa('rm', ['-rf', `${rootDir}/runc-stargz/snapshots/stargz`], {stdio: 'inherit'}).catch((err) => { console.error(err) }) diff --git a/src/utils/mounts.ts b/src/utils/mounts.ts index 5d37fd1..b94d75c 100644 --- a/src/utils/mounts.ts +++ b/src/utils/mounts.ts @@ -166,17 +166,17 @@ export async function unmountDevice(path: string, seenPaths = new Set()) } // Bind-mounts the BuildKit executor directory to the ephemeral disk. -export async function mountExecutor() { +export async function mountExecutor(rootDir: string) { const mounts = await fsp.readFile('/proc/mounts', 'utf8') - if (mounts.includes('/var/lib/buildkit/runc-stargz/executor')) { + if (mounts.includes(`${rootDir}/runc-stargz/executor`)) { console.log(`Executor dir is already mounted`) return } await execa('mkdir', ['-p', '/mnt/executor'], {stdio: 'inherit'}) - await execa('rm', ['-rf', '/var/lib/buildkit/runc-stargz/executor'], {stdio: 'inherit'}) - await execa('mkdir', ['-p', '/var/lib/buildkit/runc-stargz/executor'], {stdio: 'inherit'}) - await execa('mount', ['--bind', '/mnt/executor', '/var/lib/buildkit/runc-stargz/executor'], {stdio: 'inherit'}) + await execa('rm', ['-rf', `${rootDir}/runc-stargz/executor`], {stdio: 'inherit'}) + await execa('mkdir', ['-p', `${rootDir}/runc-stargz/executor`], {stdio: 'inherit'}) + await execa('mount', ['--bind', '/mnt/executor', `${rootDir}/runc-stargz/executor`], {stdio: 'inherit'}) } async function waitForDevice(device: string) {