Skip to content

Commit d0728da

Browse files
Merge pull request #118 from depot/dynamic-root-path
Allow the API to specify the root dir path
2 parents a7d4b05 + 469bb49 commit d0728da

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/tasks/buildkit.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,22 @@ export async function startBuildKit(message: RegisterMachineResponse, task: Regi
2727
} catch {}
2828
}
2929

30+
let rootDir = '/var/lib/buildkit'
31+
3032
let useCeph = false
3133
for (const mount of task.mounts) {
34+
rootDir = mount.path
3235
await ensureMounted(mount.device, mount.path, mount.fsType, mount.cephVolume, mount.options)
3336
if (mount.cephVolume) useCeph = true
3437
}
3538

3639
if (!useCeph) {
37-
await mountExecutor()
40+
await mountExecutor(rootDir)
3841
}
3942

4043
// Attempt to delete old snapshotter data
4144
try {
42-
execa('rm', ['-rf', '/var/lib/buildkit/runc-overlayfs'], {stdio: 'inherit'}).catch((err) => {
45+
execa('rm', ['-rf', `${rootDir}/runc-overlayfs`], {stdio: 'inherit'}).catch((err) => {
4346
console.error(err)
4447
})
4548
} catch {}
@@ -55,7 +58,7 @@ export async function startBuildKit(message: RegisterMachineResponse, task: Regi
5558
const maxParallelism = task.maxParallelism > 0 ? task.maxParallelism : 12
5659

5760
const config = `
58-
root = "/var/lib/buildkit"
61+
root = "${rootDir}"
5962
6063
[grpc]
6164
address = ["tcp://0.0.0.0:443", "unix:///run/buildkit/buildkitd.sock"]
@@ -230,7 +233,7 @@ keepBytes = ${cacheSizeBytes}
230233
}
231234

232235
// Remove estargz cache because we will rely on the buildkit layer cache instead.
233-
await execa('rm', ['-rf', '/var/lib/buildkit/runc-stargz/snapshots/stargz'], {stdio: 'inherit'}).catch((err) => {
236+
await execa('rm', ['-rf', `${rootDir}/runc-stargz/snapshots/stargz`], {stdio: 'inherit'}).catch((err) => {
234237
console.error(err)
235238
})
236239

src/utils/mounts.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,17 @@ export async function unmountDevice(path: string, seenPaths = new Set<string>())
166166
}
167167

168168
// Bind-mounts the BuildKit executor directory to the ephemeral disk.
169-
export async function mountExecutor() {
169+
export async function mountExecutor(rootDir: string) {
170170
const mounts = await fsp.readFile('/proc/mounts', 'utf8')
171-
if (mounts.includes('/var/lib/buildkit/runc-stargz/executor')) {
171+
if (mounts.includes(`${rootDir}/runc-stargz/executor`)) {
172172
console.log(`Executor dir is already mounted`)
173173
return
174174
}
175175

176176
await execa('mkdir', ['-p', '/mnt/executor'], {stdio: 'inherit'})
177-
await execa('rm', ['-rf', '/var/lib/buildkit/runc-stargz/executor'], {stdio: 'inherit'})
178-
await execa('mkdir', ['-p', '/var/lib/buildkit/runc-stargz/executor'], {stdio: 'inherit'})
179-
await execa('mount', ['--bind', '/mnt/executor', '/var/lib/buildkit/runc-stargz/executor'], {stdio: 'inherit'})
177+
await execa('rm', ['-rf', `${rootDir}/runc-stargz/executor`], {stdio: 'inherit'})
178+
await execa('mkdir', ['-p', `${rootDir}/runc-stargz/executor`], {stdio: 'inherit'})
179+
await execa('mount', ['--bind', '/mnt/executor', `${rootDir}/runc-stargz/executor`], {stdio: 'inherit'})
180180
}
181181

182182
async function waitForDevice(device: string) {

0 commit comments

Comments
 (0)