Skip to content

Commit

Permalink
Merge pull request #112 from depot/cni
Browse files Browse the repository at this point in the history
Only write CNI file if it doesn't exist
  • Loading branch information
jacobwgillespie authored May 21, 2024
2 parents a9e943e + 58dcb2a commit ba3d707
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/tasks/buildkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {execa} from 'execa'
import * as fsp from 'fs/promises'
import {onShutdown, onShutdownError} from 'node-graceful-shutdown'
import {RegisterMachineResponse, RegisterMachineResponse_BuildKitTask} from '../gen/ts/depot/cloud/v3/machine_pb'
import {pathExists} from '../utils/common'
import {ensureMounted, fstrim, mountExecutor, unmapBlockDevice, unmountDevice} from '../utils/mounts'
import {reportHealth} from './health'
import {reportUsage} from './usage'
Expand Down Expand Up @@ -102,7 +103,7 @@ keepBytes = ${cacheSizeBytes}
`
await fsp.writeFile('/etc/buildkit/buildkitd.toml', config, {mode: 0o644})

if (task.enableCni) {
if (task.enableCni && !(await pathExists('/etc/buildkit/cni.json'))) {
const cniConfig = {
cniVersion: '1.0.0',
name: 'buildkit',
Expand Down
11 changes: 11 additions & 0 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as fsp from 'node:fs/promises'

export async function promises<T extends Record<string, any>>(promises: T): Promise<{[K in keyof T]: Awaited<T[K]>}> {
const entries = Object.entries(promises)
const values = await Promise.all(
Expand All @@ -11,3 +13,12 @@ export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve
export function assertNever(x: never): never {
throw new Error('Unexpected value: ' + x)
}

export async function pathExists(path: string) {
try {
await fsp.access(path)
return true
} catch {
return false
}
}

0 comments on commit ba3d707

Please sign in to comment.