@@ -34,6 +34,7 @@ const INSTALLATION_DEFAULTS = {
34
34
COMPONENTS_FOLDER : 'components' ,
35
35
KUBECONFIG_PATH : path . join ( homedir ( ) , '.kube' , 'config' ) ,
36
36
SAAS_RUNTIME : 'SAAS runtime' ,
37
+ HELM_FILE_PATH : path . join ( process . cwd ( ) , 'generated_values.yaml' ) ,
37
38
} ;
38
39
39
40
const RUNTIME_IMAGES = {
@@ -349,18 +350,33 @@ async function getRecommendedKubeNamespace(kubeconfigPath, kubeContextName) {
349
350
return name ;
350
351
}
351
352
352
- async function bypassDownloadSuccess ( shouldBypass , localDir , localBin ) {
353
- if ( shouldBypass ) {
354
- const newLocation = path . join ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER , localDir , localBin ) ;
355
- if ( await pathExists ( newLocation ) ) {
356
- return true ;
353
+ async function getComponent ( location = CODEFRESH_PATH , component , bypassDownload ) {
354
+ const componentName = component . name || 'component' ;
355
+ const localBinLocation = path . join (
356
+ process . cwd ( ) ,
357
+ INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ,
358
+ _ . get ( component , 'local.dir' , '' ) ,
359
+ _ . get ( component , 'local.bin' , '' ) ,
360
+ ) ;
361
+
362
+ const downloadedBinLocation = path . join (
363
+ process . cwd ( ) ,
364
+ location ,
365
+ _ . get ( component , 'local.dir' , '' ) ,
366
+ _ . get ( component , 'local.bin' , '' ) ,
367
+ ) ;
368
+
369
+ if ( bypassDownload ) {
370
+ if ( await pathExists ( localBinLocation ) ) {
371
+ return path . join ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ) ;
372
+ }
373
+ if ( await pathExists ( downloadedBinLocation ) ) {
374
+ return location ;
357
375
}
376
+
377
+ throw new Error ( `cannot bypass download, ${ componentName } not found, aborting.` ) ;
358
378
}
359
- return false ;
360
- }
361
379
362
- async function attemptDownload ( location , component ) {
363
- console . log ( 'Downloading installer' ) ;
364
380
const downloader = new Downloader ( {
365
381
progress : new cliProgress . SingleBar (
366
382
{
@@ -372,61 +388,30 @@ async function attemptDownload(location, component) {
372
388
location,
373
389
} ) ;
374
390
375
- return await to ( downloader . download ( component ) ) ;
376
- }
377
-
378
- async function downloadVeonona ( location = CODEFRESH_PATH , bypassDownload = false ) {
379
- if ( await bypassDownloadSuccess ( bypassDownload , components . venona . local . dir , components . venona . local . binary ) ) {
380
- return path . resolve ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ) ;
381
- }
391
+ const [ err ] = await to ( downloader . download ( component ) ) ;
392
+ if ( err ) {
393
+ if ( await pathExists ( localBinLocation ) ) {
394
+ console . log ( `failed to download ${ componentName } , using local binary instead` ) ;
382
395
383
- const [ error ] = await attemptDownload ( location , components . venona ) ;
384
- if ( error ) {
385
- if ( await bypassDownloadSuccess ( ! bypassDownload , components . venona . local . dir , components . venona . local . binary ) ) {
386
396
return path . resolve ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ) ;
387
397
}
388
398
389
- console . log ( 'Failed to find component, aborting' ) ;
390
- throw error ;
399
+ throw new Error ( `failed to download ${ componentName } , aborting.` ) ;
391
400
}
392
401
393
402
return location ;
394
403
}
395
404
396
- async function downloadProvider ( { provider, location = CODEFRESH_PATH } , bypassDownload = false ) {
397
- const localSettings = components . gitops [ provider ] . local ;
398
-
399
- if ( await bypassDownloadSuccess ( bypassDownload , localSettings . dir , localSettings . binary ) ) {
400
- return path . resolve ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ) ;
401
- }
402
-
403
- const [ error ] = await attemptDownload ( location , components . gitops [ provider ] ) ;
404
- if ( error ) {
405
- if ( await bypassDownloadSuccess ( ! bypassDownload , localSettings . dir , localSettings . binary ) ) {
406
- return path . resolve ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ) ;
407
- }
408
-
409
- console . log ( 'Failed to find component, aborting' ) ;
410
- throw error ;
411
- }
412
- return location ;
405
+ async function downloadVeonona ( location , bypassDownload = false ) {
406
+ return await getComponent ( location , components . venona , bypassDownload ) ;
413
407
}
414
408
415
- async function downloadSteveDore ( location = CODEFRESH_PATH , bypassDownload = false ) {
416
- if ( await bypassDownloadSuccess ( bypassDownload , components . stevedore . local . dir , components . stevedore . local . binary ) ) {
417
- return path . resolve ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ) ;
418
- }
419
-
420
- const [ error ] = await attemptDownload ( location , components . stevedore ) ;
421
- if ( error ) {
422
- if ( await bypassDownloadSuccess ( ! bypassDownload , components . stevedore . local . dir , components . stevedore . local . binary ) ) {
423
- return path . resolve ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ) ;
424
- }
409
+ async function downloadProvider ( { provider, location } , bypassDownload = false ) {
410
+ return await await getComponent ( location , components . gitops [ provider ] , bypassDownload ) ;
411
+ }
425
412
426
- console . log ( 'Failed to find component, aborting' ) ;
427
- throw error ;
428
- }
429
- return location ;
413
+ async function downloadSteveDore ( location , bypassDownload = false ) {
414
+ return await getComponent ( location , components . stevedore , bypassDownload ) ;
430
415
}
431
416
432
417
async function downloadHybridComponents ( location , bypassDownload = false ) {
0 commit comments