@@ -14,10 +14,11 @@ const DEFAULTS = require('../../defaults');
14
14
const sdk = require ( '../../../../logic/sdk' ) ;
15
15
const installationProgress = require ( './installation-process' ) ;
16
16
const { to } = require ( './../../../../logic/cli-config/errors/awaitTo' ) ;
17
- const { createErrorHandler } = require ( './helper' ) ;
18
17
const YAML = require ( 'yaml' ) ;
19
18
const fs = require ( 'fs' ) ;
20
19
const {
20
+ createErrorHandler,
21
+ keyValueArrayToObject,
21
22
createTestPipeline,
22
23
executeTestPipeline,
23
24
updateTestPipelineRuntime,
@@ -34,6 +35,8 @@ const {
34
35
detectProxy,
35
36
keyValueAsStringToObject,
36
37
getRuntimeImagesWithRegistryUrl,
38
+ addProxyVariables,
39
+ objectToKeyValueArray,
37
40
INSTALLATION_DEFAULTS ,
38
41
} = require ( './helper' ) ;
39
42
const InstallationPlan = require ( './InstallationPlan' ) ;
@@ -57,6 +60,7 @@ function printInstallationOptionsSummary({
57
60
shouldExecutePipeline,
58
61
httpProxy,
59
62
httpsProxy,
63
+ noProxy,
60
64
appProxy,
61
65
appProxyHost,
62
66
} ) {
@@ -67,6 +71,7 @@ function printInstallationOptionsSummary({
67
71
4. Execute demo pipeline after install: ${ colors . cyan ( ! ! shouldExecutePipeline ) }
68
72
5. HTTP proxy: ${ httpProxy ? colors . cyan ( httpProxy ) : 'none' }
69
73
6. HTTPS proxy: ${ httpsProxy ? colors . cyan ( httpsProxy ) : 'none' }
74
+ 7. No proxy: ${ noProxy ? colors . cyan ( noProxy ) : 'none' }
70
75
` ;
71
76
72
77
if ( appProxy ) {
@@ -146,7 +151,7 @@ const initCmd = new Command({
146
151
describe : 'Path to kubeconfig file (default is $HOME/.kube/config)' ,
147
152
} )
148
153
. option ( 'values' , {
149
- describe : 'specify values in a YAML file' ,
154
+ describe : 'specify values in a YAML file (see example here: https://github.com/codefresh-io/venona/blob/release-1.0/venonactl/example/values-example.yaml) ' ,
150
155
} )
151
156
. option ( 'set-value' , {
152
157
describe : 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes' ,
@@ -171,8 +176,9 @@ const initCmd = new Command({
171
176
describe : 'Print logs' ,
172
177
} )
173
178
. option ( 'env-vars' , {
174
- describe : 'Addiontal env vars to be used in agent\'s pod ' ,
179
+ describe : 'Addiontal env vars to be used in all Codefresh components ' ,
175
180
type : array ,
181
+ default : [ ] ,
176
182
} )
177
183
. option ( 'app-proxy' , {
178
184
describe : 'install app proxy component (default false)' ,
@@ -191,7 +197,9 @@ const initCmd = new Command({
191
197
describe : 'docker daemon access (default true)' ,
192
198
default : true ,
193
199
type : 'boolean' ,
194
- } ) ,
200
+ } )
201
+ . example ( 'codefresh runner init --values values.yaml (see values file example here: '
202
+ + 'https://github.com/codefresh-io/venona/blob/release-1.0/venonactl/example/values-example.yaml)' ) ,
195
203
handler : async ( argv ) => {
196
204
let resumedInstallation = false ;
197
205
@@ -225,16 +233,16 @@ const initCmd = new Command({
225
233
'set-value' : setValue ,
226
234
'set-file' : setFile ,
227
235
'skip-cluster-test' : skipClusterTest ,
228
- 'docker-registry' : dockerRegistry ,
229
236
'app-proxy-ingress-class' : appProxyIngressClass ,
237
+ 'env-vars' : envVars ,
230
238
} = _argv ;
231
239
let {
232
240
yes : noQuestions ,
233
241
'kube-context-name' : kubeContextName ,
234
242
'kube-namespace' : kubeNamespace ,
235
243
'set-default-runtime' : shouldMakeDefaultRe ,
244
+ 'docker-registry' : dockerRegistry ,
236
245
'exec-demo-pipeline' : shouldExecutePipeline ,
237
- 'env-vars' : envVars ,
238
246
'http-proxy' : httpProxy ,
239
247
'https-proxy' : httpsProxy ,
240
248
'no-proxy' : noProxy ,
@@ -275,17 +283,23 @@ const initCmd = new Command({
275
283
if ( _ . get ( valuesObj , 'AppProxy' ) ) {
276
284
appProxy = true ;
277
285
}
278
- if ( ! appProxyHost && _ . get ( valuesObj , 'AppProxy.Host' ) ) {
279
- appProxyHost = _ . get ( valuesObj , 'AppProxy.Host' ) ;
286
+ if ( ! appProxyHost && _ . get ( valuesObj , 'AppProxy.Ingress. Host' ) ) {
287
+ appProxyHost = _ . get ( valuesObj , 'AppProxy.Ingress. Host' ) ;
280
288
}
281
- if ( ! appProxyPathPrefix && _ . get ( valuesObj , 'AppProxy.PathPrefix' ) ) {
282
- appProxyPathPrefix = _ . get ( valuesObj , 'AppProxy.PathPrefix' ) ;
289
+ if ( ! appProxyPathPrefix && _ . get ( valuesObj , 'AppProxy.Ingress. PathPrefix' ) ) {
290
+ appProxyPathPrefix = _ . get ( valuesObj , 'AppProxy.Ingress. PathPrefix' ) ;
283
291
}
284
292
if ( appProxy && ! appProxyHost ) {
285
293
handleError ( new Error ( 'no hostname provided' ) , 'cannot install app-proxy component without a hostname' , undefined , undefined , true ) ;
286
294
}
287
295
if ( _ . has ( valuesObj , 'dockerDaemonScheduler.userAccess' ) ) {
288
- dockerDaemonAccess = _ . get ( valuesObj , 'dockerDaemonScheduler.userAccess' )
296
+ dockerDaemonAccess = _ . get ( valuesObj , 'dockerDaemonScheduler.userAccess' ) ;
297
+ }
298
+ if ( _ . has ( valuesObj , 'EnvVars' ) && envVars . length === 0 ) {
299
+ envVars . push ( ...objectToKeyValueArray ( _ . get ( valuesObj , 'EnvVars' ) ) ) ;
300
+ }
301
+ if ( _ . has ( valuesObj , 'DockerRegistry' ) && ! dockerRegistry ) {
302
+ dockerRegistry = _ . get ( valuesObj , 'DockerRegistry' ) ;
289
303
}
290
304
}
291
305
if ( ! url ) {
@@ -303,10 +317,7 @@ const initCmd = new Command({
303
317
httpProxy = httpProxy || detectedProxyVars . httpProxy ;
304
318
httpsProxy = httpsProxy || detectedProxyVars . httpsProxy ;
305
319
noProxy = noProxy || detectedProxyVars . noProxy ;
306
- envVars = envVars || [ ] ;
307
- if ( ! Array . isArray ( envVars ) ) {
308
- envVars = [ envVars ] ;
309
- }
320
+
310
321
if ( noQuestions ) {
311
322
// use defaults
312
323
kubeContextName = kubeContextName || getKubeContext ( kubeConfigPath ) ;
@@ -344,7 +355,7 @@ const initCmd = new Command({
344
355
type : 'input' ,
345
356
name : 'httpProxy' ,
346
357
default : httpProxy ,
347
- message : 'HTTP proxy to be used by runner inside Kubernetes ?' ,
358
+ message : 'detected HTTP_PROXY, should I use this in all Codefresh components ?' ,
348
359
} ) ;
349
360
}
350
361
@@ -353,7 +364,7 @@ const initCmd = new Command({
353
364
type : 'input' ,
354
365
name : 'httpsProxy' ,
355
366
default : httpsProxy ,
356
- message : 'HTTPS proxy to be used by runner inside Kubernetes ?' ,
367
+ message : 'detected HTTPS_PROXY, should I use this in all Codefresh components ?' ,
357
368
358
369
} ) ;
359
370
}
@@ -362,7 +373,7 @@ const initCmd = new Command({
362
373
type : 'input' ,
363
374
name : 'noProxy' ,
364
375
default : noProxy ,
365
- message : 'NO_PROXY to be used by runner inside Kubernetes ?' ,
376
+ message : 'detected NO_PROXY, should I use this in all Codefresh components ?' ,
366
377
367
378
} ) ;
368
379
}
@@ -409,7 +420,8 @@ const initCmd = new Command({
409
420
kubeNamespace = kubeNamespace || answers . namespace ;
410
421
shouldMakeDefaultRe = _ . isUndefined ( shouldMakeDefaultRe ) ? answers . shouldMakeDefaultRe : shouldMakeDefaultRe ;
411
422
shouldExecutePipeline = _ . isUndefined ( shouldExecutePipeline ) ? answers . shouldExecutePipeline : shouldExecutePipeline ;
412
- ( { httpProxy, httpsProxy, appProxyHost } = answers ) ;
423
+ // eslint-disable-next-line object-curly-newline
424
+ ( { httpProxy, httpsProxy, noProxy, appProxyHost } = answers ) ;
413
425
}
414
426
415
427
printInstallationOptionsSummary ( {
@@ -419,6 +431,7 @@ const initCmd = new Command({
419
431
shouldExecutePipeline,
420
432
httpProxy,
421
433
httpsProxy,
434
+ noProxy,
422
435
appProxy,
423
436
appProxyHost,
424
437
} ) ;
@@ -455,18 +468,7 @@ const initCmd = new Command({
455
468
installationPlan = new InstallationPlan ( { progressReporter, errHandler : handleError } ) ;
456
469
}
457
470
458
- if ( httpProxy ) {
459
- envVars . push ( `http_proxy=${ httpProxy } ` ) ;
460
- envVars . push ( `HTTP_PROXY=${ httpProxy } ` ) ;
461
- }
462
- if ( httpsProxy ) {
463
- envVars . push ( `https_proxy=${ httpsProxy } ` ) ;
464
- envVars . push ( `HTTPS_PROXY=${ httpsProxy } ` ) ;
465
- }
466
- if ( noProxy ) {
467
- envVars . push ( `no_proxy=${ noProxy } ` ) ;
468
- envVars . push ( `NO_PROXY=${ noProxy } ` ) ;
469
- }
471
+ addProxyVariables ( envVars , { httpsProxy, httpProxy, noProxy } ) ;
470
472
471
473
// save the answers for backup
472
474
_argv [ 'kube-context-name' ] = kubeContextName ;
@@ -596,19 +598,17 @@ const initCmd = new Command({
596
598
func : async ( ) => {
597
599
const reName = installationPlan . getContext ( 'runtimeName' ) ;
598
600
const re = await sdk . runtimeEnvs . get ( { name : reName } ) ;
599
- let currentEnvVars = _ . get ( re , 'runtimeScheduler.envVars' , { } ) ;
600
- const envVarsAsObject = envVars . reduce ( ( acc , current ) => {
601
- const parts = current . split ( '=' ) ;
602
- // eslint-disable-next-line prefer-destructuring
603
- acc [ parts [ 0 ] ] = parts [ 1 ] ;
604
- return acc ;
605
- } , { } ) ;
606
- currentEnvVars = _ . merge ( currentEnvVars , envVarsAsObject ) ;
607
- const body = _ . set ( re , 'runtimeScheduler.envVars' , currentEnvVars ) ;
608
- await sdk . runtimeEnvs . update ( { name : reName } , _ . merge ( re , body ) ) ;
601
+ const envVarsObj = keyValueArrayToObject ( envVars ) ;
602
+ const currentEngineEnvVars = _ . get ( re , 'runtimeScheduler.envVars' , { } ) ;
603
+ const currentDindEnvVars = _ . get ( re , 'dockerDaemonScheduler.envVars' , { } ) ;
604
+ const newEngineEnvVars = _ . merge ( currentEngineEnvVars , envVarsObj ) ;
605
+ const newDindEnvVars = _ . merge ( currentDindEnvVars , envVarsObj ) ;
606
+ _ . set ( re , 'runtimeScheduler.envVars' , newEngineEnvVars ) ;
607
+ _ . set ( re , 'dockerDaemonScheduler.envVars' , newDindEnvVars ) ;
608
+ await sdk . runtimeEnvs . update ( { name : reName } , re ) ;
609
609
console . log ( `Runtime environment "${ colors . cyan ( reName ) } " has been updated with env vars` ) ;
610
610
} ,
611
- condition : ! ! envVars ,
611
+ condition : envVars . length ,
612
612
} ) ;
613
613
614
614
// set runtime as default
@@ -662,6 +662,7 @@ const initCmd = new Command({
662
662
verbose,
663
663
kubeNodeSelector,
664
664
dockerRegistry,
665
+ envVars,
665
666
valuesFile,
666
667
setValue,
667
668
setFile,
@@ -681,7 +682,10 @@ const initCmd = new Command({
681
682
verbose,
682
683
kubeConfigPath,
683
684
dockerRegistry,
685
+ envVars,
684
686
valuesFile,
687
+ setValue,
688
+ setFile,
685
689
appProxyHost,
686
690
appProxyIngressClass,
687
691
} ) ;
@@ -763,6 +767,9 @@ const initCmd = new Command({
763
767
'kube-context-name' : kubeContextName ,
764
768
'kube-namespace' : kubeNamespace ,
765
769
'docker-registry' : dockerRegistry ,
770
+ 'env-vars' : envVars ,
771
+ 'set-value' : setValue ,
772
+ 'set-file' : setFile ,
766
773
token : _ . get ( sdk , 'config.context.token' ) ,
767
774
verbose,
768
775
noExit : true , // to prevent if from calling inner: process.exit()
0 commit comments