diff --git a/lib/interface/cli/commands/hybrid/execute-test-pipeline.cmd.js b/lib/interface/cli/commands/hybrid/execute-test-pipeline.cmd.js new file mode 100644 index 000000000..4fa0680db --- /dev/null +++ b/lib/interface/cli/commands/hybrid/execute-test-pipeline.cmd.js @@ -0,0 +1,37 @@ +const Command = require('../../Command'); +const runnerRoot = require('../root/runner.cmd'); +const colors = require('colors'); +const InstallationPlan = require('./InstallationPlan'); +const { addPipelineToInstallationPlan } = require('./pipeline-helper'); +const { createErrorHandler } = require('./helper'); + +const handleError = createErrorHandler(`\nIf you had any issues with the installation please report them at:\ + ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`); + +const defaultDockerRegistry = 'quay.io'; + +const command = new Command({ + command: 'execute-test-pipeline', + parent: runnerRoot, + requiresAuthentication: true, + description: 'Executes test pipeline', + webDocs: { + category: 'Runner', + title: 'Execute test pipeline', + }, + builder: yargs => yargs + .option('runtime-name', { + describe: 'Runtime name to execute pipeline on', + }), + handler: async (argv) => { + const { runtimeName } = argv; + + const installationPlan = new InstallationPlan({ errHandler: handleError }); + installationPlan.addContext('runtimeName', runtimeName ? runtimeName.trim() : runtimeName); + await addPipelineToInstallationPlan(installationPlan, defaultDockerRegistry, true); + await installationPlan.execute(); + process.exit(); // TODO : This is not needed - needed to be fixed + }, +}); + +module.exports = command; diff --git a/lib/interface/cli/commands/hybrid/init.cmd.js b/lib/interface/cli/commands/hybrid/init.cmd.js index abb1eca3f..c84c9db91 100644 --- a/lib/interface/cli/commands/hybrid/init.cmd.js +++ b/lib/interface/cli/commands/hybrid/init.cmd.js @@ -19,9 +19,6 @@ const installationProgress = require('./installation-process'); const { to } = require('./../../../../logic/cli-config/errors/awaitTo'); const { createErrorHandler, - createTestPipeline, - executeTestPipeline, - updateTestPipelineRuntime, drawCodefreshFiglet, getDefaultRuntime, getRecommendedKubeNamespace, @@ -40,6 +37,9 @@ const { const InstallationPlan = require('./InstallationPlan'); const { produceVenonaKeys } = require('./key-helper'); const { array } = require('yargs'); +const { + addPipelineToInstallationPlan, +} = require('./pipeline-helper'); const defaultDockerRegistry = 'quay.io'; const handleError = createErrorHandler(`\nIf you had any issues with the installation please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`); @@ -318,10 +318,6 @@ const initCmd = new Command({ httpsProxy = httpsProxy || detectedProxyVars.httpsProxy; noProxy = noProxy || detectedProxyVars.noProxy; - if (shouldUseHelm) { - shouldExecutePipeline = false; - } - if (noQuestions) { // use defaults kubeContextName = kubeContextName || getKubeContext(kubeConfigPath); @@ -415,7 +411,7 @@ const initCmd = new Command({ type: 'confirm', name: 'shouldExecutePipeline', default: INSTALLATION_DEFAULTS.RUN_DEMO_PIPELINE, - message: 'Run demo pipeline after install?', + message: shouldUseHelm ? 'Create demo pipeline?' : 'Run demo pipeline after install?', }); } @@ -503,7 +499,7 @@ const initCmd = new Command({ bypassDownload, }, installationEvent: installationProgress.events.ACCEPTANCE_TESTS_RAN, - condition: !skipClusterTest, + condition: !skipClusterTest && !shouldUseHelm, }); // generate new agent name @@ -834,6 +830,20 @@ const initCmd = new Command({ condition: !shouldUseHelm, }); + + function shouldInstallMonitoringFn() { + if (!installMonitor) { + return false; + } + + if (isInCluster() || skipClusterIntegration) { + console.log('Monitor component cannot be installed without cluster integration, you can install it seperately using: "codefresh install monitor"'); + return false; + } + + return true; + } + // install monitoring installationPlan.addStep({ name: 'install cluster monitoring', @@ -858,22 +868,7 @@ const initCmd = new Command({ successMessage: 'Successfully installed cluster monitoring', installationEvent: installationProgress.events.MONITOR_INSTALLED, executeOnDryRun: true, - condition: async () => { - if (shouldUseHelm) { - return false; - } - - if (!installMonitor) { - return false; - } - - if (isInCluster() || skipClusterIntegration) { - console.log('Monitor component cannot be installed without cluster integration, you can install it seperately using: "codefresh install monitor"'); - return false; - } - - return true; - }, + condition: !shouldUseHelm && shouldInstallMonitoringFn, }); // helm value files if its enabled @@ -888,6 +883,16 @@ const initCmd = new Command({ kubeNamespace, ); + const _appProxy = { + enabled: appProxy || false, + host: appProxyHost || '', + }; + + const monitor = { + enabled: shouldInstallMonitoringFn(), + clusterId: kubeContextName, + }; + const global = { namespace: kubeNamespace, codefreshHost: sdk.config.context.url, @@ -899,7 +904,7 @@ const initCmd = new Command({ keys, }; - const content = JSON.stringify({ global }, null, 4); + const content = JSON.stringify({ appProxy: _appProxy, monitor, global }, null, 4); fs.writeFileSync( helmValuesFile, @@ -914,51 +919,7 @@ const initCmd = new Command({ // Post Installation if (shouldExecutePipeline) { - const pipelines = await sdk.pipelines.list({ id: `${INSTALLATION_DEFAULTS.PROJECT_NAME}/${INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME}` }); - const testPipelineExists = !!_.get(pipelines, 'docs.length'); - - if (!testPipelineExists) { - installationPlan.addStep({ - name: 'create test pipeline', - func: async () => { - await createTestPipeline( - installationPlan.getContext('runtimeName'), - INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME, - ['echo hello Codefresh Runner!'], - dockerRegistry, - ); - }, - installationEvent: installationProgress.events.PIPELINE_CREATED, - }); - } else { - installationPlan.addStep({ - name: 'update test pipeline runtime', - func: async () => { - await updateTestPipelineRuntime( - undefined, - installationPlan.getContext('runtimeName'), - INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME, - dockerRegistry, - ); - }, - errMessage: colors.yellow('*warning* could not update test pipeline runtime, you can' + - ' change it manually if you want to run it again on this runtime'), - successMessage: 'Updated test pipeline runtime', - exitOnError: false, - }); - } - - installationPlan.addStep({ - name: 'execute test pipeline', - func: async () => { - await executeTestPipeline( - installationPlan.getContext('runtimeName'), - INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME, - ); - }, - errMessage: 'Failed to execute test pipeline', - installationEvent: installationProgress.events.PIPELINE_EXECUTED, - }); + await addPipelineToInstallationPlan(installationPlan, dockerRegistry, !shouldUseHelm); } await installationPlan.execute(); @@ -972,11 +933,22 @@ const initCmd = new Command({ if (installMonitor) { console.log(`Go to ${colors.blue('https://g.codefresh.io/kubernetes/services/')} to view your cluster in Codefresh dashbaord`); } + console.log(`Link to the new runtime: ${colors.blue(`https://g.codefresh.io/account-admin/account-conf/runtime-environments?runtime=${encodeURI(installationPlan.getContext('runtimeName'))}`)}`); console.log(`\nDocumentation link: ${colors.blue('https://codefresh.io/docs/docs/enterprise/codefresh-runner/#codefresh-runner-preview-release')}`); console.log(`If you had any issues with the installation please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`); await to(progressReporter.report(installationProgress.events.FINISHED, installationProgress.status.SUCCESS)); await drawCodefreshFiglet(); + + if (shouldUseHelm) { + console.log('\n\nTo install helm run:'); + console.log('helm repo add cf-runtime https://h.cfcr.io/codefresh-inc/runtime'); + console.log(`kubectl create ns ${kubeNamespace}`); + console.log(`helm install cf-runtime cf-runtime/cf-runtime -f ${helmValuesFile} --namespace ${kubeNamespace}\n`); + console.log('In order to test your runner helm based installation please execute\n' + + 'codefresh runner execute-test-pipeline'); + } + process.exit(); // TODO : This is not needed - needed to be fixed }, }); diff --git a/lib/interface/cli/commands/hybrid/pipeline-helper.js b/lib/interface/cli/commands/hybrid/pipeline-helper.js new file mode 100644 index 000000000..6f1c2e589 --- /dev/null +++ b/lib/interface/cli/commands/hybrid/pipeline-helper.js @@ -0,0 +1,71 @@ +const sdk = require('../../../../logic/sdk'); +const colors = require('colors'); +const installationProgress = require('./installation-process'); +const _ = require('lodash'); + +const { + createTestPipeline, + executeTestPipeline, + updateTestPipelineRuntime, + INSTALLATION_DEFAULTS, +} = require('./helper'); + +const defaultDockerRegistry = 'quay.io'; + +async function addPipelineToInstallationPlan(installationPlan, dockerRegistry = '', executePipeline = true) { + if (!dockerRegistry) { + // eslint-disable-next-line no-param-reassign + dockerRegistry = defaultDockerRegistry; + } + + const pipelines = await sdk.pipelines.list({ id: `${INSTALLATION_DEFAULTS.PROJECT_NAME}/${INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME}` }); + const testPipelineExists = !!_.get(pipelines, 'docs.length'); + + if (!testPipelineExists) { + installationPlan.addStep({ + name: 'create test pipeline', + func: async () => { + await createTestPipeline( + installationPlan.getContext('runtimeName'), + INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME, + ['echo hello Codefresh Runner!'], + dockerRegistry, + ); + }, + installationEvent: installationProgress.events.PIPELINE_CREATED, + }); + } else { + installationPlan.addStep({ + name: 'update test pipeline runtime', + func: async () => { + await updateTestPipelineRuntime( + undefined, + installationPlan.getContext('runtimeName'), + INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME, + dockerRegistry, + ); + }, + errMessage: colors.yellow('*warning* could not update test pipeline runtime, you can' + + ' change it manually if you want to run it again on this runtime'), + successMessage: 'Updated test pipeline runtime', + exitOnError: false, + }); + } + + installationPlan.addStep({ + name: 'execute test pipeline', + func: async () => { + await executeTestPipeline( + installationPlan.getContext('runtimeName'), + INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME, + ); + }, + errMessage: 'Failed to execute test pipeline', + installationEvent: installationProgress.events.PIPELINE_EXECUTED, + condition: executePipeline, + }); +} + +module.exports = { + addPipelineToInstallationPlan, +}; diff --git a/package.json b/package.json index a854fb63a..4148b7d20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.75.16", + "version": "0.75.17", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,