Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
dependabot-action/src/container-service.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
63 lines (57 sloc)
1.57 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as core from '@actions/core' | |
import {Container} from 'dockerode' | |
import {pack} from 'tar-stream' | |
import {FileFetcherInput, FileUpdaterInput, ProxyConfig} from './config-types' | |
import {outStream, errStream} from './utils' | |
export class ContainerRuntimeError extends Error {} | |
export const ContainerService = { | |
async storeInput( | |
name: string, | |
path: string, | |
container: Container, | |
input: FileFetcherInput | FileUpdaterInput | ProxyConfig | |
): Promise<void> { | |
const tar = pack() | |
tar.entry({name}, JSON.stringify(input)) | |
tar.finalize() | |
await container.putArchive(tar, {path}) | |
}, | |
async storeCert( | |
name: string, | |
path: string, | |
container: Container, | |
cert: string | |
): Promise<void> { | |
const tar = pack() | |
tar.entry({name}, cert) | |
tar.finalize() | |
await container.putArchive(tar, {path}) | |
}, | |
async run(container: Container): Promise<boolean> { | |
try { | |
const stream = await container.attach({ | |
stream: true, | |
stdout: true, | |
stderr: true | |
}) | |
container.modem.demuxStream( | |
stream, | |
outStream('updater'), | |
errStream('updater') | |
) | |
await container.start() | |
const outcome = await container.wait() | |
if (outcome.StatusCode === 0) { | |
return true | |
} else { | |
core.info(`Failure running container ${container.id}`) | |
throw new ContainerRuntimeError( | |
'The updater encountered one or more errors.' | |
) | |
} | |
} finally { | |
await container.remove({v: true}) | |
core.info(`Cleaned up container ${container.id}`) | |
} | |
} | |
} |