Skip to content

Commit 1c92eb2

Browse files
monitor installation with helm (#661)
1 parent 3aaa800 commit 1c92eb2

File tree

4 files changed

+152
-72
lines changed

4 files changed

+152
-72
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const Command = require('../../Command');
2+
const runnerRoot = require('../root/runner.cmd');
3+
const colors = require('colors');
4+
const InstallationPlan = require('./InstallationPlan');
5+
const { addPipelineToInstallationPlan } = require('./pipeline-helper');
6+
const { createErrorHandler } = require('./helper');
7+
8+
const handleError = createErrorHandler(`\nIf you had any issues with the installation please report them at:\
9+
${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`);
10+
11+
const defaultDockerRegistry = 'quay.io';
12+
13+
const command = new Command({
14+
command: 'execute-test-pipeline',
15+
parent: runnerRoot,
16+
requiresAuthentication: true,
17+
description: 'Executes test pipeline',
18+
webDocs: {
19+
category: 'Runner',
20+
title: 'Execute test pipeline',
21+
},
22+
builder: yargs => yargs
23+
.option('runtime-name', {
24+
describe: 'Runtime name to execute pipeline on',
25+
}),
26+
handler: async (argv) => {
27+
const { runtimeName } = argv;
28+
29+
const installationPlan = new InstallationPlan({ errHandler: handleError });
30+
installationPlan.addContext('runtimeName', runtimeName ? runtimeName.trim() : runtimeName);
31+
await addPipelineToInstallationPlan(installationPlan, defaultDockerRegistry, true);
32+
await installationPlan.execute();
33+
process.exit(); // TODO : This is not needed - needed to be fixed
34+
},
35+
});
36+
37+
module.exports = command;

lib/interface/cli/commands/hybrid/init.cmd.js

Lines changed: 43 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ const installationProgress = require('./installation-process');
1919
const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
2020
const {
2121
createErrorHandler,
22-
createTestPipeline,
23-
executeTestPipeline,
24-
updateTestPipelineRuntime,
2522
drawCodefreshFiglet,
2623
getDefaultRuntime,
2724
getRecommendedKubeNamespace,
@@ -40,6 +37,9 @@ const {
4037
const InstallationPlan = require('./InstallationPlan');
4138
const { produceVenonaKeys } = require('./key-helper');
4239
const { array } = require('yargs');
40+
const {
41+
addPipelineToInstallationPlan,
42+
} = require('./pipeline-helper');
4343

4444
const defaultDockerRegistry = 'quay.io';
4545
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({
318318
httpsProxy = httpsProxy || detectedProxyVars.httpsProxy;
319319
noProxy = noProxy || detectedProxyVars.noProxy;
320320

321-
if (shouldUseHelm) {
322-
shouldExecutePipeline = false;
323-
}
324-
325321
if (noQuestions) {
326322
// use defaults
327323
kubeContextName = kubeContextName || getKubeContext(kubeConfigPath);
@@ -415,7 +411,7 @@ const initCmd = new Command({
415411
type: 'confirm',
416412
name: 'shouldExecutePipeline',
417413
default: INSTALLATION_DEFAULTS.RUN_DEMO_PIPELINE,
418-
message: 'Run demo pipeline after install?',
414+
message: shouldUseHelm ? 'Create demo pipeline?' : 'Run demo pipeline after install?',
419415
});
420416
}
421417

@@ -503,7 +499,7 @@ const initCmd = new Command({
503499
bypassDownload,
504500
},
505501
installationEvent: installationProgress.events.ACCEPTANCE_TESTS_RAN,
506-
condition: !skipClusterTest,
502+
condition: !skipClusterTest && !shouldUseHelm,
507503
});
508504

509505
// generate new agent name
@@ -834,6 +830,20 @@ const initCmd = new Command({
834830
condition: !shouldUseHelm,
835831
});
836832

833+
834+
function shouldInstallMonitoringFn() {
835+
if (!installMonitor) {
836+
return false;
837+
}
838+
839+
if (isInCluster() || skipClusterIntegration) {
840+
console.log('Monitor component cannot be installed without cluster integration, you can install it seperately using: "codefresh install monitor"');
841+
return false;
842+
}
843+
844+
return true;
845+
}
846+
837847
// install monitoring
838848
installationPlan.addStep({
839849
name: 'install cluster monitoring',
@@ -858,22 +868,7 @@ const initCmd = new Command({
858868
successMessage: 'Successfully installed cluster monitoring',
859869
installationEvent: installationProgress.events.MONITOR_INSTALLED,
860870
executeOnDryRun: true,
861-
condition: async () => {
862-
if (shouldUseHelm) {
863-
return false;
864-
}
865-
866-
if (!installMonitor) {
867-
return false;
868-
}
869-
870-
if (isInCluster() || skipClusterIntegration) {
871-
console.log('Monitor component cannot be installed without cluster integration, you can install it seperately using: "codefresh install monitor"');
872-
return false;
873-
}
874-
875-
return true;
876-
},
871+
condition: !shouldUseHelm && shouldInstallMonitoringFn,
877872
});
878873

879874
// helm value files if its enabled
@@ -888,6 +883,16 @@ const initCmd = new Command({
888883
kubeNamespace,
889884
);
890885

886+
const _appProxy = {
887+
enabled: appProxy || false,
888+
host: appProxyHost || '',
889+
};
890+
891+
const monitor = {
892+
enabled: shouldInstallMonitoringFn(),
893+
clusterId: kubeContextName,
894+
};
895+
891896
const global = {
892897
namespace: kubeNamespace,
893898
codefreshHost: sdk.config.context.url,
@@ -899,7 +904,7 @@ const initCmd = new Command({
899904
keys,
900905
};
901906

902-
const content = JSON.stringify({ global }, null, 4);
907+
const content = JSON.stringify({ appProxy: _appProxy, monitor, global }, null, 4);
903908

904909
fs.writeFileSync(
905910
helmValuesFile,
@@ -914,51 +919,7 @@ const initCmd = new Command({
914919

915920
// Post Installation
916921
if (shouldExecutePipeline) {
917-
const pipelines = await sdk.pipelines.list({ id: `${INSTALLATION_DEFAULTS.PROJECT_NAME}/${INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME}` });
918-
const testPipelineExists = !!_.get(pipelines, 'docs.length');
919-
920-
if (!testPipelineExists) {
921-
installationPlan.addStep({
922-
name: 'create test pipeline',
923-
func: async () => {
924-
await createTestPipeline(
925-
installationPlan.getContext('runtimeName'),
926-
INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME,
927-
['echo hello Codefresh Runner!'],
928-
dockerRegistry,
929-
);
930-
},
931-
installationEvent: installationProgress.events.PIPELINE_CREATED,
932-
});
933-
} else {
934-
installationPlan.addStep({
935-
name: 'update test pipeline runtime',
936-
func: async () => {
937-
await updateTestPipelineRuntime(
938-
undefined,
939-
installationPlan.getContext('runtimeName'),
940-
INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME,
941-
dockerRegistry,
942-
);
943-
},
944-
errMessage: colors.yellow('*warning* could not update test pipeline runtime, you can' +
945-
' change it manually if you want to run it again on this runtime'),
946-
successMessage: 'Updated test pipeline runtime',
947-
exitOnError: false,
948-
});
949-
}
950-
951-
installationPlan.addStep({
952-
name: 'execute test pipeline',
953-
func: async () => {
954-
await executeTestPipeline(
955-
installationPlan.getContext('runtimeName'),
956-
INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME,
957-
);
958-
},
959-
errMessage: 'Failed to execute test pipeline',
960-
installationEvent: installationProgress.events.PIPELINE_EXECUTED,
961-
});
922+
await addPipelineToInstallationPlan(installationPlan, dockerRegistry, !shouldUseHelm);
962923
}
963924

964925
await installationPlan.execute();
@@ -972,11 +933,22 @@ const initCmd = new Command({
972933
if (installMonitor) {
973934
console.log(`Go to ${colors.blue('https://g.codefresh.io/kubernetes/services/')} to view your cluster in Codefresh dashbaord`);
974935
}
936+
975937
console.log(`Link to the new runtime: ${colors.blue(`https://g.codefresh.io/account-admin/account-conf/runtime-environments?runtime=${encodeURI(installationPlan.getContext('runtimeName'))}`)}`);
976938
console.log(`\nDocumentation link: ${colors.blue('https://codefresh.io/docs/docs/enterprise/codefresh-runner/#codefresh-runner-preview-release')}`);
977939
console.log(`If you had any issues with the installation please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`);
978940
await to(progressReporter.report(installationProgress.events.FINISHED, installationProgress.status.SUCCESS));
979941
await drawCodefreshFiglet();
942+
943+
if (shouldUseHelm) {
944+
console.log('\n\nTo install helm run:');
945+
console.log('helm repo add cf-runtime https://h.cfcr.io/codefresh-inc/runtime');
946+
console.log(`kubectl create ns ${kubeNamespace}`);
947+
console.log(`helm install cf-runtime cf-runtime/cf-runtime -f ${helmValuesFile} --namespace ${kubeNamespace}\n`);
948+
console.log('In order to test your runner helm based installation please execute\n' +
949+
'codefresh runner execute-test-pipeline');
950+
}
951+
980952
process.exit(); // TODO : This is not needed - needed to be fixed
981953
},
982954
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const sdk = require('../../../../logic/sdk');
2+
const colors = require('colors');
3+
const installationProgress = require('./installation-process');
4+
const _ = require('lodash');
5+
6+
const {
7+
createTestPipeline,
8+
executeTestPipeline,
9+
updateTestPipelineRuntime,
10+
INSTALLATION_DEFAULTS,
11+
} = require('./helper');
12+
13+
const defaultDockerRegistry = 'quay.io';
14+
15+
async function addPipelineToInstallationPlan(installationPlan, dockerRegistry = '', executePipeline = true) {
16+
if (!dockerRegistry) {
17+
// eslint-disable-next-line no-param-reassign
18+
dockerRegistry = defaultDockerRegistry;
19+
}
20+
21+
const pipelines = await sdk.pipelines.list({ id: `${INSTALLATION_DEFAULTS.PROJECT_NAME}/${INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME}` });
22+
const testPipelineExists = !!_.get(pipelines, 'docs.length');
23+
24+
if (!testPipelineExists) {
25+
installationPlan.addStep({
26+
name: 'create test pipeline',
27+
func: async () => {
28+
await createTestPipeline(
29+
installationPlan.getContext('runtimeName'),
30+
INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME,
31+
['echo hello Codefresh Runner!'],
32+
dockerRegistry,
33+
);
34+
},
35+
installationEvent: installationProgress.events.PIPELINE_CREATED,
36+
});
37+
} else {
38+
installationPlan.addStep({
39+
name: 'update test pipeline runtime',
40+
func: async () => {
41+
await updateTestPipelineRuntime(
42+
undefined,
43+
installationPlan.getContext('runtimeName'),
44+
INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME,
45+
dockerRegistry,
46+
);
47+
},
48+
errMessage: colors.yellow('*warning* could not update test pipeline runtime, you can' +
49+
' change it manually if you want to run it again on this runtime'),
50+
successMessage: 'Updated test pipeline runtime',
51+
exitOnError: false,
52+
});
53+
}
54+
55+
installationPlan.addStep({
56+
name: 'execute test pipeline',
57+
func: async () => {
58+
await executeTestPipeline(
59+
installationPlan.getContext('runtimeName'),
60+
INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME,
61+
);
62+
},
63+
errMessage: 'Failed to execute test pipeline',
64+
installationEvent: installationProgress.events.PIPELINE_EXECUTED,
65+
condition: executePipeline,
66+
});
67+
}
68+
69+
module.exports = {
70+
addPipelineToInstallationPlan,
71+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.75.16",
3+
"version": "0.75.17",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)