Files
runner-container-hooks/packages/k8s/src/hooks/run-script-step.ts
T

39 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-06-02 15:53:11 -04:00
/* eslint-disable @typescript-eslint/no-unused-vars */
import { RunScriptStepArgs } from 'hooklib'
import { execPodStep } from '../k8s'
2022-06-06 00:21:44 -04:00
import { getJobPodName, JOB_CONTAINER_NAME } from './constants'
2022-06-02 15:53:11 -04:00
export async function runScriptStep(
args: RunScriptStepArgs,
state,
responseFile
): Promise<void> {
const cb = new CommandsBuilder(
args.entryPoint,
args.entryPointArgs,
args.environmentVariables
)
2022-06-06 00:21:44 -04:00
await execPodStep(cb.command, getJobPodName(), JOB_CONTAINER_NAME)
2022-06-02 15:53:11 -04:00
}
class CommandsBuilder {
constructor(
private entryPoint: string,
private entryPointArgs: string[],
private environmentVariables: { [key: string]: string }
) {}
get command(): string[] {
const envCommands: string[] = []
if (
this.environmentVariables &&
Object.entries(this.environmentVariables).length
) {
for (const [key, value] of Object.entries(this.environmentVariables)) {
envCommands.push(`${key}=${value}`)
}
}
return ['env', ...envCommands, this.entryPoint, ...this.entryPointArgs]
}
}