Skip to content

Commit de59bd8

Browse files
authored
Merge pull request actions#12 from actions/nikola-jokic/allow-no-job-container
Repaired prepare-job hook without job container
2 parents 347e68d + d3ec1c0 commit de59bd8

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

packages/docker/src/dockerCommands/container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export async function containerBuild(
149149
dockerArgs.push('-t', tag)
150150
dockerArgs.push('-f', args.dockerfile)
151151
dockerArgs.push(getBuildContext(args.dockerfile))
152-
// TODO: figure out build working directory
152+
153153
await runDockerCommand(dockerArgs, {
154154
workingDir: getWorkingDir(args.dockerfile)
155155
})

packages/docker/src/hooks/prepare-job.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ export async function prepareJob(
9494
)
9595
}
9696

97-
const isAlpine = await isContainerAlpine(containerMetadata!.id)
97+
let isAlpine = false
98+
if (containerMetadata?.id) {
99+
isAlpine = await isContainerAlpine(containerMetadata.id)
100+
}
98101

99102
if (containerMetadata?.id) {
100103
containerMetadata.ports = await containerPorts(containerMetadata.id)
@@ -105,7 +108,10 @@ export async function prepareJob(
105108
}
106109
}
107110

108-
const healthChecks: Promise<void>[] = [healthCheck(containerMetadata!)]
111+
const healthChecks: Promise<void>[] = []
112+
if (containerMetadata) {
113+
healthChecks.push(healthCheck(containerMetadata))
114+
}
109115
for (const service of servicesMetadata) {
110116
healthChecks.push(healthCheck(service))
111117
}
@@ -133,7 +139,6 @@ function generateResponseFile(
133139
servicesMetadata?: ContainerMetadata[],
134140
isAlpine = false
135141
): void {
136-
// todo figure out if we are alpine
137142
const response = {
138143
state: { network: networkName },
139144
context: {},

packages/docker/tests/prepare-job-test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,14 @@ describe('prepare job', () => {
118118
expect(redisServicePorts['80']).toBe('8080')
119119
expect(redisServicePorts['8080']).toBe('8088')
120120
})
121+
122+
it('should run prepare job without job container without exception', async () => {
123+
prepareJobDefinition.args.container = null
124+
const prepareJobOutput = testSetup.createOutputFile(
125+
'prepare-job-output.json'
126+
)
127+
await expect(
128+
prepareJob(prepareJobDefinition.args, prepareJobOutput)
129+
).resolves.not.toThrow()
130+
})
121131
})

packages/k8s/src/hooks/prepare-job.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import * as core from '@actions/core'
22
import * as io from '@actions/io'
33
import * as k8s from '@kubernetes/client-node'
4-
import {
5-
PodPhase,
6-
containerVolumes,
7-
DEFAULT_CONTAINER_ENTRY_POINT,
8-
DEFAULT_CONTAINER_ENTRY_POINT_ARGS
9-
} from '../k8s/utils'
104
import { ContextPorts, prepareJobArgs, writeToResponseFile } from 'hooklib'
115
import path from 'path'
126
import {
@@ -19,12 +13,22 @@ import {
1913
requiredPermissions,
2014
waitForPodPhases
2115
} from '../k8s'
16+
import {
17+
containerVolumes,
18+
DEFAULT_CONTAINER_ENTRY_POINT,
19+
DEFAULT_CONTAINER_ENTRY_POINT_ARGS,
20+
PodPhase
21+
} from '../k8s/utils'
2222
import { JOB_CONTAINER_NAME } from './constants'
2323

2424
export async function prepareJob(
2525
args: prepareJobArgs,
2626
responseFile
2727
): Promise<void> {
28+
if (!args.container) {
29+
throw new Error('Job Container is required.')
30+
}
31+
2832
await prunePods()
2933
if (!(await isAuthPermissionsOK())) {
3034
throw new Error(

packages/k8s/tests/prepare-job-test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,11 @@ describe('Prepare job', () => {
6868
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
6969
).rejects.toThrow()
7070
})
71+
72+
it('should not run prepare job without the job container', async () => {
73+
prepareJobData.args.container = undefined
74+
await expect(
75+
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
76+
).rejects.toThrow()
77+
})
7178
})

0 commit comments

Comments
 (0)