mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 16:46:43 +00:00
Merge branch 'main' into nikola-jokic/computed-build-directory
This commit is contained in:
@@ -196,6 +196,18 @@ export async function containerNetworkRemove(network: string): Promise<void> {
|
|||||||
await runDockerCommand(dockerArgs)
|
await runDockerCommand(dockerArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function containerNetworkPrune(): Promise<void> {
|
||||||
|
const dockerArgs = [
|
||||||
|
'network',
|
||||||
|
'prune',
|
||||||
|
'--force',
|
||||||
|
'--filter',
|
||||||
|
`label=${getRunnerLabel()}`
|
||||||
|
]
|
||||||
|
|
||||||
|
await runDockerCommand(dockerArgs)
|
||||||
|
}
|
||||||
|
|
||||||
export async function containerPrune(): Promise<void> {
|
export async function containerPrune(): Promise<void> {
|
||||||
const dockerPSArgs: string[] = [
|
const dockerPSArgs: string[] = [
|
||||||
'ps',
|
'ps',
|
||||||
|
|||||||
@@ -1,21 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
containerRemove,
|
containerNetworkPrune,
|
||||||
containerNetworkRemove
|
containerPrune
|
||||||
} from '../dockerCommands/container'
|
} from '../dockerCommands/container'
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
export async function cleanupJob(): Promise<void> {
|
||||||
export async function cleanupJob(args, state, responseFile): Promise<void> {
|
await containerPrune()
|
||||||
const containerIds: string[] = []
|
await containerNetworkPrune()
|
||||||
if (state?.container) {
|
|
||||||
containerIds.push(state.container)
|
|
||||||
}
|
|
||||||
if (state?.services) {
|
|
||||||
containerIds.push(state.services)
|
|
||||||
}
|
|
||||||
if (containerIds.length > 0) {
|
|
||||||
await containerRemove(containerIds)
|
|
||||||
}
|
|
||||||
if (state.network) {
|
|
||||||
await containerNetworkRemove(state.network)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ async function run(): Promise<void> {
|
|||||||
await prepareJob(args as PrepareJobArgs, responseFile)
|
await prepareJob(args as PrepareJobArgs, responseFile)
|
||||||
return exit(0)
|
return exit(0)
|
||||||
case Command.CleanupJob:
|
case Command.CleanupJob:
|
||||||
await cleanupJob(null, state, null)
|
await cleanupJob()
|
||||||
return exit(0)
|
return exit(0)
|
||||||
case Command.RunScriptStep:
|
case Command.RunScriptStep:
|
||||||
await runScriptStep(args as RunScriptStepArgs, state)
|
await runScriptStep(args as RunScriptStepArgs, state)
|
||||||
|
|||||||
@@ -46,13 +46,6 @@ describe('cleanup job', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should cleanup successfully', async () => {
|
it('should cleanup successfully', async () => {
|
||||||
const prepareJobOutputContent = fs.readFileSync(
|
await expect(cleanupJob()).resolves.not.toThrow()
|
||||||
prepareJobOutputPath,
|
|
||||||
'utf-8'
|
|
||||||
)
|
|
||||||
const parsedPrepareJobOutput = JSON.parse(prepareJobOutputContent)
|
|
||||||
await expect(
|
|
||||||
cleanupJob(prepareJobDefinition.args, parsedPrepareJobOutput.state, null)
|
|
||||||
).resolves.not.toThrow()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ describe('e2e', () => {
|
|||||||
await expect(
|
await expect(
|
||||||
runContainerStep(runContainerStepDefinition.args, resp.state)
|
runContainerStep(runContainerStepDefinition.args, resp.state)
|
||||||
).resolves.not.toThrow()
|
).resolves.not.toThrow()
|
||||||
await expect(cleanupJob(resp, resp.state, null)).resolves.not.toThrow()
|
await expect(cleanupJob()).resolves.not.toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should prepare job, then run script step, then run container step with Dockerfile then cleanup', async () => {
|
it('should prepare job, then run script step, then run container step with Dockerfile then cleanup', async () => {
|
||||||
@@ -111,6 +111,6 @@ ENTRYPOINT [ "tail", "-f", "/dev/null" ]
|
|||||||
await expect(
|
await expect(
|
||||||
runContainerStep(containerStepDataCopy.args, resp.state)
|
runContainerStep(containerStepDataCopy.args, resp.state)
|
||||||
).resolves.not.toThrow()
|
).resolves.not.toThrow()
|
||||||
await expect(cleanupJob(resp, resp.state, null)).resolves.not.toThrow()
|
await expect(cleanupJob()).resolves.not.toThrow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user