1
1
/* eslint-disable max-len */
2
+ const fs = require ( 'fs' ) ;
3
+
2
4
const Command = require ( '../../Command' ) ;
3
5
const runnerRoot = require ( '../root/runner.cmd' ) ;
4
6
const inquirer = require ( 'inquirer' ) ;
@@ -36,13 +38,14 @@ const {
36
38
INSTALLATION_DEFAULTS ,
37
39
} = require ( './helper' ) ;
38
40
const InstallationPlan = require ( './InstallationPlan' ) ;
41
+ const { produceVenonaKeys } = require ( './key-helper' ) ;
39
42
const { array } = require ( 'yargs' ) ;
40
43
41
44
const defaultDockerRegistry = 'quay.io' ;
42
45
const handleError = createErrorHandler ( `\nIf you had any issues with the installation please report them at: ${ colors . blue ( 'https://github.com/codefresh-io/cli/issues/new' ) } ` ) ;
43
46
44
47
async function isNewAccount ( ) {
45
- const [ pipelines , err ] = await to ( sdk . pipelines . list ( { } ) ) ;
48
+ const [ pipelines , err ] = await to ( sdk . pipelines . list ( { } ) ) ;
46
49
if ( ! err && _ . isArray ( _ . get ( pipelines , 'docs' ) ) ) {
47
50
return ! pipelines . docs . length ;
48
51
}
@@ -61,6 +64,7 @@ function printInstallationOptionsSummary({
61
64
appProxy,
62
65
appProxyHost,
63
66
dryRun,
67
+ shouldUseHelm,
64
68
} ) {
65
69
let summary = `\n${ colors . green ( 'Installation options summary:' ) }
66
70
1. Kubernetes Context: ${ colors . cyan ( kubeContextName ) }
@@ -78,6 +82,9 @@ function printInstallationOptionsSummary({
78
82
if ( dryRun ) {
79
83
summary += '**** running in dry-run mode ****' ;
80
84
}
85
+ if ( shouldUseHelm ) {
86
+ summary += '**** running in helm values generation mode ****' ;
87
+ }
81
88
console . log ( summary ) ;
82
89
}
83
90
@@ -104,6 +111,10 @@ const initCmd = new Command({
104
111
. option ( 'url' , {
105
112
describe : 'Codefresh system custom url' ,
106
113
} )
114
+ . option ( 'generate-helm-values-file' , {
115
+ describe : 'Path to the new generated helm values file' ,
116
+ type : 'string' ,
117
+ } )
107
118
. option ( 'kube-context-name' , {
108
119
describe : 'Name of the Kubernetes context on which runner should be installed [$CF_ARG_KUBE_CONTEXT_NAME]' ,
109
120
} )
@@ -246,6 +257,7 @@ const initCmd = new Command({
246
257
const {
247
258
'kube-node-selector' : kubeNodeSelector ,
248
259
'build-node-selector' : buildNodeSelector ,
260
+ 'generate-helm-values-file' : helmValuesFile ,
249
261
tolerations,
250
262
'kube-config-path' : kubeConfigPath ,
251
263
'storage-class-name' : storageClassName ,
@@ -274,6 +286,9 @@ const initCmd = new Command({
274
286
'dry-run' : dryRun ,
275
287
'bypass-download' : bypassDownload
276
288
} = _argv ;
289
+
290
+ const shouldUseHelm = ! ! helmValuesFile ;
291
+
277
292
let {
278
293
'kube-context-name' : kubeContextName ,
279
294
'kube-namespace' : kubeNamespace ,
@@ -303,6 +318,10 @@ const initCmd = new Command({
303
318
httpsProxy = httpsProxy || detectedProxyVars . httpsProxy ;
304
319
noProxy = noProxy || detectedProxyVars . noProxy ;
305
320
321
+ if ( shouldUseHelm ) {
322
+ shouldExecutePipeline = false ;
323
+ }
324
+
306
325
if ( noQuestions ) {
307
326
// use defaults
308
327
kubeContextName = kubeContextName || getKubeContext ( kubeConfigPath ) ;
@@ -420,6 +439,7 @@ const initCmd = new Command({
420
439
appProxy,
421
440
appProxyHost,
422
441
dryRun,
442
+ shouldUseHelm,
423
443
} ) ;
424
444
425
445
if ( token ) {
@@ -538,6 +558,7 @@ const initCmd = new Command({
538
558
} ,
539
559
installationEvent : installationProgress . events . AGENT_INSTALLED ,
540
560
executeOnDryRun : true ,
561
+ condition : ! shouldUseHelm ,
541
562
} ) ;
542
563
543
564
// generate new runtime name
@@ -709,6 +730,7 @@ const initCmd = new Command({
709
730
} ,
710
731
installationEvent : installationProgress . events . RUNTIME_INSTALLED ,
711
732
executeOnDryRun : true ,
733
+ condition : ! shouldUseHelm ,
712
734
} ) ;
713
735
714
736
installationPlan . addStep ( {
@@ -733,7 +755,7 @@ const initCmd = new Command({
733
755
installationPlan . addContext ( 'appProxyIP' , `${ appProxyUrl } ` ) ;
734
756
} ,
735
757
installationEvent : installationProgress . events . APP_PROXY_INSTALLED ,
736
- condition : ! ! appProxy ,
758
+ condition : ! ! appProxy && ! shouldUseHelm ,
737
759
executeOnDryRun : true ,
738
760
} ) ;
739
761
@@ -751,7 +773,13 @@ const initCmd = new Command({
751
773
await sdk . runtimeEnvs . update ( { name : reName } , _ . merge ( re , body ) ) ;
752
774
console . log ( `Runtime environment "${ colors . cyan ( reName ) } " has been updated with the app proxy` ) ;
753
775
} ,
754
- condition : async ( ) => installationPlan . getContext ( 'appProxyIP' ) ,
776
+ condition : async ( ) => {
777
+ if ( shouldUseHelm ) {
778
+ return false ;
779
+ }
780
+
781
+ return installationPlan . getContext ( 'appProxyIP' ) ;
782
+ } ,
755
783
} ) ;
756
784
757
785
// update agent with new runtime
@@ -802,6 +830,7 @@ const initCmd = new Command({
802
830
} ,
803
831
installationEvent : installationProgress . events . RUNNER_INSTALLED ,
804
832
executeOnDryRun : true ,
833
+ condition : ! shouldUseHelm ,
805
834
} ) ;
806
835
807
836
// install monitoring
@@ -829,6 +858,10 @@ const initCmd = new Command({
829
858
installationEvent : installationProgress . events . MONITOR_INSTALLED ,
830
859
executeOnDryRun : true ,
831
860
condition : async ( ) => {
861
+ if ( shouldUseHelm ) {
862
+ return false ;
863
+ }
864
+
832
865
if ( ! installMonitor ) {
833
866
return false ;
834
867
}
@@ -842,10 +875,47 @@ const initCmd = new Command({
842
875
} ,
843
876
} ) ;
844
877
878
+ // helm value files if its enabled
879
+ installationPlan . addStep ( {
880
+ name : 'generate helm value files' ,
881
+ func : async ( ) => {
882
+ const runtimeNameContext = installationPlan . getContext ( 'runtimeName' ) ;
883
+ const agent = installationPlan . getContext ( 'agent' ) ;
884
+
885
+ const keys = await produceVenonaKeys (
886
+ _ . get ( sdk , 'config.context.token' ) ,
887
+ kubeNamespace ,
888
+ ) ;
889
+
890
+ const global = {
891
+ namespace : kubeNamespace ,
892
+ codefreshHost : sdk . config . context . url ,
893
+ agentToken : agent . token ,
894
+ agentId : agent . id ,
895
+ agentName : agent . name ,
896
+ accountId : agent . account ,
897
+ runtimeName : runtimeNameContext ,
898
+ keys,
899
+ } ;
900
+
901
+ const content = JSON . stringify ( { global } , null , 4 ) ;
902
+
903
+ fs . writeFileSync (
904
+ helmValuesFile ,
905
+ content ,
906
+ {
907
+ encoding : 'utf8' ,
908
+ } ,
909
+ ) ;
910
+ } ,
911
+ condition : shouldUseHelm ,
912
+ } ) ;
913
+
845
914
// Post Installation
846
915
if ( shouldExecutePipeline ) {
847
916
const pipelines = await sdk . pipelines . list ( { id : `${ INSTALLATION_DEFAULTS . PROJECT_NAME } /${ INSTALLATION_DEFAULTS . DEMO_PIPELINE_NAME } ` } ) ;
848
917
const testPipelineExists = ! ! _ . get ( pipelines , 'docs.length' ) ;
918
+
849
919
if ( ! testPipelineExists ) {
850
920
installationPlan . addStep ( {
851
921
name : 'create test pipeline' ,
@@ -876,6 +946,7 @@ const initCmd = new Command({
876
946
exitOnError : false ,
877
947
} ) ;
878
948
}
949
+
879
950
installationPlan . addStep ( {
880
951
name : 'execute test pipeline' ,
881
952
func : async ( ) => {
@@ -891,9 +962,12 @@ const initCmd = new Command({
891
962
892
963
await installationPlan . execute ( ) ;
893
964
894
- console . log ( colors . green ( '\nRunner Status:' ) ) ;
895
- await getAgents . handler ( { } ) ;
896
- console . log ( '' ) ;
965
+ if ( ! shouldUseHelm ) {
966
+ console . log ( colors . green ( '\nRunner Status:' ) ) ;
967
+ await getAgents . handler ( { } ) ;
968
+ console . log ( '' ) ;
969
+ }
970
+
897
971
if ( installMonitor ) {
898
972
console . log ( `Go to ${ colors . blue ( 'https://g.codefresh.io/kubernetes/services/' ) } to view your cluster in Codefresh dashbaord` ) ;
899
973
}
0 commit comments