diff --git a/lib/interface/cli/commands/agent/install.cmd.js b/lib/interface/cli/commands/agent/install.cmd.js index 605a8f292..92324cfb5 100644 --- a/lib/interface/cli/commands/agent/install.cmd.js +++ b/lib/interface/cli/commands/agent/install.cmd.js @@ -108,7 +108,7 @@ const installAgentCmd = new Command({ agent = await sdk.agents.create({ name }); // eslint-disable-next-line prefer-destructuring token = agent.token; - console.log(`An agent with name: ${colors.blue(name)} has been created\nMake sure to copy your access token now. You won’t be able to see it again`); + console.log(`A Codefresh Runner with name: ${colors.cyan(name)} has been created.\n${colors.yellow('*IMPORTANT*')} Make sure to copy your access token now and store it in a safe location. You won’t be able to see it again.`); console.log(token); } else { // take the agent id from the token @@ -120,7 +120,7 @@ const installAgentCmd = new Command({ const { subject } = agentData; if (subject.type !== 'agent') { - throw new Error('token is not assosicated with agent'); + throw new Error('token is not assosicated with a runner'); } const agentId = agentData.subject.ref; const data = await sdk.agents.get({ agentId }); @@ -133,7 +133,7 @@ const installAgentCmd = new Command({ const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic); let totalSize; events.onStart((size) => { - console.log('Downloading agent\'s installer \n'); + console.log('Downloading Codefresh Runner installer \n'); progressBar.start(size, 0); totalSize = size; }); @@ -163,7 +163,7 @@ const installAgentCmd = new Command({ events, }); if (agentInstallStatusCode !== 0) { - throw new Error(`\nAgent installation failed with code ${agentInstallStatusCode}`); + throw new Error(`\nRunner installation failed with code ${agentInstallStatusCode}`); } if (installRuntime) { await installRuntimeCmd.handler({ diff --git a/lib/interface/cli/commands/hybrid/init.cmd.js b/lib/interface/cli/commands/hybrid/init.cmd.js index 300e53bc6..23f806556 100644 --- a/lib/interface/cli/commands/hybrid/init.cmd.js +++ b/lib/interface/cli/commands/hybrid/init.cmd.js @@ -10,17 +10,20 @@ const { getConfigForSdk } = require('../../commad-line-interface'); const colors = require('colors'); const DEFAULTS = require('../../defaults'); const sdk = require('../../../../logic/sdk'); -const Output = require('../../../../output/Output'); const _ = require('lodash'); -const defaultNamespace = 'codefresh'; +const INSTALLATION_DEFAULTS = { + NAMESPACE: 'codefresh', + MAKE_DEFAULT_RE: true, + RUN_DEMO_PIPELINE: true, +}; const initCmd = new Command({ root: false, parent: runnerRoot, command: 'init', requiresAuthentication: false, - description: 'Install codefresh runner solution\'s components on kubernetes cluster', + description: 'Install Codefresh Runner solution\'s components on kubernetes cluster', webDocs: { category: 'Runner', title: 'Init', @@ -48,6 +51,19 @@ const initCmd = new Command({ .option('dry-run', { describe: 'Set to true to simulate installation', }) + .option('yes', { + describe: 'Use installation defaults (don\'t ask any questions)', + alias: 'y', + type: 'boolean', + }) + .option('set-default-runtime', { + describe: 'Set this as the default runtime environment for your Codefresh account', + type: 'boolean', + }) + .option('exec-demo-pipeline', { + describe: 'Run a demo pipeline after the installation completes', + type: 'boolean', + }) .option('in-cluster', { describe: 'Set flag if venona is been installed from inside a cluster', }) @@ -82,78 +98,100 @@ const initCmd = new Command({ 'venona-version': venonaVersion, 'kube-config-path': kubeConfigPath, 'skip-version-check': skipVersionCheck, + yes: noQuestions, verbose, name, token, url, } = argv; let { 'kube-context-name': kubeContextName, 'kube-namespace': kubeNamespace, + 'set-default-runtime': shouldMakeDefaultRe, + 'exec-demo-pipeline': shouldExecutePipeline, } = argv; if (_.get(sdk, 'config.context.isNoAuth') && !token) { console.log('Not authenticated as a Codefresh account: '); console.log('In order to install a Codefresh Runner you need to provide ' + - `an authentication token which can be generated here: ${colors.blue(`${argv.url}/user/settings`)}.` + - '\nAfter getting the token you may run this command again with the [--token] option or use the codefresh auth command to create an authenticated context.'); + `an authentication token which can be generated here: ${colors.blue(`${argv.url}/user/settings`)}` + + '\nAfter getting the token you may run this command again with the [--token] option or use the \'codefresh auth\' command to create an authenticated context.'); process.exit(1); } + if (noQuestions) { + // set defaults + kubeContextName = getKubeContext(kubeConfigPath); + kubeNamespace = INSTALLATION_DEFAULTS.NAMESPACE; + shouldMakeDefaultRe = INSTALLATION_DEFAULTS.MAKE_DEFAULT_RE; + shouldExecutePipeline = INSTALLATION_DEFAULTS.RUN_DEMO_PIPELINE; + } + const questions = []; - if (!kubeContextName) { + if (!kubeContextName && !noQuestions) { const contexts = getAllKubeContexts(kubeConfigPath); const currentKubeContext = getKubeContext(kubeConfigPath); questions.push({ type: 'list', name: 'context', - message: 'Select Kubernetes context', + message: 'Name of Kubernetes context to use', default: currentKubeContext, choices: contexts, }); } - if (!kubeNamespace) { + if (!kubeNamespace && !noQuestions) { questions.push({ type: 'input', name: 'namespace', - default: defaultNamespace, - message: 'Insert Kubernetes namespace (will be created if not exists) ', + default: INSTALLATION_DEFAULTS.NAMESPACE, + message: 'Kubernetes namespace to install into (will be created if it does not exist)', validate: value => (value !== undefined && value !== '') || 'Please enter namespace\'s name', }); } - questions.push({ - type: 'confirm', - name: 'shouldMakeDefaultRe', - default: true, - message: 'Should mark the hybrid runtime as default runtime ?', - - }); - - questions.push({ - type: 'confirm', - name: 'shouldExecutePipeline', - default: true, - message: 'Run demo pipeline ?', + if (_.isUndefined(shouldMakeDefaultRe) && !noQuestions) { + questions.push({ + type: 'confirm', + name: 'shouldMakeDefaultRe', + default: INSTALLATION_DEFAULTS.MAKE_DEFAULT_RE, + message: 'Set this as the default runtime environment for your Codefresh account? (Y/N)', + }); + } - }); + if (_.isUndefined(shouldExecutePipeline) && !noQuestions) { + questions.push({ + type: 'confirm', + name: 'shouldExecutePipeline', + default: INSTALLATION_DEFAULTS.RUN_DEMO_PIPELINE, + message: 'Run demo pipeline after install? (Y/N)', + }); + } - console.log(colors.green('This installer will guide you through the hybrid installation process')); + console.log(colors.green('This installer will guide you through the Codefresh Runner installation process')); const answers = await inquirer.prompt(questions); kubeContextName = kubeContextName || answers.context; kubeNamespace = kubeNamespace || answers.namespace; - const { shouldMakeDefaultRe, shouldExecutePipeline } = answers; - console.log(colors.green(`Installation options summary : \n Context: ${colors.blue(kubeContextName)} \n Namespace: ${colors.blue(kubeNamespace)} \n Make hybrid runime as default: ${colors.blue(shouldMakeDefaultRe)}\nExecute hello hyrbird pipeline: ${colors.blue(shouldExecutePipeline)}`)); + shouldMakeDefaultRe = shouldMakeDefaultRe || answers.shouldMakeDefaultRe; + shouldExecutePipeline = shouldExecutePipeline || answers.shouldExecutePipeline; + + console.log(colors.green(`\nInstallation options summary: +${colors.white('1. Kubernetes Context:')} ${colors.cyan(kubeContextName)} +${colors.white('2. Kubernetes Namespace:')} ${colors.cyan(kubeNamespace)} +${colors.white('3. Set this as default account runtime-environment:')} ${colors.cyan(shouldMakeDefaultRe)} +${colors.white('4. Execute demo pipeline after install:')} ${colors.cyan(shouldExecutePipeline)} +`)); + if (token) { // Add context await createContext.handler({ apiKey: token, - name: 'hybrid', + name: 'cf-runner', url, }); const config = await getConfigForSdk(); await sdk.configure(config); - console.log('A codefresh context named hybrid was added in your $HOME folder'); + console.log('A Codefresh context named "cf-runner" was added to your "cfconfig" file.'); } + // Install runner and runtime await installAgent.handler({ name, 'kube-context-name': kubeContextName, @@ -173,10 +211,10 @@ const initCmd = new Command({ createDemoPipeline: true, executeDemoPipeline: shouldExecutePipeline, }); - console.log(colors.green('Agent Status:\n')); + console.log(colors.green('Runner Status:\n')); await getAgents.handler({}); - console.log(colors.green(`\nDocumenation link: ${colors.blue('https://codefresh.io/docs/docs/enterprise/codefresh-runner/#codefresh-runner-preview-release')}`)); - console.log(colors.green('\nTo report issues please follow this link: https://github.com/codefresh-io/cli/issues/new')); + console.log(colors.green(`\nDocumenation link: ${colors.blue('https://codefresh.io/docs/docs/enterprise/codefresh-runner/#codefresh-runner-preview-release')}`)); + console.log(colors.green(`\nIf you had any issues with the installation please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`)); process.exit(); // TODO : This is not needed - needed to be fixed }, }); diff --git a/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js b/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js index 6ce59623b..862f30143 100644 --- a/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js +++ b/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js @@ -13,26 +13,6 @@ const colors = require('colors'); const defaultNamespace = 'codefresh'; const pipelineName = 'hello_hybrid'; -const _getAgentData = async (token) => { - // take the agent id from the token - const apiKey = token.split('.')[0]; - const agentKey = await sdk.tokens.getById({ id: apiKey }); - if (!agentKey) { - throw new Error('token is not valid'); - } - const { subject } = agentKey; - - if (subject.type !== 'agent') { - throw new Error('token is not assosicated with agent'); - } - const agentId = agentKey.subject.ref; - const agentData = await sdk.agents.get({ agentId }); - if (!agentData || agentData === '') { - throw new Error('failed to get agent data'); - } - return agentData; -}; - const createHelloWorlPipeline = async (runtime) => { const pipeline = await sdk.pipelines.create({ metadata: { name: pipelineName } }); pipeline.spec.runtimeEnvironment = { @@ -132,7 +112,7 @@ const installRuntimeCmd = new Command({ describe: 'service account for cluster default is default', }) .option('make-default-runtime', { - describe: 'should all pipelines run on the hybrid runtime (default is false)', + describe: 'should all pipelines run on the this runtime (default is false)', }) .option('skip-cluster-test', { describe: 'Do not run cluster acceptance test', @@ -210,13 +190,13 @@ const installRuntimeCmd = new Command({ clusterName, agent: true, }); - console.log(`Runtime envrionment ${colors.blue(runtimeName)} has been created`); + console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been created`); if (shouldMakeDefaultRe) { const re = await sdk.runtimeEnvs.get({ name: runtimeName, }); await sdk.onPrem.runtimeEnvs.account.setDefault({ account: re.accountId, name: re.metadata.name }); - console.log(`Runtime envrionment ${colors.blue(runtimeName)} has been set to default runtme`); + console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been set as the default runtime`); } // create the cluster in codefresh @@ -229,20 +209,20 @@ const installRuntimeCmd = new Command({ terminateProcess: false, }); } catch (error) { - console.log(`Failed to register cluster on codefresh, cause: ${error.message}`); + console.log(`Failed to register cluster on Codefresh, cause: ${error.message}`); } if (createDemoPipeline) { await createHelloWorlPipeline(runtimeName); - console.log(`Pipeline ${colors.blue(pipelineName)} has been created`); + console.log(`Pipeline "${colors.cyan(pipelineName)}" has been created`); } // install RE on cluster const runtimeEvents = new ProgressEvents(); - const runtimeFormat = 'downloading runtime installer [{bar}] {percentage}% | {value}/{total}'; + const runtimeFormat = 'downloading runtime installer [{bar}] {percentage}% | {value}/{total}'; const runtimmrProgressBar = new cliProgress.SingleBar({ stopOnComplete: true, format: runtimeFormat }, cliProgress.Presets.shades_classic); let runtimeTotalSize; runtimeEvents.onStart((size) => { - console.log('Downloading runtime\'s installer \n'); + console.log('Downloading runtime installer:\n'); runtimmrProgressBar.start(size, 0); runtimeTotalSize = size; }); @@ -274,7 +254,7 @@ const installRuntimeCmd = new Command({ // attach RE to agent in codefresh if (installRuntimeExitCode !== 0) { - throw new Error(`Runtime envrionment install failed with exit code ${installRuntimeExitCode}`); + throw new Error(`Runtime environment installation failed with exit code: ${installRuntimeExitCode}`); } if (attachRuntime) { @@ -305,7 +285,7 @@ const installRuntimeCmd = new Command({ throw new Error(`Attach runtime failed with exit code ${attachRuntimeStatusCode}`); } if (executeDemoPipeline) { - console.log(`Executing pipeline ${colors.blue(pipelineName)}`); + console.log(`Executing pipeline "${colors.cyan(pipelineName)}"`); await runCmd.handler({ name: pipelineName, exitProcess: false, diff --git a/package.json b/package.json index a4a89327e..14998caa9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.59.1", + "version": "0.59.2", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,