@@ -34,6 +34,7 @@ const INSTALLATION_DEFAULTS = {
3434 COMPONENTS_FOLDER : 'components' ,
3535 KUBECONFIG_PATH : path . join ( homedir ( ) , '.kube' , 'config' ) ,
3636 SAAS_RUNTIME : 'SAAS runtime' ,
37+ HELM_FILE_PATH : path . join ( process . cwd ( ) , 'generated_values.yaml' ) ,
3738} ;
3839
3940const RUNTIME_IMAGES = {
@@ -349,18 +350,33 @@ async function getRecommendedKubeNamespace(kubeconfigPath, kubeContextName) {
349350 return name ;
350351}
351352
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 ;
357375 }
376+
377+ throw new Error ( `cannot bypass download, ${ componentName } not found, aborting.` ) ;
358378 }
359- return false ;
360- }
361379
362- async function attemptDownload ( location , component ) {
363- console . log ( 'Downloading installer' ) ;
364380 const downloader = new Downloader ( {
365381 progress : new cliProgress . SingleBar (
366382 {
@@ -372,61 +388,30 @@ async function attemptDownload(location, component) {
372388 location,
373389 } ) ;
374390
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` ) ;
382395
383- const [ error ] = await attemptDownload ( location , components . venona ) ;
384- if ( error ) {
385- if ( await bypassDownloadSuccess ( ! bypassDownload , components . venona . local . dir , components . venona . local . binary ) ) {
386396 return path . resolve ( process . cwd ( ) , INSTALLATION_DEFAULTS . COMPONENTS_FOLDER ) ;
387397 }
388398
389- console . log ( 'Failed to find component, aborting' ) ;
390- throw error ;
399+ throw new Error ( `failed to download ${ componentName } , aborting.` ) ;
391400 }
392401
393402 return location ;
394403}
395404
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 ) ;
413407}
414408
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+ }
425412
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 ) ;
430415}
431416
432417async function downloadHybridComponents ( location , bypassDownload = false ) {
0 commit comments