Skip to content

Commit c9341f7

Browse files
authored
CR-1683 - inject proxy env vars to engine container (#596)
* inject proxy env vars to engine container * 0.73.23
1 parent 3ea200e commit c9341f7

File tree

7 files changed

+58
-53
lines changed

7 files changed

+58
-53
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v10.15.3

lib/interface/cli/commands/gitops/install.cmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
const _ = require('lodash');
33
const Command = require('../../Command');
44
const installRoot = require('../root/install.cmd');
5-
const { downloadProvider, detectProxy } = require('../hybrid/helper');
5+
const { detectProxy } = require('../../helpers/general');
6+
const { downloadProvider } = require('../hybrid/helper');
67
const { Runner, components } = require('../../../../binary');
78

89
const installArgoCmd = new Command({

lib/interface/cli/commands/hybrid/helper.js

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -950,38 +950,13 @@ function keyValueAsStringToObject(nodeSelectorStr) {
950950
}
951951
}
952952

953-
function keyValueArrayToObject(arr) {
954-
return arr.reduce((acc, cur) => {
955-
const parts = cur.split('=');
956-
// eslint-disable-next-line prefer-destructuring
957-
acc[parts[0]] = parts[1];
958-
return acc;
959-
}, {});
960-
}
961-
962953
function objectToKeyValueArray(obj) {
963954
return Object.keys(obj).reduce((acc, key) => {
964955
acc.push(`${key}=${obj[key]}`);
965956
return acc;
966957
}, []);
967958
}
968959

969-
function addProxyVariables(envVars, { httpProxy, httpsProxy, noProxy }) {
970-
const envVarsObj = keyValueArrayToObject(envVars);
971-
if (httpsProxy && !envVarsObj.HTTPS_PROXY && !envVarsObj.https_proxy) {
972-
envVars.push(`HTTPS_PROXY=${httpsProxy}`);
973-
envVars.push(`https_proxy=${httpsProxy}`);
974-
}
975-
if (httpProxy && !envVarsObj.HTTP_PROXY && !envVarsObj.http_proxy) {
976-
envVars.push(`HTTP_PROXY=${httpProxy}`);
977-
envVars.push(`http_proxy=${httpProxy}`);
978-
}
979-
if (noProxy && !envVarsObj.NO_PROXY && !envVarsObj.no_proxy) {
980-
envVars.push(`NO_PROXY=${noProxy}`);
981-
envVars.push(`no_proxy=${noProxy}`);
982-
}
983-
}
984-
985960
function serealizeToKeyValuePairs(obj) {
986961
return _.keys(obj).reduce((acc, key) => {
987962
if (acc) {
@@ -991,17 +966,6 @@ function serealizeToKeyValuePairs(obj) {
991966
}, '');
992967
}
993968

994-
function detectProxy() {
995-
const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY;
996-
const httpsProxy = process.env.https_proxy || process.env.HTTPS_PROXY;
997-
const noProxy = process.env.no_proxy || process.env.NO_PROXY;
998-
return {
999-
httpProxy,
1000-
httpsProxy,
1001-
noProxy,
1002-
};
1003-
}
1004-
1005969
function getRuntimeImagesWithRegistryUrl(registry) {
1006970
return Object.keys(RUNTIME_IMAGES).reduce((acc, cur) => {
1007971
acc[cur] = `${registry}/${RUNTIME_IMAGES[cur]}`;
@@ -1088,7 +1052,6 @@ module.exports = {
10881052
getRuntimeVersion,
10891053
createTestPipeline,
10901054
getTestPipeline,
1091-
addProxyVariables,
10921055
updateTestPipelineRuntime,
10931056
executeTestPipeline,
10941057
createProgressBar,
@@ -1103,14 +1066,12 @@ module.exports = {
11031066
newRuntimeName,
11041067
newAgentName,
11051068
keyValueAsStringToObject,
1106-
keyValueArrayToObject,
11071069
objectToKeyValueArray,
11081070
downloadRelatedComponents: downloadHybridComponents,
11091071
downloadSteveDore,
11101072
downloadVeonona,
11111073
downloadProvider,
11121074
runUpgrade,
1113-
detectProxy,
11141075
serealizeToKeyValuePairs,
11151076
getRuntimeImagesWithRegistryUrl,
11161077
installAppProxy,

lib/interface/cli/commands/hybrid/init.cmd.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const runnerRoot = require('../root/runner.cmd');
44
const inquirer = require('inquirer');
55
const colors = require('colors');
66
const _ = require('lodash');
7+
const { addProxyVariables, detectProxy, keyValueArrayToObject } = require('../../helpers/general');
78
const { getAllKubeContexts, getKubeContext } = require('../../helpers/kubernetes');
89
const installMonitoring = require('../monitor/install.cmd');
910
const createClusterCmd = require('../cluster/create.cmd');
@@ -16,7 +17,6 @@ const installationProgress = require('./installation-process');
1617
const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
1718
const {
1819
createErrorHandler,
19-
keyValueArrayToObject,
2020
createTestPipeline,
2121
executeTestPipeline,
2222
updateTestPipelineRuntime,
@@ -30,10 +30,8 @@ const {
3030
attachRuntime,
3131
newRuntimeName,
3232
newAgentName,
33-
detectProxy,
3433
keyValueAsStringToObject,
3534
getRuntimeImagesWithRegistryUrl,
36-
addProxyVariables,
3735
mergeValuesFromValuesFile,
3836
INSTALLATION_DEFAULTS,
3937
} = require('./helper');

lib/interface/cli/commands/pipeline/run.local.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const _ = require('lodash');
77
const { sdk } = require('../../../../logic');
88
const { followLogs } = require('../../helpers/logs');
99
const chalk = require('chalk');
10+
const { addProxyVariables, detectProxy } = require('../../helpers/general');
1011

1112
const regex = /##[0-9a-f]{24}##/i;
1213
const EngineErrorPrefix = 'EngineError';
@@ -113,15 +114,18 @@ class RunLocalCommand extends RunBaseCommand {
113114
console.log(`Running pipeline: ${pipelineName}`);
114115

115116
return new Promise((resolve, reject) => {
117+
const proxyEnv = detectProxy();
118+
const env = [
119+
...(debug ? ['PIPELINE_DEBUG_MODE=true'] : []),
120+
`ACCESS_TOKEN=${currentContext.token}`,
121+
`PIPELINE_ID=${pipelineName}`,
122+
`BRANCH=${branch}`,
123+
`CF_HOST=${currentContext.url}`,
124+
'DOCKER_SOCKET_PATH=/var/run/docker.sock',
125+
];
126+
addProxyVariables(env, proxyEnv);
116127
const eventEmitter = this.docker.run(DEFAULTS.ENGINE_IMAGE, [], undefined, _.mergeWith({
117-
Env: [
118-
...(debug ? ['PIPELINE_DEBUG_MODE=true'] : []),
119-
`ACCESS_TOKEN=${currentContext.token}`,
120-
`PIPELINE_ID=${pipelineName}`,
121-
`BRANCH=${branch}`,
122-
`CF_HOST=${currentContext.url}`,
123-
'DOCKER_SOCKET_PATH=/var/run/docker.sock',
124-
],
128+
Env: env,
125129
Hostconfig: {
126130
Binds: [
127131
'/var/run/docker.sock:/var/run/docker.sock',
@@ -131,8 +135,10 @@ class RunLocalCommand extends RunBaseCommand {
131135
if (err) {
132136
console.log(chalk.red(`Error when running pipeline : ${err}`));
133137
// eslint-disable-next-line prefer-promise-reject-errors
134-
resolve(1);
138+
return resolve(1);
135139
}
140+
141+
resolve(0);
136142
});
137143
if (this.argv.detach) {
138144
resolve(0);

lib/interface/cli/helpers/general.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,41 @@ function ignoreHttpError(e) {
182182
return undefined;
183183
}
184184

185+
function detectProxy() {
186+
const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY;
187+
const httpsProxy = process.env.https_proxy || process.env.HTTPS_PROXY;
188+
const noProxy = process.env.no_proxy || process.env.NO_PROXY;
189+
return {
190+
httpProxy,
191+
httpsProxy,
192+
noProxy,
193+
};
194+
}
195+
196+
function keyValueArrayToObject(arr) {
197+
return arr.reduce((acc, cur) => {
198+
const parts = cur.split('=');
199+
// eslint-disable-next-line prefer-destructuring
200+
acc[parts[0]] = parts[1];
201+
return acc;
202+
}, {});
203+
}
204+
205+
function addProxyVariables(envVars, { httpProxy, httpsProxy, noProxy }) {
206+
const envVarsObj = keyValueArrayToObject(envVars);
207+
if (httpsProxy && !envVarsObj.HTTPS_PROXY && !envVarsObj.https_proxy) {
208+
envVars.push(`HTTPS_PROXY=${httpsProxy}`);
209+
envVars.push(`https_proxy=${httpsProxy}`);
210+
}
211+
if (httpProxy && !envVarsObj.HTTP_PROXY && !envVarsObj.http_proxy) {
212+
envVars.push(`HTTP_PROXY=${httpProxy}`);
213+
envVars.push(`http_proxy=${httpProxy}`);
214+
}
215+
if (noProxy && !envVarsObj.NO_PROXY && !envVarsObj.no_proxy) {
216+
envVars.push(`NO_PROXY=${noProxy}`);
217+
envVars.push(`no_proxy=${noProxy}`);
218+
}
219+
}
185220

186221
module.exports = {
187222
wrapHandler,
@@ -194,4 +229,7 @@ module.exports = {
194229
watchFile,
195230
isDebug,
196231
ignoreHttpError,
232+
detectProxy,
233+
keyValueArrayToObject,
234+
addProxyVariables,
197235
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.73.22",
3+
"version": "0.73.23",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)