Merge pull request #12 from actions/nikola-jokic/allow-no-job-container

Repaired prepare-job hook without job container
This commit is contained in:
Thomas Boop
2022-06-10 13:34:52 -04:00
committed by GitHub
5 changed files with 36 additions and 10 deletions

View File

@@ -149,7 +149,7 @@ export async function containerBuild(
dockerArgs.push('-t', tag)
dockerArgs.push('-f', args.dockerfile)
dockerArgs.push(getBuildContext(args.dockerfile))
// TODO: figure out build working directory
await runDockerCommand(dockerArgs, {
workingDir: getWorkingDir(args.dockerfile)
})

View File

@@ -94,7 +94,10 @@ export async function prepareJob(
)
}
const isAlpine = await isContainerAlpine(containerMetadata!.id)
let isAlpine = false
if (containerMetadata?.id) {
isAlpine = await isContainerAlpine(containerMetadata.id)
}
if (containerMetadata?.id) {
containerMetadata.ports = await containerPorts(containerMetadata.id)
@@ -105,7 +108,10 @@ export async function prepareJob(
}
}
const healthChecks: Promise<void>[] = [healthCheck(containerMetadata!)]
const healthChecks: Promise<void>[] = []
if (containerMetadata) {
healthChecks.push(healthCheck(containerMetadata))
}
for (const service of servicesMetadata) {
healthChecks.push(healthCheck(service))
}
@@ -133,7 +139,6 @@ function generateResponseFile(
servicesMetadata?: ContainerMetadata[],
isAlpine = false
): void {
// todo figure out if we are alpine
const response = {
state: { network: networkName },
context: {},

View File

@@ -118,4 +118,14 @@ describe('prepare job', () => {
expect(redisServicePorts['80']).toBe('8080')
expect(redisServicePorts['8080']).toBe('8088')
})
it('should run prepare job without job container without exception', async () => {
prepareJobDefinition.args.container = null
const prepareJobOutput = testSetup.createOutputFile(
'prepare-job-output.json'
)
await expect(
prepareJob(prepareJobDefinition.args, prepareJobOutput)
).resolves.not.toThrow()
})
})

View File

@@ -1,12 +1,6 @@
import * as core from '@actions/core'
import * as io from '@actions/io'
import * as k8s from '@kubernetes/client-node'
import {
PodPhase,
containerVolumes,
DEFAULT_CONTAINER_ENTRY_POINT,
DEFAULT_CONTAINER_ENTRY_POINT_ARGS
} from '../k8s/utils'
import { ContextPorts, prepareJobArgs, writeToResponseFile } from 'hooklib'
import path from 'path'
import {
@@ -19,12 +13,22 @@ import {
requiredPermissions,
waitForPodPhases
} from '../k8s'
import {
containerVolumes,
DEFAULT_CONTAINER_ENTRY_POINT,
DEFAULT_CONTAINER_ENTRY_POINT_ARGS,
PodPhase
} from '../k8s/utils'
import { JOB_CONTAINER_NAME } from './constants'
export async function prepareJob(
args: prepareJobArgs,
responseFile
): Promise<void> {
if (!args.container) {
throw new Error('Job Container is required.')
}
await prunePods()
if (!(await isAuthPermissionsOK())) {
throw new Error(

View File

@@ -68,4 +68,11 @@ describe('Prepare job', () => {
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
).rejects.toThrow()
})
it('should not run prepare job without the job container', async () => {
prepareJobData.args.container = undefined
await expect(
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
).rejects.toThrow()
})
})