Skip to content

Commit

Permalink
Merge pull request #112 from github/jurre/proxy-job-id
Browse files Browse the repository at this point in the history
Pass job-id directly to proxy
  • Loading branch information
Jurre authored and GitHub committed Oct 5, 2021
2 parents 7b7ff2c + c54c6a7 commit 33b0097
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
16 changes: 4 additions & 12 deletions __tests__/proxy-integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Docker from 'dockerode'
import {Credential, JobDetails} from '../src/api-client'
import {Credential} from '../src/api-client'
import {ImageService} from '../src/image-service'
import {PROXY_IMAGE_NAME} from '../src/main'
import {ProxyBuilder} from '../src/proxy'
Expand All @@ -10,15 +10,7 @@ import path from 'path'

describe('ProxyBuilder', () => {
const docker = new Docker()
const details: JobDetails = {
id: '1',
'allowed-updates': [
{
'dependency-type': 'all'
}
],
'package-manager': 'npm_and_yarn'
}
const jobId = 1
const credentials: Credential[] = [
{
type: 'git_source',
Expand Down Expand Up @@ -48,7 +40,7 @@ describe('ProxyBuilder', () => {
return
}

const proxy = await builder.run(details, credentials)
const proxy = await builder.run(jobId, credentials)
await proxy.container.start()

expect(proxy.networkName).toBe('job-1-network')
Expand Down Expand Up @@ -91,7 +83,7 @@ describe('ProxyBuilder', () => {
fs.writeFileSync(certPath, 'ca-pem-contents')
process.env.CUSTOM_CA_PATH = certPath

const proxy = await builder.run(details, credentials)
const proxy = await builder.run(jobId, credentials)
await proxy.container.start()

const id = proxy.container.id
Expand Down
12 changes: 6 additions & 6 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.

16 changes: 8 additions & 8 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ProxyConfig
} from './config-types'
import {ContainerService} from './container-service'
import {Credential, JobDetails} from './api-client'
import {Credential} from './api-client'
import {pki} from 'node-forge'
import {outStream, errStream} from './utils'

Expand Down Expand Up @@ -60,15 +60,15 @@ export class ProxyBuilder {
private readonly proxyImage: string
) {}

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

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

const container = await this.createContainer(details.id, name, networkName)
const container = await this.createContainer(jobId, name, networkName)

await ContainerService.storeInput(
CONFIG_FILE_NAME,
Expand Down Expand Up @@ -130,7 +130,7 @@ export class ProxyBuilder {

private buildProxyConfig(
credentials: Credential[],
jobId: string
jobId: number
): ProxyConfig {
const ca = this.generateCertificateAuthority()
const password = crypto.randomBytes(20).toString('hex')
Expand Down Expand Up @@ -167,7 +167,7 @@ export class ProxyBuilder {
}

private async createContainer(
jobId: string,
jobId: number,
containerName: string,
networkName: string
): Promise<Container> {
Expand Down
2 changes: 1 addition & 1 deletion src/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Updater {
*/
async runUpdater(): Promise<boolean> {
const proxy = await new ProxyBuilder(this.docker, this.proxyImage).run(
this.details,
this.apiClient.params.jobId,
this.credentials
)
proxy.container.start()
Expand Down

0 comments on commit 33b0097

Please sign in to comment.