@@ -10,9 +10,12 @@ const { followLogs } = require('../../helpers/logs');
1010const ProgressEvents = require ( '../../helpers/progressEvents' ) ;
1111const cliProgress = require ( 'cli-progress' ) ;
1212const figlet = require ( 'figlet' ) ;
13+ const path = require ( 'path' ) ;
1314const {
1415 components, Runner, Downloader, CommonProgressFormat,
16+ CODEFRESH_PATH ,
1517} = require ( './../../../../binary' ) ;
18+ const { pathExists } = require ( '../../helpers/general' ) ;
1619
1720const INSTALLATION_DEFAULTS = {
1821 NAMESPACE : 'codefresh' ,
@@ -23,6 +26,7 @@ const INSTALLATION_DEFAULTS = {
2326 CF_CONTEXT_NAME : 'cf-runner' ,
2427 STORAGE_CLASS_PREFIX : 'dind-local-volumes-runner' ,
2528 RESUME_OLD_INSTALLATION : true ,
29+ COMPONENTS_FOLDER : 'components' ,
2630} ;
2731
2832const maxRuntimeNameLength = 63 ;
@@ -308,7 +312,7 @@ async function getRecommendedKubeNamespace(kubeconfigPath, kubeContextName) {
308312 return name ;
309313}
310314
311- async function _downloadVeonona ( ) {
315+ async function downloadVeonona ( location = CODEFRESH_PATH ) {
312316 const downloader = new Downloader ( {
313317 progress : new cliProgress . SingleBar (
314318 {
@@ -317,13 +321,57 @@ async function _downloadVeonona() {
317321 } ,
318322 cliProgress . Presets . shades_classic ,
319323 ) ,
324+ location,
320325 } ) ;
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 } ` ) ;
322370}
323371
324372async function runClusterAcceptanceTests ( { kubeNamespace, kubeConfigPath } ) {
325- await _downloadVeonona ( ) ;
326- const componentRunner = new Runner ( ) ;
373+ const binLocation = await downloadVeonona ( ) ;
374+ const componentRunner = new Runner ( binLocation ) ;
327375 const cmd = [ 'test' , '--log-formtter' , DefaultLogFormatter ] ;
328376 if ( kubeNamespace ) {
329377 cmd . push ( '--kube-namespace' ) ;
@@ -353,8 +401,8 @@ async function installAgent({
353401 verbose, // --verbose
354402 logFormatting = DefaultLogFormatter , // --log-formtter
355403} ) {
356- await _downloadVeonona ( ) ;
357- const componentRunner = new Runner ( ) ;
404+ const binLocation = await downloadVeonona ( ) ;
405+ const componentRunner = new Runner ( binLocation ) ;
358406 const cmd = [
359407 'install' ,
360408 'agent' ,
@@ -422,8 +470,8 @@ async function installRuntime({
422470 storageClassName, // --storage-class
423471 logFormatting = DefaultLogFormatter , // --log-formtter
424472} ) {
425- await _downloadVeonona ( ) ;
426- const componentRunner = new Runner ( ) ;
473+ const binLocation = await downloadVeonona ( ) ;
474+ const componentRunner = new Runner ( binLocation ) ;
427475 const cmd = [
428476 'install' ,
429477 'runtime' ,
@@ -487,8 +535,8 @@ async function attachRuntime({
487535 runtimeName, // --runtimeName
488536 logFormatting = DefaultLogFormatter , // --log-formtter
489537} ) {
490- await _downloadVeonona ( ) ;
491- const componentRunner = new Runner ( ) ;
538+ const binLocation = await downloadVeonona ( ) ;
539+ const componentRunner = new Runner ( binLocation ) ;
492540 const cmd = [
493541 'attach' ,
494542 '--kube-context-name' ,
@@ -615,6 +663,9 @@ module.exports = {
615663 newRuntimeName,
616664 newAgentName,
617665 parseNodeSelector,
666+ downloadRelatedComponents : downloadHybridComponents ,
667+ downloadSteveDore,
668+ downloadVeonona,
618669 INSTALLATION_DEFAULTS ,
619670 DefaultLogFormatter,
620671} ;
0 commit comments