1- const debug = require ( 'debug' ) ( 'codefresh:cli:create:context' ) ;
2- const _ = require ( 'lodash' ) ;
31const Command = require ( '../../Command' ) ;
4- const fs = require ( 'fs' ) ;
5- const { spawn } = require ( 'child_process' ) ;
6- const rp = require ( 'request-promise' ) ;
72const createRoot = require ( '../root/create.cmd' ) ;
8- const authManager = require ( '../../../../logic/auth' ) . manager ; // eslint-disable-line
9- const { cluster } = require ( '../../../../logic' ) . api ;
10- const CFError = require ( 'cf-errors' ) ;
11-
12- const { CODEFRESH_PATH } = require ( '../../defaults' ) ;
13- const scriptUrl = 'https://raw.githubusercontent.com/codefresh-io/k8s-dind-config/master/codefresh-k8s-configure.sh' ;
14- let filePath = `${ CODEFRESH_PATH } /runtime/codefresh-k8s-configure.sh` ;
15- const dirPath = `${ CODEFRESH_PATH } /runtime` ;
16-
17-
18- const callToScript = ( k8sScript ) => {
19- k8sScript . stdout . pipe ( process . stdout ) ;
20- k8sScript . stderr . pipe ( process . stderr ) ;
21- process . stdin . pipe ( k8sScript . stdin ) ;
22- k8sScript . on ( 'exit' , ( code ) => {
23- fs . unlink ( 'filePath' , ( error ) => {
24- if ( error ) {
25- throw error ;
26- }
27- console . log ( 'finish' ) ;
28- } ) ;
29- process . exit ( code ) ;
30- } ) ;
31- } ;
323
4+ const DEPRECATION_MESSAGE = 'Create runtime-environment is been deprecated. Please use Venona to create a runtime-environment' ;
5+ const VENONA_REPO_URL = 'https://github.com/codefresh-io/venona' ;
336
347const command = new Command ( {
358 command : 'runtime-environments [cluster]' ,
@@ -41,67 +14,9 @@ const command = new Command({
4114 title : 'Create Runtime-Environments' ,
4215 weight : 100 ,
4316 } ,
44- builder : ( yargs ) => {
45- return yargs
46- . option ( 'cluster' , {
47- describe : 'codefresh cluster integration name' ,
48- alias : 'c' ,
49- required : true ,
50- } )
51- . option ( 'namespace' , {
52- describe : 'namespace' ,
53- alias : 'n' ,
54- default : 'codefresh' ,
55- } )
56- . option ( 'kube-context' , {
57- describe : 'kubectl context name' ,
58- alias : 'kc' ,
59- } )
60- . option ( 'gcloud' , {
61- describe : 'set if your cluster provider is gcloud' ,
62- type : Boolean ,
63- } )
64- . example ( 'codefresh create re --cluster prod --namespace codefresh --kube-context kubeCodefresh' , 'Creating a runtime environment which configured to cluster prod and namespace codefresh' ) ;
65- } ,
66- handler : async ( argv ) => {
67- const currentContext = authManager . getCurrentContext ( ) ;
68- const { namespace } = argv ;
69- const clusterName = argv . cluster ;
70- const context = argv [ 'kube-context' ] || '' ;
71- const gcloud = argv . gcloud || '' ;
72- const clusters = await cluster . getAllClusters ( ) ;
73- const validCluster = _ . find ( clusters , ( c ) => {
74- return _ . isEqual ( c . info . name , clusterName ) ;
75- } ) ;
76- if ( validCluster ) {
77- if ( ! process . env . LOCAL ) {
78- if ( ! fs . existsSync ( CODEFRESH_PATH ) ) {
79- fs . mkdirSync ( CODEFRESH_PATH ) ;
80- fs . mkdirSync ( dirPath ) ;
81- } else if ( ! fs . existsSync ( dirPath ) ) {
82- fs . mkdirSync ( dirPath ) ;
83- }
84- const options = {
85- url : scriptUrl ,
86- method : 'GET' ,
87- } ;
88- const response = await rp ( options ) ;
89- fs . writeFile ( filePath , response , ( err ) => {
90- if ( err ) {
91- throw err ;
92- }
93- fs . chmodSync ( filePath , '644' ) ;
94- const k8sScript = spawn ( 'bash' , [ filePath , '--api-token' , currentContext . token , '--api-host' , currentContext . url , '--namespace' , namespace , '--image-tag' , 'master' , '--remote' , '--context' , context , '--gcloud' , gcloud , clusterName ] ) ;
95- callToScript ( k8sScript ) ;
96- } ) ;
97- } else {
98- filePath = './codefresh-k8s-configure.sh' ;
99- const k8sScript = spawn ( 'bash' , [ filePath , '--api-token' , currentContext . token , '--api-host' , currentContext . url , '--namespace' , namespace , '--context' , context , '--image-tag' , 'master' , '--gcloud' , gcloud , clusterName ] ) ;
100- callToScript ( k8sScript ) ;
101- }
102- } else {
103- throw new CFError ( `No cluster exists with the name: ${ clusterName } ` ) ;
104- }
17+ handler : async ( ) => {
18+ console . log ( `${ DEPRECATION_MESSAGE } ${ VENONA_REPO_URL } ` ) ;
19+ process . exit ( 1 ) ;
10520 } ,
10621} ) ;
10722
0 commit comments