Skip to content

Commit

Permalink
Merge pull request #163 from github/forward-proxy-urls-to-the-proxy-c…
Browse files Browse the repository at this point in the history
…ontainer

Forward proxy `ENV` variables to proxy container
  • Loading branch information
Landon Grindheim authored and GitHub committed May 5, 2022
2 parents 148f5e0 + 1bf953b commit f443a39
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
30 changes: 30 additions & 0 deletions __tests__/proxy-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,35 @@ integration('ProxyBuilder', () => {
])
const stdout = proc.stdout.toString()
expect(stdout).toEqual('ca-pem-contents')

await proxy.shutdown()
})

jest.setTimeout(20000)
it('forwards custom proxy urls if configured', async () => {
const url = 'http://example.com'
process.env.HTTP_PROXY = url

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

const id = proxy.container.id
const proc = spawnSync('docker', ['exec', id, 'printenv', 'http_proxy'])
const output = proc.stdout.toString().trim()
expect(output).toMatch(url)
})

jest.setTimeout(20000)
it('forwards downcased proxy urls if configured', async () => {
const url = 'https://example.com'
process.env.https_proxy = url

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

const id = proxy.container.id
const proc = spawnSync('docker', ['exec', id, 'printenv', 'https_proxy'])
const output = proc.stdout.toString().trim()
expect(output).toEqual(url)
})
})
7 changes: 6 additions & 1 deletion dist/main/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/main/index.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,14 @@ export class ProxyBuilder {
name: containerName,
AttachStdout: true,
AttachStderr: true,
Env: [`JOB_ID=${jobId}`],
Env: [
`http_proxy=${process.env.http_proxy || process.env.HTTP_PROXY || ''}`,
`https_proxy=${
process.env.https_proxy || process.env.HTTPS_PROXY || ''
}`,
`no_proxy=${process.env.no_proxy || process.env.NO_PROXY || ''}`,
`JOB_ID=${jobId}`
],
Entrypoint: [
'sh',
'-c',
Expand Down

0 comments on commit f443a39

Please sign in to comment.