Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add proxy cache experiment #1137

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion __tests__/proxy-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ integration('ProxyBuilder', () => {
}
]

const builder = new ProxyBuilder(docker, PROXY_IMAGE_NAME)
const cachedMode = true
const builder = new ProxyBuilder(docker, PROXY_IMAGE_NAME, cachedMode)

beforeAll(async () => {
await ImageService.pull(PROXY_IMAGE_NAME)
Expand Down
13 changes: 8 additions & 5 deletions __tests__/updater-builder-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ integration('UpdaterBuilder', () => {
const details: JobDetails = {
'allowed-updates': [],
id: '1',
'package-manager': 'npm_and_yarn'
'package-manager': 'npm_and_yarn',
experiments: {}
}

const workingDirectory = path.join(
Expand Down Expand Up @@ -51,10 +52,12 @@ integration('UpdaterBuilder', () => {
fs.mkdirSync(outputPath)
fs.mkdirSync(repoPath)

const proxy = await new ProxyBuilder(docker, PROXY_IMAGE_NAME).run(
1,
credentials
)
const cachedMode = true
const proxy = await new ProxyBuilder(
docker,
PROXY_IMAGE_NAME,
cachedMode
).run(1, credentials)
await proxy.container.start()
const input = {job: details}
const params = new JobParameters(
Expand Down
11 changes: 8 additions & 3 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.

1 change: 1 addition & 0 deletions src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type JobDetails = {
}>
id: string
'package-manager': string
experiments: object
}

export type JobError = {
Expand Down
6 changes: 4 additions & 2 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export type Proxy = {
export class ProxyBuilder {
constructor(
private readonly docker: Docker,
private readonly proxyImage: string
private readonly proxyImage: string,
private readonly cachedMode: boolean
) {}

async run(jobId: number, credentials: Credential[]): Promise<Proxy> {
Expand Down Expand Up @@ -192,7 +193,8 @@ export class ProxyBuilder {
process.env.https_proxy || process.env.HTTPS_PROXY || ''
}`,
`no_proxy=${process.env.no_proxy || process.env.NO_PROXY || ''}`,
`JOB_ID=${jobId}`
`JOB_ID=${jobId}`,
`PROXY_CACHE=${this.cachedMode ? 'true' : 'false'}`
],
Entrypoint: [
'sh',
Expand Down
11 changes: 10 additions & 1 deletion src/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ export class Updater {
// Create required folders in the workingDirectory
fs.mkdirSync(this.outputHostPath)

const proxy = await new ProxyBuilder(this.docker, this.proxyImage).run(
const cachedMode =
this.details.experiments?.hasOwnProperty('proxy-cached') === true

const proxyBuilder = new ProxyBuilder(
this.docker,
this.proxyImage,
cachedMode
)

const proxy = await proxyBuilder.run(
this.apiClient.params.jobId,
this.credentials
)
Expand Down
Loading