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

Proxy support #674

Merged
merged 37 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f5939eb
Proxy support
DavidGOrtega Jul 27, 2021
8c1124c
remove unused and lint
DavidGOrtega Jul 28, 2021
ad4b726
log teardown
DavidGOrtega Jul 29, 2021
beb4430
skip tb
DavidGOrtega Jul 29, 2021
f372d41
node 14
DavidGOrtega Jul 29, 2021
874cd6a
remove skip and node update
DavidGOrtega Aug 2, 2021
9bc69cd
remove consle
DavidGOrtega Aug 2, 2021
82e6b89
Merge branch 'master' into proxy
0x2b3bfa0 Aug 5, 2021
7f37af9
Remove stray newline after merge
0x2b3bfa0 Aug 5, 2021
567da27
merge master
DavidGOrtega Aug 6, 2021
c31efc3
Merge branch 'proxy' of https://github.com/iterative/cml into proxy
DavidGOrtega Aug 6, 2021
74327a0
upgrade deps
DavidGOrtega Aug 6, 2021
ada6c55
update locl
DavidGOrtega Aug 6, 2021
4aba7d0
Avoid upsetting the linter
0x2b3bfa0 Aug 9, 2021
4768406
detectOpenHandles
DavidGOrtega Aug 10, 2021
3a7fe82
Merge branch 'proxy' of https://github.com/iterative/cml into proxy
DavidGOrtega Aug 10, 2021
cd77704
remove jest global
DavidGOrtega Aug 13, 2021
e5e91e4
max tiemout
DavidGOrtega Aug 13, 2021
b59670b
--testTimeout param
DavidGOrtega Aug 13, 2021
7050b35
tb back
DavidGOrtega Aug 13, 2021
6ccfac6
tb partial tests
DavidGOrtega Aug 13, 2021
8b26e14
tb partial tests 2
DavidGOrtega Aug 13, 2021
f1bb509
skip tb test
DavidGOrtega Aug 13, 2021
0aee11a
tb skip change
DavidGOrtega Aug 13, 2021
bf8c672
isolating tb test
DavidGOrtega Aug 13, 2021
426650a
isolating tb test
DavidGOrtega Aug 13, 2021
6eedd36
commit one
DavidGOrtega Aug 14, 2021
3b1c850
merge master [skip ci]
DavidGOrtega Aug 16, 2021
0e79e23
merge master [skip ci]
DavidGOrtega Aug 16, 2021
e22ba1c
merge master
DavidGOrtega Aug 16, 2021
9b15a95
no proxy
DavidGOrtega Aug 16, 2021
d504372
no timeout
DavidGOrtega Aug 16, 2021
77c046b
Run tests with global timeout
0x2b3bfa0 Sep 2, 2021
5a0c4a0
merge master
DavidGOrtega Sep 13, 2021
ebe684d
remove skip
DavidGOrtega Sep 13, 2021
aa5a5ef
merge master
DavidGOrtega Sep 13, 2021
d194c87
forceexit
DavidGOrtega Sep 13, 2021
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ENV LC_ALL="en_US.UTF-8"
# INSTALL NODE, GIT & GO
RUN add-apt-repository ppa:git-core/ppa --yes \
&& add-apt-repository ppa:longsleep/golang-backports --yes \
&& curl --location https://deb.nodesource.com/setup_12.x | bash \
&& curl --location https://deb.nodesource.com/setup_14.x | bash \
DavidGOrtega marked this conversation as resolved.
Show resolved Hide resolved
&& apt-get update \
&& apt-get install --yes git golang-go nodejs \
&& apt-get clean \
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ compute resources as secrets. In the above example, `AWS_ACCESS_KEY_ID` and
Please see our docs about
[configuring cloud storage providers](#configuring-cloud-storage-providers).

#### Proxy support

CML support proxy via known environment variables `http_proxy` and
`https_proxy`.

#### On-premise (Local) Runners

This means using on-premise machines as self-hosted runners. The `cml-runner`
Expand Down
2 changes: 2 additions & 0 deletions bin/cml-tensorboard-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const run = async (opts) => {

// reads stdout every 5 secs to find the tb uri
setInterval(async () => {
console.log('1sec');
const stdoutData = await fs.readFile(stdoutPath, 'utf8');
const regex = /(https?:\/\/[^\s]+)/;
const matches = stdoutData.match(regex);
Expand All @@ -85,6 +86,7 @@ const run = async (opts) => {

// waits 1 min before dies
setTimeout(async () => {
console.log('here');
closeFd(stdoutFd) && closeFd(stderrFd);
console.error(await fs.readFile(stderrPath, 'utf8'));
throw new Error('Tensorboard took too long! Canceled.');
Expand Down
6 changes: 5 additions & 1 deletion bin/cml-tensorboard-dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ describe('CML e2e', () => {
`);
});

test('cml-tensorboard-dev.js --md returns md and after command TB is still up', async () => {
test.skip('cml-tensorboard-dev.js --md returns md and after command TB is still up', async () => {
const name = 'My experiment';
const desc = 'Test experiment';
const title = 'go to the experiment';
console.log(`node ./bin/cml-tensorboard-dev.js --credentials '${CREDENTIALS}' \
--md --title '${title}' \
--logdir logs --name '${name}' --description '${desc}'`);

0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
const output = await exec(
`node ./bin/cml-tensorboard-dev.js --credentials '${CREDENTIALS}' \
--md --title '${title}' \
Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

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

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"fs-extra": "^9.0.1",
"git-url-parse": "^11.4.0",
"globby": "^11.0.3",
"https-proxy-agent": "^5.0.0",
"js-base64": "^3.5.2",
"mmmagic": "^0.5.3",
"node-fetch": "^2.6.0",
Expand All @@ -92,8 +93,13 @@
"husky": "^4.2.3",
"jest": "^24.9.0",
"lint-staged": "^10.0.8",
"prettier": "^2.1.1"
"prettier": "^2.1.1",
"transparent-proxy": "^1.8.5"
},
"description": "<p align=\"center\"> <img src=\"https://static.iterative.ai/img/cml/title_strip_trim.png\" width=400> </p>",
"homepage": "https://github.com/iterative/cml#readme"
"homepage": "https://github.com/iterative/cml#readme",
"jest": {
"globalSetup": "./tests/setup.js",
"globalTeardown": "./tests/teardown.js"
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
}
}
1 change: 1 addition & 0 deletions src/cml.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const CML = require('../src/cml').default;

jest.setTimeout(60000);

describe('Github tests', () => {
const OLD_ENV = process.env;

Expand Down
6 changes: 5 additions & 1 deletion src/drivers/bitbucket_cloud.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fetch = require('node-fetch');
const { URL } = require('url');

const { proxyAgent } = require('../utils');

const { BITBUCKET_COMMIT, BITBUCKET_BRANCH } = process.env;
class BitbucketCloud {
constructor(opts = {}) {
Expand Down Expand Up @@ -181,10 +183,12 @@ class BitbucketCloud {
'Content-Type': 'application/json',
Authorization: 'Basic ' + `${token}`
};

const response = await fetch(url || `${api}${endpoint}`, {
method,
headers,
body
body,
agent: proxyAgent()
});

if (response.status > 300) {
Expand Down
7 changes: 7 additions & 0 deletions src/drivers/bitbucket_cloud.test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
jest.setTimeout(120000);

const BitbucketCloud = require('./bitbucket_cloud');
const {
TEST_BBCLOUD_TOKEN: TOKEN,
TEST_BBCLOUD_REPO: REPO,
TEST_BBCLOUD_SHA: SHA
} = process.env;

describe('Non Enviromental tests', () => {
const client = new BitbucketCloud({ repo: REPO, token: TOKEN });

test('test repo and token', async () => {
expect(client.repo).toBe(REPO);
expect(client.token).toBe(TOKEN);
});

test('Comment', async () => {
const report = '## Test comment';
const commitSha = SHA;

await client.commentCreate({ report, commitSha });
});

test('Check', async () => {
await expect(client.checkCreate()).rejects.toThrow(
'Bitbucket Cloud does not support check!'
);
});

test('Publish', async () => {
const path = `${__dirname}/../../assets/logo.png`;
await expect(client.upload({ path })).rejects.toThrow(
'Bitbucket Cloud does not support upload!'
);
});

test('Runner token', async () => {
await expect(client.runnerToken()).rejects.toThrow(
'Bitbucket Cloud does not support runnerToken!'
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { Octokit } = require('@octokit/rest');
const { throttling } = require('@octokit/plugin-throttling');
const tar = require('tar');

const { download, exec } = require('../utils');
const { download, exec, proxyAgent } = require('../utils');

const CHECK_TITLE = 'CML Report';
process.env.RUNNER_ALLOW_RUNASROOT = 1;
Expand Down Expand Up @@ -51,6 +51,7 @@ const octokit = (token, repo) => {
}
};
const octokitOptions = {
request: { agent: proxyAgent() },
auth: token,
throttle: {
onRateLimit: throttleHandler,
Expand Down
1 change: 0 additions & 1 deletion src/drivers/github.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
jest.setTimeout(80000);

const GithubClient = require('./github');

const {
Expand Down
9 changes: 7 additions & 2 deletions src/drivers/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fs = require('fs').promises;
const fse = require('fs-extra');
const { resolve } = require('path');

const { fetchUploadData, download, exec } = require('../utils');
const { fetchUploadData, download, exec, proxyAgent } = require('../utils');

const {
IN_DOCKER,
Expand Down Expand Up @@ -271,7 +271,12 @@ class Gitlab {
if (!url) throw new Error('Gitlab API endpoint not found');

const headers = { 'PRIVATE-TOKEN': token, Accept: 'application/json' };
const response = await fetch(url, { method, headers, body });
const response = await fetch(url, {
method,
headers,
body,
agent: proxyAgent()
});

if (response.status > 300) throw new Error(response.statusText);
if (raw) return response;
Expand Down
10 changes: 10 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fetch = require('node-fetch');
const HttpsProxyAgent = require('https-proxy-agent');
const fs = require('fs');
const PATH = require('path');
const mmm = require('mmmagic');
Expand Down Expand Up @@ -165,6 +166,14 @@ const sshConnection = async (opts) => {
return ssh;
};

const proxyAgent = (opts = {}) => {
const { https_proxy: httpsProxy, http_proxy: httpProxy } = process.env;
const { url = httpsProxy || httpProxy } = opts;

if (!url) return;
return new HttpsProxyAgent(url);
};

exports.exec = exec;
exports.fetchUploadData = fetchUploadData;
exports.upload = upload;
Expand All @@ -175,3 +184,4 @@ exports.sshPublicFromPrivateRsa = sshPublicFromPrivateRsa;
exports.watermarkUri = watermarkUri;
exports.download = download;
exports.sshConnection = sshConnection;
exports.proxyAgent = proxyAgent;
22 changes: 21 additions & 1 deletion src/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const { exec, upload, sshPublicFromPrivateRsa } = require('./utils');
const {
exec,
upload,
sshPublicFromPrivateRsa,
proxyAgent
} = require('./utils');

describe('exec tests', () => {
test('exec is await and outputs hello', async () => {
Expand Down Expand Up @@ -44,4 +49,19 @@ describe('Other tests', () => {
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwMFO1qTq68Uao1TU6W+911SWZN+mce+OTodS5mne0vMiWm7AFJuaxMKzL1NGeXOAUY+oeTAE7NCyi56mqEo3R8kOvwYbIQKmz27lzL0ZniI9UkYkE9aFslvTgou6cqcJO6S8GMNnJLLXbmX37zGUgZyuTAuot885WHqKyW0Pg/zplBNIPBRA+yhQG8z17dj8VwixoE7KgRiNK9CN5Yz/2TRlsHLan9LH9vHSK477bj+jPtbII4V5ZP5Du/70Seb1fe3648DVpg4mjDmLrQkW/rtNanKMVLw3bD9VroeLe3PW91nLq+noOuljPETtxxrhGagE28U6igPTmIQYczrpz ';
expect(publicKey).toBe(expected);
});

describe('proxyAgent', () => {
const { http_proxy, https_proxy } = process.env;
process.env.http_proxy = 'https://www.example1.com';
expect(proxyAgent().proxy.host).toBe('www.example1.com');

// https_proxy overrides http_proxy
process.env.https_proxy = 'https://www.example2.com';
expect(proxyAgent().proxy.host).toBe('www.example2.com');

const url = 'https://www.example.com';
expect(proxyAgent({ url: `${url}` }).proxy.host).toBe('www.example.com');

process.env = { ...process.env, http_proxy, https_proxy };
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
});
});
22 changes: 22 additions & 0 deletions tests/proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const ProxyServer = require('transparent-proxy');

const PORT = 9093;
const startProxy = () => {
if (global.proxyTestsServer) return;

global.proxyTestsServer = new ProxyServer();
global.proxyTestsServer.listen(PORT, '0.0.0.0', () =>
console.log(`Proxy listening on port ${PORT}`)
);
};
const stopProxy = () => {
console.log('Teardown Jest. Stoping Proxy...');
global.proxyTestsServer.close();
global.proxyTestsServer.unref();
};

module.exports = {
startProxy,
stopProxy,
PORT
};
5 changes: 5 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { startProxy, PORT } = require('./proxy');
module.exports = () => {
process.env.http_proxy = `http://localhost:${PORT}`;
startProxy();
};
4 changes: 4 additions & 0 deletions tests/teardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { stopProxy } = require('./proxy');
module.exports = () => {
stopProxy();
};