Skip to content

Commit

Permalink
Use IPAddress in URL to locate proxy container
Browse files Browse the repository at this point in the history
We've encountered some friction when running Dependabot on Actions
runners in Kubernetes clusters. We're thinking the friction has to do
with DNS resolution, and that using an IP address will prevent that step
from needing to happen.
  • Loading branch information
Landon Grindheim authored and GitHub committed Apr 18, 2022
1 parent 3383d05 commit 11b24bd
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 18 deletions.
13 changes: 10 additions & 3 deletions __tests__/proxy-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ integration('ProxyBuilder', () => {
const proxy = await builder.run(jobId, credentials)
await proxy.container.start()

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

const containerInfo = await proxy.container.inspect()
expect(containerInfo.Name).toBe('/dependabot-job-1-proxy')
expect(containerInfo.Config.Entrypoint).toEqual([
Expand All @@ -46,6 +43,16 @@ integration('ProxyBuilder', () => {
'/usr/sbin/update-ca-certificates && /update-job-proxy'
])

expect(proxy.networkName).toBe('dependabot-job-1-internal-network')

const proxyUrl = await proxy.url()
expect(proxyUrl).toMatch(/^http:\/\/1:.+:1080$/)

const proxyIPAddress =
containerInfo.NetworkSettings.Networks[proxy.networkName].IPAddress
expect(proxyIPAddress.length).toBeGreaterThan(0)
expect(proxyUrl).toContain(proxyIPAddress)

const networkInfo = await proxy.network.inspect()
expect(networkInfo.Name).toBe('dependabot-job-1-internal-network')
expect(networkInfo.Internal).toBe(true)
Expand Down
4 changes: 3 additions & 1 deletion __tests__/updater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ describe('Updater', () => {
},
network: jest.fn(),
networkName: 'mockNetworkName',
url: 'http://localhost',
url: () => {
'http://localhost'
},
cert: 'mockCertificate',
shutdown: jest.fn()
}
Expand Down
23 changes: 17 additions & 6 deletions 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.

16 changes: 14 additions & 2 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type Proxy = {
container: Container
network: Network
networkName: string
url: string
url: () => Promise<string>
cert: string
shutdown: () => Promise<void>
}
Expand Down Expand Up @@ -111,7 +111,19 @@ export class ProxyBuilder {
errStream(' proxy')
)

const url = `http://${config.proxy_auth.username}:${config.proxy_auth.password}@${name}:1080`
const url = async (): Promise<string> => {
const containerInfo = await container.inspect()

if (containerInfo.State.Running === true) {
const ipAddress =
containerInfo.NetworkSettings.Networks[`${internalNetworkName}`]
.IPAddress
return `http://${config.proxy_auth.username}:${config.proxy_auth.password}@${ipAddress}:1080`
} else {
throw new Error("proxy container isn't running")
}
}

return {
container,
network: internalNetwork,
Expand Down
9 changes: 5 additions & 4 deletions src/updater-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class UpdaterBuilder {
/usr/sbin/update-ca-certificates &&\
$DEPENDABOT_HOME/dependabot-updater/bin/run ${updaterCommand}`

const proxyUrl = await this.proxy.url()
const container = await this.docker.createContainer({
Image: this.updaterImage,
name: containerName,
Expand All @@ -47,10 +48,10 @@ export class UpdaterBuilder {
`DEPENDABOT_REPO_CONTENTS_PATH=${REPO_CONTENTS_PATH}`,
`DEPENDABOT_API_URL=${this.jobParams.dependabotApiDockerUrl}`,
`SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt`,
`http_proxy=${this.proxy.url}`,
`HTTP_PROXY=${this.proxy.url}`,
`https_proxy=${this.proxy.url}`,
`HTTPS_PROXY=${this.proxy.url}`,
`http_proxy=${proxyUrl}`,
`HTTP_PROXY=${proxyUrl}`,
`https_proxy=${proxyUrl}`,
`HTTPS_PROXY=${proxyUrl}`,
`ENABLE_CONNECTIVITY_CHECK=1`
],
Cmd: ['sh', '-c', cmd],
Expand Down
2 changes: 1 addition & 1 deletion src/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class Updater {
this.apiClient.params.jobId,
this.credentials
)
proxy.container.start()
await proxy.container.start()

try {
const files = await this.runFileFetcher(proxy)
Expand Down

0 comments on commit 11b24bd

Please sign in to comment.