@@ -14,10 +14,11 @@ const DEFAULTS = require('../../defaults');
1414const sdk = require ( '../../../../logic/sdk' ) ;
1515const installationProgress = require ( './installation-process' ) ;
1616const { to } = require ( './../../../../logic/cli-config/errors/awaitTo' ) ;
17- const { createErrorHandler } = require ( './helper' ) ;
1817const YAML = require ( 'yaml' ) ;
1918const fs = require ( 'fs' ) ;
2019const {
20+ createErrorHandler,
21+ keyValueArrayToObject,
2122 createTestPipeline,
2223 executeTestPipeline,
2324 updateTestPipelineRuntime,
@@ -34,6 +35,8 @@ const {
3435 detectProxy,
3536 keyValueAsStringToObject,
3637 getRuntimeImagesWithRegistryUrl,
38+ addProxyVariables,
39+ objectToKeyValueArray,
3740 INSTALLATION_DEFAULTS ,
3841} = require ( './helper' ) ;
3942const InstallationPlan = require ( './InstallationPlan' ) ;
@@ -57,6 +60,7 @@ function printInstallationOptionsSummary({
5760 shouldExecutePipeline,
5861 httpProxy,
5962 httpsProxy,
63+ noProxy,
6064 appProxy,
6165 appProxyHost,
6266} ) {
@@ -67,6 +71,7 @@ function printInstallationOptionsSummary({
6771 4. Execute demo pipeline after install: ${ colors . cyan ( ! ! shouldExecutePipeline ) }
6872 5. HTTP proxy: ${ httpProxy ? colors . cyan ( httpProxy ) : 'none' }
6973 6. HTTPS proxy: ${ httpsProxy ? colors . cyan ( httpsProxy ) : 'none' }
74+ 7. No proxy: ${ noProxy ? colors . cyan ( noProxy ) : 'none' }
7075 ` ;
7176
7277 if ( appProxy ) {
@@ -146,7 +151,7 @@ const initCmd = new Command({
146151 describe : 'Path to kubeconfig file (default is $HOME/.kube/config)' ,
147152 } )
148153 . 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) ' ,
150155 } )
151156 . option ( 'set-value' , {
152157 describe : 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes' ,
@@ -171,8 +176,9 @@ const initCmd = new Command({
171176 describe : 'Print logs' ,
172177 } )
173178 . 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 ' ,
175180 type : array ,
181+ default : [ ] ,
176182 } )
177183 . option ( 'app-proxy' , {
178184 describe : 'install app proxy component (default false)' ,
@@ -191,7 +197,9 @@ const initCmd = new Command({
191197 describe : 'docker daemon access (default true)' ,
192198 default : true ,
193199 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)' ) ,
195203 handler : async ( argv ) => {
196204 let resumedInstallation = false ;
197205
@@ -225,16 +233,16 @@ const initCmd = new Command({
225233 'set-value' : setValue ,
226234 'set-file' : setFile ,
227235 'skip-cluster-test' : skipClusterTest ,
228- 'docker-registry' : dockerRegistry ,
229236 'app-proxy-ingress-class' : appProxyIngressClass ,
237+ 'env-vars' : envVars ,
230238 } = _argv ;
231239 let {
232240 yes : noQuestions ,
233241 'kube-context-name' : kubeContextName ,
234242 'kube-namespace' : kubeNamespace ,
235243 'set-default-runtime' : shouldMakeDefaultRe ,
244+ 'docker-registry' : dockerRegistry ,
236245 'exec-demo-pipeline' : shouldExecutePipeline ,
237- 'env-vars' : envVars ,
238246 'http-proxy' : httpProxy ,
239247 'https-proxy' : httpsProxy ,
240248 'no-proxy' : noProxy ,
@@ -275,17 +283,23 @@ const initCmd = new Command({
275283 if ( _ . get ( valuesObj , 'AppProxy' ) ) {
276284 appProxy = true ;
277285 }
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' ) ;
280288 }
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' ) ;
283291 }
284292 if ( appProxy && ! appProxyHost ) {
285293 handleError ( new Error ( 'no hostname provided' ) , 'cannot install app-proxy component without a hostname' , undefined , undefined , true ) ;
286294 }
287295 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' ) ;
289303 }
290304 }
291305 if ( ! url ) {
@@ -303,10 +317,7 @@ const initCmd = new Command({
303317 httpProxy = httpProxy || detectedProxyVars . httpProxy ;
304318 httpsProxy = httpsProxy || detectedProxyVars . httpsProxy ;
305319 noProxy = noProxy || detectedProxyVars . noProxy ;
306- envVars = envVars || [ ] ;
307- if ( ! Array . isArray ( envVars ) ) {
308- envVars = [ envVars ] ;
309- }
320+
310321 if ( noQuestions ) {
311322 // use defaults
312323 kubeContextName = kubeContextName || getKubeContext ( kubeConfigPath ) ;
@@ -344,7 +355,7 @@ const initCmd = new Command({
344355 type : 'input' ,
345356 name : 'httpProxy' ,
346357 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 ?' ,
348359 } ) ;
349360 }
350361
@@ -353,7 +364,7 @@ const initCmd = new Command({
353364 type : 'input' ,
354365 name : 'httpsProxy' ,
355366 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 ?' ,
357368
358369 } ) ;
359370 }
@@ -362,7 +373,7 @@ const initCmd = new Command({
362373 type : 'input' ,
363374 name : 'noProxy' ,
364375 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 ?' ,
366377
367378 } ) ;
368379 }
@@ -409,7 +420,8 @@ const initCmd = new Command({
409420 kubeNamespace = kubeNamespace || answers . namespace ;
410421 shouldMakeDefaultRe = _ . isUndefined ( shouldMakeDefaultRe ) ? answers . shouldMakeDefaultRe : shouldMakeDefaultRe ;
411422 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 ) ;
413425 }
414426
415427 printInstallationOptionsSummary ( {
@@ -419,6 +431,7 @@ const initCmd = new Command({
419431 shouldExecutePipeline,
420432 httpProxy,
421433 httpsProxy,
434+ noProxy,
422435 appProxy,
423436 appProxyHost,
424437 } ) ;
@@ -455,18 +468,7 @@ const initCmd = new Command({
455468 installationPlan = new InstallationPlan ( { progressReporter, errHandler : handleError } ) ;
456469 }
457470
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 } ) ;
470472
471473 // save the answers for backup
472474 _argv [ 'kube-context-name' ] = kubeContextName ;
@@ -596,19 +598,17 @@ const initCmd = new Command({
596598 func : async ( ) => {
597599 const reName = installationPlan . getContext ( 'runtimeName' ) ;
598600 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 ) ;
609609 console . log ( `Runtime environment "${ colors . cyan ( reName ) } " has been updated with env vars` ) ;
610610 } ,
611- condition : ! ! envVars ,
611+ condition : envVars . length ,
612612 } ) ;
613613
614614 // set runtime as default
@@ -662,6 +662,7 @@ const initCmd = new Command({
662662 verbose,
663663 kubeNodeSelector,
664664 dockerRegistry,
665+ envVars,
665666 valuesFile,
666667 setValue,
667668 setFile,
@@ -681,7 +682,10 @@ const initCmd = new Command({
681682 verbose,
682683 kubeConfigPath,
683684 dockerRegistry,
685+ envVars,
684686 valuesFile,
687+ setValue,
688+ setFile,
685689 appProxyHost,
686690 appProxyIngressClass,
687691 } ) ;
@@ -763,6 +767,9 @@ const initCmd = new Command({
763767 'kube-context-name' : kubeContextName ,
764768 'kube-namespace' : kubeNamespace ,
765769 'docker-registry' : dockerRegistry ,
770+ 'env-vars' : envVars ,
771+ 'set-value' : setValue ,
772+ 'set-file' : setFile ,
766773 token : _ . get ( sdk , 'config.context.token' ) ,
767774 verbose,
768775 noExit : true , // to prevent if from calling inner: process.exit()
0 commit comments