@@ -10,9 +10,12 @@ const { followLogs } = require('../../helpers/logs');
10
10
const ProgressEvents = require ( '../../helpers/progressEvents' ) ;
11
11
const cliProgress = require ( 'cli-progress' ) ;
12
12
const figlet = require ( 'figlet' ) ;
13
+ const path = require ( 'path' ) ;
13
14
const {
14
15
components, Runner, Downloader, CommonProgressFormat,
16
+ CODEFRESH_PATH ,
15
17
} = require ( './../../../../binary' ) ;
18
+ const { pathExists } = require ( '../../helpers/general' ) ;
16
19
17
20
const INSTALLATION_DEFAULTS = {
18
21
NAMESPACE : 'codefresh' ,
@@ -23,6 +26,7 @@ const INSTALLATION_DEFAULTS = {
23
26
CF_CONTEXT_NAME : 'cf-runner' ,
24
27
STORAGE_CLASS_PREFIX : 'dind-local-volumes-runner' ,
25
28
RESUME_OLD_INSTALLATION : true ,
29
+ COMPONENTS_FOLDER : 'components' ,
26
30
} ;
27
31
28
32
const maxRuntimeNameLength = 63 ;
@@ -308,7 +312,7 @@ async function getRecommendedKubeNamespace(kubeconfigPath, kubeContextName) {
308
312
return name ;
309
313
}
310
314
311
- async function _downloadVeonona ( ) {
315
+ async function downloadVeonona ( location = CODEFRESH_PATH ) {
312
316
const downloader = new Downloader ( {
313
317
progress : new cliProgress . SingleBar (
314
318
{
@@ -317,13 +321,57 @@ async function _downloadVeonona() {
317
321
} ,
318
322
cliProgress . Presets . shades_classic ,
319
323
) ,
324
+ location,
320
325
} ) ;
321
- await downloader . download ( components . venona ) ;
326
+ const [ error ] = await to ( downloader . download ( components . venona ) ) ;
327
+ if ( error ) {
328
+ const newLocation = path . join ( INSTALLATION_DEFAULTS . COMPONENTS_FOLDER , components . venona . local . dir , components . venona . local . binary ) ;
329
+ if ( await pathExists ( newLocation ) ) {
330
+ console . log ( 'Failed to download installer, using binary from components folder' ) ;
331
+ return path . resolve ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ) ;
332
+ }
333
+ console . log ( 'Failed to download component, aborting' ) ;
334
+ throw error ;
335
+ }
336
+ return location ;
337
+ }
338
+ async function downloadSteveDore ( location = CODEFRESH_PATH ) {
339
+ const downloader = new Downloader ( {
340
+ progress : new cliProgress . SingleBar (
341
+ {
342
+ stopOnComplete : true ,
343
+ format : CommonProgressFormat ,
344
+ } ,
345
+ cliProgress . Presets . shades_classic ,
346
+ ) ,
347
+ location,
348
+ } ) ;
349
+ const [ error ] = await to ( downloader . download ( components . stevedore ) ) ;
350
+ if ( error ) {
351
+ const newLocation = path . join (
352
+ INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ,
353
+ components . stevedore . local . dir , components . stevedore . local . binary ,
354
+ ) ;
355
+ if ( await pathExists ( newLocation ) ) {
356
+ console . log ( 'Failed to download installer, using binary from components folder' ) ;
357
+ return path . resolve ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ) ;
358
+ }
359
+ console . log ( 'Failed to download component, aborting' ) ;
360
+ throw error ;
361
+ }
362
+ return location ;
363
+ }
364
+
365
+ async function downloadHybridComponents ( location ) {
366
+ await downloadVeonona ( location ) ;
367
+ console . log ( `Kubernetes components installer downloaded successfully to ${ location } ` ) ;
368
+ await downloadSteveDore ( location ) ;
369
+ console . log ( `Kubernetes registrator installer downloaded successfully ${ location } ` ) ;
322
370
}
323
371
324
372
async function runClusterAcceptanceTests ( { kubeNamespace, kubeConfigPath } ) {
325
- await _downloadVeonona ( ) ;
326
- const componentRunner = new Runner ( ) ;
373
+ const binLocation = await downloadVeonona ( ) ;
374
+ const componentRunner = new Runner ( binLocation ) ;
327
375
const cmd = [ 'test' , '--log-formtter' , DefaultLogFormatter ] ;
328
376
if ( kubeNamespace ) {
329
377
cmd . push ( '--kube-namespace' ) ;
@@ -353,8 +401,8 @@ async function installAgent({
353
401
verbose, // --verbose
354
402
logFormatting = DefaultLogFormatter , // --log-formtter
355
403
} ) {
356
- await _downloadVeonona ( ) ;
357
- const componentRunner = new Runner ( ) ;
404
+ const binLocation = await downloadVeonona ( ) ;
405
+ const componentRunner = new Runner ( binLocation ) ;
358
406
const cmd = [
359
407
'install' ,
360
408
'agent' ,
@@ -422,8 +470,8 @@ async function installRuntime({
422
470
storageClassName, // --storage-class
423
471
logFormatting = DefaultLogFormatter , // --log-formtter
424
472
} ) {
425
- await _downloadVeonona ( ) ;
426
- const componentRunner = new Runner ( ) ;
473
+ const binLocation = await downloadVeonona ( ) ;
474
+ const componentRunner = new Runner ( binLocation ) ;
427
475
const cmd = [
428
476
'install' ,
429
477
'runtime' ,
@@ -487,8 +535,8 @@ async function attachRuntime({
487
535
runtimeName, // --runtimeName
488
536
logFormatting = DefaultLogFormatter , // --log-formtter
489
537
} ) {
490
- await _downloadVeonona ( ) ;
491
- const componentRunner = new Runner ( ) ;
538
+ const binLocation = await downloadVeonona ( ) ;
539
+ const componentRunner = new Runner ( binLocation ) ;
492
540
const cmd = [
493
541
'attach' ,
494
542
'--kube-context-name' ,
@@ -615,6 +663,9 @@ module.exports = {
615
663
newRuntimeName,
616
664
newAgentName,
617
665
parseNodeSelector,
666
+ downloadRelatedComponents : downloadHybridComponents ,
667
+ downloadSteveDore,
668
+ downloadVeonona,
618
669
INSTALLATION_DEFAULTS ,
619
670
DefaultLogFormatter,
620
671
} ;
0 commit comments