Skip to content

Commit

Permalink
Merge pull request #114 from github/jurre/updater-container-name
Browse files Browse the repository at this point in the history
Give containers more descriptive names
  • Loading branch information
Jurre authored and GitHub committed Oct 6, 2021
2 parents 436b6b2 + 655585b commit 2338892
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
10 changes: 6 additions & 4 deletions __tests__/proxy-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,22 @@ describe('ProxyBuilder', () => {
const proxy = await builder.run(jobId, credentials)
await proxy.container.start()

expect(proxy.networkName).toBe('job-1-network')
expect(proxy.networkName).toBe('dependabot-job-1-network')
expect(proxy.url).toMatch(/^http:\/\/1:.+job-1-proxy:1080$/)

const containerInfo = await proxy.container.inspect()
expect(containerInfo.Name).toBe('/job-1-proxy')
expect(containerInfo.HostConfig.NetworkMode).toBe('job-1-network')
expect(containerInfo.Name).toBe('/dependabot-job-1-proxy')
expect(containerInfo.HostConfig.NetworkMode).toBe(
'dependabot-job-1-network'
)
expect(containerInfo.Config.Entrypoint).toEqual([
'sh',
'-c',
'/usr/sbin/update-ca-certificates && /update-job-proxy'
])

const networkInfo = await proxy.network.inspect()
expect(networkInfo.Name).toBe('job-1-network')
expect(networkInfo.Name).toBe('dependabot-job-1-network')
expect(networkInfo.Internal).toBe(false)

// run a bash command that executes docker and returns contents of /config.json
Expand Down
13 changes: 8 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ export class ProxyBuilder {
) {}

async run(jobId: number, credentials: Credential[]): Promise<Proxy> {
const name = `job-${jobId}-proxy`
const name = `dependabot-job-${jobId}-proxy`
const config = this.buildProxyConfig(credentials, jobId)
const cert = config.ca.cert

const networkName = `job-${jobId}-network`
const networkName = `dependabot-job-${jobId}-network`
const network = await this.ensureNetwork(networkName)

const container = await this.createContainer(jobId, name, networkName)
Expand Down
8 changes: 6 additions & 2 deletions src/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class Updater {
}

private async runFileFetcher(proxy: Proxy): Promise<FetchedFiles> {
const container = await this.createContainer(proxy, 'fetch_files')
const name = `dependabot-job-${this.apiClient.params.jobId}-file-fetcher`
const container = await this.createContainer(proxy, name, 'fetch_files')
await ContainerService.storeInput(
JOB_INPUT_FILENAME,
JOB_INPUT_PATH,
Expand Down Expand Up @@ -90,7 +91,8 @@ export class Updater {
files: FetchedFiles
): Promise<void> {
core.info(`Running update job ${this.apiClient.params.jobId}`)
const container = await this.createContainer(proxy, 'update_files')
const name = `dependabot-job-${this.apiClient.params.jobId}-updater`
const container = await this.createContainer(proxy, name, 'update_files')
const containerInput: FileUpdaterInput = {
base_commit_sha: files.base_commit_sha,
base64_dependency_files: files.base64_dependency_files,
Expand All @@ -115,6 +117,7 @@ export class Updater {

private async createContainer(
proxy: Proxy,
containerName: string,
updaterCommand: string
): Promise<Container> {
const cmd = `(echo > /etc/ca-certificates.conf) &&\
Expand All @@ -124,6 +127,7 @@ export class Updater {

const container = await this.docker.createContainer({
Image: this.updaterImage,
name: containerName,
AttachStdout: true,
AttachStderr: true,
Env: [
Expand Down

0 comments on commit 2338892

Please sign in to comment.