Skip to content

Commit

Permalink
feat: add isolated environments
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Nov 1, 2023
1 parent f18033b commit 4316af4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
12 changes: 10 additions & 2 deletions bot.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
},
"environments": {
"default": {
"warmup": 4,
"timeout": 3000,
"warmup": 3,
"timeout": 4000,
"isolated": false,
"path": "docker/runner-default",
"overrides": ["meta.json_reporter.binary_files = true"]
},
"isolated": {
"warmup": 2,
"timeout": 30000,
"isolated": true,
"path": "docker/runner-default",
"overrides": ["meta.json_reporter.binary_files = true"]
}
Expand Down
12 changes: 9 additions & 3 deletions infra/cloud-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ write_files:
"default": {
"warmup": 3,
"timeout": 4000,
"isolated": false,
"path": "https://github.com/mcbeet/beet-bot.git#main:docker/runner-default",
"overrides": [
"meta.json_reporter.binary_files = true"
]
"overrides": ["meta.json_reporter.binary_files = true"]
},
"isolated": {
"warmup": 2,
"timeout": 30000,
"isolated": true,
"path": "https://github.com/mcbeet/beet-bot.git#main:docker/runner-default",
"overrides": ["meta.json_reporter.binary_files = true"]
}
}
}
4 changes: 2 additions & 2 deletions packages/runner/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export const createBuilder = ({ warmup, timeout, setup }: BuilderOptions): Build

return new Promise<WorkerInfo>((resolve, reject) => {
handle.on('spawn', () => {
console.log(`INFO: Successfully spawned worker #${handle.pid}`)
console.log(`INFO: Successfully spawned idle worker #${handle.pid}`)
resolve({ handle, stop })
})

handle.on('error', (err) => {
console.log('WARN: Failed to spawn worker')
console.log('WARN: Failed to spawn idle worker')
reject(err)
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/runner/src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const deleteDockerBuilder = async (name: string) => {
}
}

export const setupDockerBuilder = async (name: string, path: string, overrides: string[] = []) => {
export const setupDockerBuilder = async (name: string, path: string, isolated: boolean, overrides: string[] = []) => {
const tag = getDockerImageTag(name)

try {
Expand All @@ -30,7 +30,7 @@ export const setupDockerBuilder = async (name: string, path: string, overrides:
const container = `${tag}-${id}`

const handle = execa('docker', [
'run', '--name', container, '--rm', '-i', tag,
'run', '--name', container, ...(isolated ? ['--network', 'none'] : []), '--rm', '-i', tag,
'beet', '-p', '@beet/preset_stdin.yml', ...overrides.flatMap(override => ['-s', override]), 'build', '--json'
])

Expand Down
6 changes: 4 additions & 2 deletions packages/runner/src/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type PoolRunner = {
export type EnvironmentOptions = {
warmup: number
timeout: number
isolated: boolean
path: string
overrides?: string[]
}
Expand All @@ -17,15 +18,15 @@ export const createPoolRunner = (environments: Record<string, EnvironmentOptions
const builders = new Map<string, Builder>()

for (const name in environments) {
const { warmup, timeout, path, overrides } = environments[name]
const { warmup, timeout, isolated, path, overrides } = environments[name]
builders.set(name, createBuilder({
warmup,
timeout,
setup: async (refresh: boolean) => {
if (refresh) {
await deleteDockerBuilder(name)
}
return await setupDockerBuilder(name, path, overrides)
return await setupDockerBuilder(name, path, isolated, overrides)
}
}))
}
Expand All @@ -44,6 +45,7 @@ export const createPoolRunner = (environments: Record<string, EnvironmentOptions
const builder = builders.get(name)

if (builder) {
console.log(`INFO: Trigger build in "${name}" environment`)
return await builder.build(options)
} else {
throw new Error(`Invalid environment "${name}"`)
Expand Down

0 comments on commit 4316af4

Please sign in to comment.