Skip to content

Commit

Permalink
Allow the API to specify the root dir path
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie committed Aug 6, 2024
1 parent a7d4b05 commit 469bb49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/tasks/buildkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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"]
Expand Down Expand Up @@ -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)
})

Expand Down
10 changes: 5 additions & 5 deletions src/utils/mounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ export async function unmountDevice(path: string, seenPaths = new Set<string>())
}

// 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) {
Expand Down

0 comments on commit 469bb49

Please sign in to comment.