codefresh 1.2.11 → 1.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/binary/components.js +38 -0
  2. package/lib/interface/cli/commands/agent/helper.js +28 -0
  3. package/lib/interface/cli/commands/agent/install.cmd.js +283 -0
  4. package/lib/interface/cli/commands/agent/uninstall.cmd.js +92 -0
  5. package/lib/interface/cli/commands/app-proxy/helper.js +63 -0
  6. package/lib/interface/cli/commands/app-proxy/install.cmd.js +204 -0
  7. package/lib/interface/cli/commands/app-proxy/uninstall.cmd.js +175 -0
  8. package/lib/interface/cli/commands/app-proxy/upgrade.cmd.js +110 -0
  9. package/lib/interface/cli/commands/components/download.cmd.js +1 -1
  10. package/lib/interface/cli/commands/gitops/argocd/install.js +9 -0
  11. package/lib/interface/cli/commands/gitops/argocd/uninstall.js +11 -0
  12. package/lib/interface/cli/commands/gitops/argocd/upgrade.js +9 -0
  13. package/lib/interface/cli/commands/gitops/codefresh/install.js +50 -0
  14. package/lib/interface/cli/commands/gitops/codefresh/uninstall.js +14 -0
  15. package/lib/interface/cli/commands/gitops/codefresh/upgrade.js +9 -0
  16. package/lib/interface/cli/commands/gitops/common/install.js +62 -0
  17. package/lib/interface/cli/commands/gitops/common/uninstall.js +39 -0
  18. package/lib/interface/cli/commands/gitops/common/upgrade.js +45 -0
  19. package/lib/interface/cli/commands/gitops/install.cmd.js +116 -0
  20. package/lib/interface/cli/commands/gitops/install.spec.js +77 -0
  21. package/lib/interface/cli/commands/gitops/uninstall.cmd.js +56 -0
  22. package/lib/interface/cli/commands/gitops/upgrade.cmd.js +56 -0
  23. package/lib/interface/cli/commands/hybrid/delete.cmd.js +341 -0
  24. package/lib/interface/cli/commands/hybrid/helper.js +877 -1
  25. package/lib/interface/cli/commands/hybrid/init.cmd.js +957 -0
  26. package/lib/interface/cli/commands/hybrid/key-helper.js +82 -0
  27. package/lib/interface/cli/commands/hybrid/migration.js +192 -0
  28. package/lib/interface/cli/commands/hybrid/upgrade.cmd.js +195 -0
  29. package/lib/interface/cli/commands/monitor/install.cmd.js +160 -0
  30. package/lib/interface/cli/commands/monitor/uninstall.cmd.js +78 -0
  31. package/lib/interface/cli/commands/root/install.cmd.js +17 -0
  32. package/lib/interface/cli/commands/root/uninstall.cmd.js +17 -0
  33. package/lib/interface/cli/commands/runtimeEnvironments/attach.cmd.js +180 -0
  34. package/lib/interface/cli/commands/runtimeEnvironments/create.cmd.js +23 -0
  35. package/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js +340 -0
  36. package/lib/interface/cli/commands/runtimeEnvironments/uninstall.cmd.js +149 -0
  37. package/lib/interface/cli/completion/tree.json +1 -1
  38. package/lib/interface/cli/helpers/kubernetes.js +61 -0
  39. package/lib/interface/cli/helpers/progressEvents.js +25 -0
  40. package/package.json +11 -2
@@ -0,0 +1,78 @@
1
+ /* eslint-disable max-len */
2
+ const Command = require('../../Command');
3
+ const unInstallRoot = require('../root/uninstall.cmd');
4
+ const { sdk } = require('../../../../logic');
5
+ const ProgressEvents = require('../../helpers/progressEvents');
6
+ const cliProgress = require('cli-progress');
7
+ const { DefaultLogFormatter } = require('./../hybrid/helper');
8
+
9
+
10
+ const unInstallAgentCmd = new Command({
11
+ root: false,
12
+ parent: unInstallRoot,
13
+ command: 'monitor',
14
+ description: 'Uninstall an monitor on kubernetes cluster',
15
+ webDocs: {
16
+ category: 'Monitor',
17
+ title: 'Uninstall',
18
+ weight: 100,
19
+ },
20
+ builder: yargs => yargs
21
+ .env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
22
+ .option('kube-context-name', {
23
+ describe: 'Name of the kubernetes context on which monitor should be uninstalled [$CF_ARG_KUBE_CONTEXT_NAME]',
24
+ })
25
+ .option('kube-namespace', {
26
+ describe: 'Name of the namespace on which monitor should be uninstalled [$CF_ARG_KUBE_NAMESPACE]',
27
+ })
28
+ .option('kube-config-path', {
29
+ describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
30
+ })
31
+ .option('verbose', {
32
+ describe: 'Print logs',
33
+ }),
34
+ handler: async (argv) => {
35
+ const {
36
+ 'kube-namespace': kubeNamespace,
37
+ 'kube-config-path': kubeConfigPath,
38
+ 'kube-context-name': kubeContextName,
39
+ noExit,
40
+ } = argv;
41
+
42
+ const events = new ProgressEvents();
43
+ const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
44
+ const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
45
+ let totalSize;
46
+ events.onStart((size) => {
47
+ progressBar.start(size, 0);
48
+ totalSize = size;
49
+ });
50
+ events.onProgress((progress) => {
51
+ progressBar.update(progress);
52
+ if (progress >= totalSize) {
53
+ console.log('\n');
54
+ }
55
+ });
56
+
57
+
58
+ const exitCode = await sdk.monitor.unInstall({
59
+ kubeContextName,
60
+ kubeNamespace,
61
+ kubeConfigPath,
62
+ terminateProcess: false,
63
+ events,
64
+ logFormatting: DefaultLogFormatter,
65
+ });
66
+ if (exitCode === 0) {
67
+ console.log('Monitor uninstalled successfully');
68
+ if (!noExit) {
69
+ process.exit(0);
70
+ }
71
+ }
72
+ if (!noExit) {
73
+ process.exit(1);
74
+ }
75
+ },
76
+ });
77
+
78
+ module.exports = unInstallAgentCmd;
@@ -0,0 +1,17 @@
1
+ const Command = require('../../Command');
2
+
3
+
4
+ const install = new Command({
5
+ root: true,
6
+ command: 'install',
7
+ description: 'Install a resource',
8
+ usage: 'Install operation will install codefresh components on kubernetes cluster',
9
+ webDocs: {
10
+ description: 'Install a resource',
11
+ category: 'Install Resources',
12
+ title: 'Install',
13
+ weight: 40,
14
+ },
15
+ });
16
+
17
+ module.exports = install;
@@ -0,0 +1,17 @@
1
+ const Command = require('../../Command');
2
+
3
+
4
+ const unInstall = new Command({
5
+ root: true,
6
+ command: 'uninstall',
7
+ description: 'Uninstall a resource',
8
+ usage: 'Uninstall operation will uninstall codefresh components on kubernetes cluster',
9
+ webDocs: {
10
+ description: 'Uninstall a resource',
11
+ category: 'Uninstall Resources',
12
+ title: 'Uninstall',
13
+ weight: 40,
14
+ },
15
+ });
16
+
17
+ module.exports = unInstall;
@@ -0,0 +1,180 @@
1
+ /* eslint-disable max-len */
2
+ const _ = require('lodash');
3
+ const cliProgress = require('cli-progress');
4
+ const Command = require('../../Command');
5
+ const { sdk } = require('../../../../logic');
6
+ const ProgressEvents = require('../../helpers/progressEvents');
7
+ const { getKubeContext } = require('../../helpers/kubernetes');
8
+ const { DefaultLogFormatter } = require('../hybrid/helper');
9
+
10
+ async function attachInPlatform(argv) {
11
+ const {
12
+ agentName,
13
+ agentId,
14
+ runtimeName,
15
+ } = argv;
16
+ let agent;
17
+ if (_.isEmpty(runtimeName)) {
18
+ throw new Error('runtime name is mandatory');
19
+ }
20
+
21
+ if (agentName) {
22
+ agent = await sdk.agents.getByName({ name: agentName });
23
+ } else if (agentId) {
24
+ agent = await sdk.agents.get({ agentId });
25
+ } else {
26
+ throw new Error('agent name or agent id is needed');
27
+ }
28
+
29
+ if (agent === '' || !agent) {
30
+ throw new Error('agent was not found');
31
+ }
32
+
33
+ const rt = await sdk.runtimeEnvs.get({ name: runtimeName });
34
+ if (!rt) {
35
+ throw new Error(`runtime ${runtimeName} does not exist on the account`);
36
+ }
37
+
38
+ if (!rt.metadata.agent) {
39
+ throw new Error('cannot attach non hybrid runtime');
40
+ }
41
+
42
+ const runtimes = _.get(agent, 'runtimes', []);
43
+ const existingRT = _.find(runtimes, (value) => value === runtimeName);
44
+ if (!existingRT) {
45
+ runtimes.push(runtimeName);
46
+ await sdk.agents.update({ agentId: agent.id, runtimes });
47
+ }
48
+ }
49
+
50
+ async function attachInCluster(argv) {
51
+ const {
52
+ runtimeName,
53
+ runtimeKubeConfigPath,
54
+ runtimeKubeContextName = getKubeContext(runtimeKubeConfigPath),
55
+ runtimeKubeNamespace,
56
+ agentKubeConfigPath,
57
+ agentKubeContextName = runtimeKubeContextName,
58
+ agentKubeNamespace,
59
+ runtimeKubeServiceAccount,
60
+ restartAgent,
61
+ verbose,
62
+ } = argv;
63
+ if (_.isNull(runtimeName) || _.isUndefined(runtimeName) || runtimeName === '') {
64
+ throw new Error('runtime name is mandatory');
65
+ }
66
+
67
+ if (!runtimeKubeNamespace) {
68
+ throw new Error('runtime-kube-namespace is mandatory parameter');
69
+ }
70
+
71
+ // call venonactl to attach
72
+ const events = new ProgressEvents();
73
+ const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
74
+ const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
75
+ let totalSize;
76
+ events.onStart((size) => {
77
+ progressBar.start(size, 0);
78
+ totalSize = size;
79
+ });
80
+ events.onProgress((progress) => {
81
+ progressBar.update(progress);
82
+ if (progress >= totalSize) {
83
+ console.log('\n');
84
+ }
85
+ });
86
+ await sdk.runtime.attach({
87
+ runtimeName,
88
+ kubeConfigPath: runtimeKubeConfigPath,
89
+ kubeContextName: runtimeKubeContextName,
90
+ kubeNamespace: runtimeKubeNamespace,
91
+ kubeServiceAccount: runtimeKubeServiceAccount,
92
+ agentKubeConfigPath,
93
+ agentKubeContextName,
94
+ agentKubeNamespace,
95
+ verbose,
96
+ restartAgent,
97
+ terminateProcess: false,
98
+ events,
99
+ logFormatting: DefaultLogFormatter,
100
+ });
101
+ if (!restartAgent) {
102
+ console.log('Please restart agent\'s pod in order that changes will take effect');
103
+ }
104
+ }
105
+
106
+ const attachRuntimeCmd = new Command({
107
+ root: true,
108
+ command: 'attach runtime',
109
+ description: 'Attach a runtime to agent',
110
+ usage: 'attach runtime',
111
+ webDocs: {
112
+ category: 'Runtime-Environments',
113
+ title: 'Attach Runtime-Environments',
114
+ weight: 100,
115
+ },
116
+ builder: (yargs) => yargs
117
+ .env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
118
+ .option('runtime-name', {
119
+ describe: 'Runtime\'s name',
120
+ })
121
+ .option('agent-name', {
122
+ describe: 'Agent\'s name',
123
+ })
124
+ .option('agent-id', {
125
+ describe: 'Agent\'s ID',
126
+ })
127
+ .option('runtime-kube-context-name', {
128
+ describe: 'Runtime kubernetes context',
129
+ })
130
+ .option('runtime-kube-namespace', {
131
+ describe: 'Runtime\'s namespace',
132
+ })
133
+ .option('runtime-kube-config-path', {
134
+ describe: 'Path to kubeconfig file for runtime (default is $HOME/.kube/config)',
135
+ })
136
+ .option('agent-kube-context-name', {
137
+ describe: 'Agent kubernetes context',
138
+ })
139
+ .option('agent-kube-namespace', {
140
+ describe: 'Agent\'s namespace',
141
+ })
142
+ .option('agent-kube-service-account', {
143
+ describe: 'The service account to use for the agent pod',
144
+ })
145
+ .option('agent-kube-config-path', {
146
+ describe: 'Path to kubeconfig file for the agent (default is $HOME/.kube/config)',
147
+ })
148
+ .option('restart-agent', {
149
+ describe: 'restart agent afte install - default false',
150
+ })
151
+ .option('platform-only', {
152
+ describe: 'Set to true to attach runtime to agent on the platform side only',
153
+ })
154
+ .option('verbose', {
155
+ describe: 'Print logs',
156
+ }),
157
+ handler: async (argv) => {
158
+ const {
159
+ runtimeKubeNamespace,
160
+ platformOnly,
161
+ terminateProcess,
162
+ } = argv;
163
+ if (!runtimeKubeNamespace && !platformOnly) {
164
+ throw new Error('runtime-kube-namespace is mandatory parameter');
165
+ }
166
+
167
+ await attachInPlatform(argv);
168
+ if (!platformOnly) {
169
+ await attachInCluster(argv);
170
+ }
171
+
172
+ if (terminateProcess || terminateProcess === undefined) {
173
+ process.exit();
174
+ }
175
+
176
+ return 0;
177
+ },
178
+ });
179
+
180
+ module.exports = attachRuntimeCmd;
@@ -0,0 +1,23 @@
1
+ const Command = require('../../Command');
2
+ const createRoot = require('../root/create.cmd');
3
+
4
+ const DEPRECATION_MESSAGE = 'Create runtime-environment command has been deprecated.\nUse codefresh install runtime command instead';
5
+
6
+ const command = new Command({
7
+ command: 'runtime-environments [cluster]',
8
+ aliases: ['re', 'runtime-environment'],
9
+ parent: createRoot,
10
+ description: 'Create a runtime environment',
11
+ webDocs: {
12
+ category: 'Runtime-Environments',
13
+ title: 'Create Runtime-Environments',
14
+ weight: 100,
15
+ },
16
+ handler: async () => {
17
+ console.log(`${DEPRECATION_MESSAGE}`);
18
+ process.exit(1);
19
+ },
20
+ });
21
+
22
+
23
+ module.exports = command;
@@ -0,0 +1,340 @@
1
+ /* eslint-disable max-len */
2
+ const cliProgress = require('cli-progress');
3
+ const colors = require('colors');
4
+ const _ = require('lodash');
5
+ const Command = require('../../Command');
6
+ const { sdk } = require('../../../../logic');
7
+ const attachRuntimeCmd = require('./attach.cmd');
8
+ const installRoot = require('../root/install.cmd');
9
+ const { getKubeContext } = require('../../helpers/kubernetes');
10
+ const ProgressEvents = require('../../helpers/progressEvents');
11
+ const createClusterCmd = require('../cluster/create.cmd');
12
+ const { DefaultLogFormatter, INSTALLATION_DEFAULTS } = require('../hybrid/helper');
13
+
14
+ const defaultNamespace = 'codefresh';
15
+ const defaultStorageClassPrefix = 'dind-local-volumes-runner';
16
+ const maxRuntimeNameLength = 63;
17
+
18
+ async function newRuntimeName(kubeContextName, kubeNamespace) {
19
+ const defaultName = `${kubeContextName}/${kubeNamespace}`.slice(0, maxRuntimeNameLength);
20
+ const runtimes = await sdk.runtimeEnvs.list({ });
21
+ let name;
22
+
23
+ if (!_.isArray(runtimes) || !_.find(runtimes, (re) => _.get(re, 'metadata.name') === defaultName)) {
24
+ name = defaultName; // use the default name if there are no collisions
25
+ } else {
26
+ const reNames = new Set(_.map(runtimes, (re) => _.get(re, 'metadata.name'))); // for fast lookup
27
+ let i = 1;
28
+ let suggestName;
29
+ // eslint-disable-next-line no-constant-condition
30
+ while (true) {
31
+ suggestName = `${defaultName.slice(0, maxRuntimeNameLength - 1 - i.toString().length)}_${i}`;
32
+ if (!reNames.has(suggestName)) {
33
+ break;
34
+ }
35
+ i += 1;
36
+ }
37
+
38
+ name = suggestName;
39
+ }
40
+
41
+ return name;
42
+ }
43
+
44
+ async function createRuntimeInPlatform(argv, runtimeName) {
45
+ const {
46
+ kubeNodeSelector,
47
+ buildAnnotations,
48
+ makeDefaultRuntime,
49
+ runtimeKubeConfigPath,
50
+ runtimeKubeContextName = getKubeContext(runtimeKubeConfigPath),
51
+ runtimeKubeNamespace = defaultNamespace,
52
+ storageClassName = `${defaultStorageClassPrefix}-${runtimeKubeNamespace}`,
53
+ } = argv;
54
+
55
+ // parse kubeNodeSelector in form key1=value1,key2=value2 to {key1: value1, key2: value2}
56
+ const kubeNodeSelectorObj = {};
57
+ if (kubeNodeSelector) {
58
+ const nsSplitParts = kubeNodeSelector.split(',');
59
+ nsSplitParts.forEach((nsPart) => {
60
+ const [key, value] = nsPart.split('=');
61
+ if (!key || !value) {
62
+ throw new Error('invalid kube-node-selector parameter');
63
+ }
64
+
65
+ kubeNodeSelectorObj[key] = value;
66
+ });
67
+ }
68
+
69
+ // create RE in codefresh
70
+ await sdk.cluster.create({
71
+ runtimeEnvironmentName: runtimeName,
72
+ storageClassName: storageClassName || `${defaultStorageClassPrefix}-${runtimeKubeNamespace}`,
73
+ serviceAccount: INSTALLATION_DEFAULTS.RUNTIME_SERVICE_ACCOUNT,
74
+ nodeSelector: kubeNodeSelectorObj,
75
+ annotations: buildAnnotations,
76
+ clusterName: runtimeKubeContextName,
77
+ namespace: runtimeKubeNamespace,
78
+ agent: true,
79
+ });
80
+ console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been created`);
81
+ if (makeDefaultRuntime) {
82
+ const re = await sdk.runtimeEnvs.get({
83
+ name: runtimeName,
84
+ });
85
+ await sdk.runtimeEnvs.setDefault({ account: re.accountId, name: re.metadata.name });
86
+ console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been set as the default runtime`);
87
+ }
88
+ }
89
+
90
+ async function createClusterInPlatform(argv) {
91
+ const {
92
+ clusterServiceAccount,
93
+ runtimeKubeConfigPath,
94
+ runtimeKubeContextName = getKubeContext(runtimeKubeConfigPath),
95
+ runtimeKubeNamespace = defaultNamespace,
96
+ } = argv;
97
+
98
+ try {
99
+ // check if cluster already exists
100
+ const clusters = await sdk.clusters.list() || [];
101
+ // should create cluster if it does not exist already
102
+ const createCluster = !clusters.find((cluster) => cluster.selector === runtimeKubeContextName);
103
+
104
+ // create the cluster in codefresh if does not exists
105
+ if (createCluster) {
106
+ console.log(`Adding cluster "${colors.cyan(runtimeKubeContextName)}" integration to your Codefresh account`);
107
+ try {
108
+ await createClusterCmd.handler({
109
+ 'kube-context': runtimeKubeContextName,
110
+ namespace: runtimeKubeNamespace,
111
+ 'behind-firewall': true,
112
+ serviceaccount: clusterServiceAccount || 'default',
113
+ terminateProcess: false,
114
+ });
115
+ } catch (error) {
116
+ console.log(`Failed to register cluster on Codefresh, cause: ${error.message}`);
117
+ }
118
+ }
119
+ } catch (error) {
120
+ console.log(`Failed to fetch account clusters, cause: ${error.message}`);
121
+ }
122
+ }
123
+
124
+ async function installRuntimeInCluster(argv, runtimeName) {
125
+ const {
126
+ storageClassName,
127
+ dryRun,
128
+ inCluster,
129
+ kubeNodeSelector,
130
+ setValue,
131
+ setFile,
132
+ attachRuntime,
133
+ dockerRegistry,
134
+ runtimeKubeConfigPath,
135
+ runtimeKubeContextName = getKubeContext(runtimeKubeConfigPath),
136
+ runtimeKubeNamespace = defaultNamespace,
137
+ token = sdk.config.context.token,
138
+ verbose,
139
+ } = argv;
140
+
141
+ const apiHost = sdk.config.context.url;
142
+
143
+ // install RE on cluster
144
+ const runtimeEvents = new ProgressEvents();
145
+ const runtimeFormat = 'downloading runtime installer [{bar}] {percentage}% | {value}/{total}';
146
+ const runtimmrProgressBar = new cliProgress.SingleBar({ stopOnComplete: true, format: runtimeFormat }, cliProgress.Presets.shades_classic);
147
+ let runtimeTotalSize;
148
+ runtimeEvents.onStart((size) => {
149
+ console.log('Downloading runtime installer:\n');
150
+ runtimmrProgressBar.start(size, 0);
151
+ runtimeTotalSize = size;
152
+ });
153
+ runtimeEvents.onProgress((progress) => {
154
+ runtimmrProgressBar.update(progress);
155
+ if (progress >= runtimeTotalSize) {
156
+ console.log('\n');
157
+ }
158
+ });
159
+
160
+ const installRuntimeExitCode = await sdk.runtime.install({
161
+ apiHost,
162
+ name: runtimeName,
163
+ storageClassName: storageClassName && storageClassName.startsWith('dind-local-volumes') ? undefined : storageClassName,
164
+ kubeConfigPath: runtimeKubeConfigPath,
165
+ kubeContextName: runtimeKubeContextName,
166
+ kubeNamespace: runtimeKubeNamespace,
167
+ kubeNodeSelector,
168
+ token,
169
+ inCluster,
170
+ dockerRegistry,
171
+ setValue,
172
+ setFile,
173
+ terminateProcess: !attachRuntime,
174
+ events: runtimeEvents,
175
+ dryRun,
176
+ verbose,
177
+ logFormatting: DefaultLogFormatter,
178
+ });
179
+ // attach RE to agent in codefresh
180
+
181
+ if (installRuntimeExitCode !== 0) {
182
+ throw new Error(`Runtime environment installation failed with exit code: ${installRuntimeExitCode}`);
183
+ }
184
+ }
185
+
186
+ async function attachRuntimeToAgent(argv, runtimeName) {
187
+ const {
188
+ agentName,
189
+ runtimeKubeConfigPath,
190
+ runtimeKubeContextName = getKubeContext(runtimeKubeConfigPath),
191
+ runtimeKubeNamespace = defaultNamespace,
192
+ agentKubeConfigPath = runtimeKubeConfigPath,
193
+ agentKubeContextName = runtimeKubeContextName,
194
+ agentKubeNamespace,
195
+ platformOnly,
196
+ } = argv;
197
+
198
+ const attachRuntimeStatusCode = await attachRuntimeCmd.handler({
199
+ agentName,
200
+ runtimeName,
201
+ runtimeKubeConfigPath,
202
+ runtimeKubeContextName,
203
+ runtimeKubeNamespace,
204
+ agentKubeConfigPath,
205
+ agentKubeContextName,
206
+ agentKubeNamespace,
207
+ restartAgent: true,
208
+ platformOnly,
209
+ terminateProcess: false,
210
+ });
211
+ if (attachRuntimeStatusCode !== 0) {
212
+ throw new Error(`Attach runtime failed with exit code ${attachRuntimeStatusCode}`);
213
+ }
214
+ }
215
+
216
+ const installRuntimeCmd = new Command({
217
+ root: false,
218
+ parent: installRoot,
219
+ command: 'runtime',
220
+ description: 'Install and create a runtime on kubernetes cluster',
221
+ webDocs: {
222
+ category: 'Runtime-Environments',
223
+ title: 'Install Runtime-Environment',
224
+ weight: 100,
225
+ },
226
+ builder: (yargs) => yargs
227
+ .env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
228
+ .option('runtime-name', {
229
+ describe: 'The name of the runtime to install',
230
+ })
231
+ .option('token', {
232
+ describe: 'Agent\'s token',
233
+ })
234
+ .option('agent-name', {
235
+ describe: 'Agent\'s name',
236
+ })
237
+ .option('storage-class-name', {
238
+ describe: 'Set a name of your custom storage class, note: this will not install volume provisioning components',
239
+ })
240
+ .option('docker-registry', {
241
+ describe: 'The prefix for the container registry that will be used for pulling the required components images. Example: --docker-registry="docker.io"',
242
+ type: 'string',
243
+ })
244
+ .option('set-value', {
245
+ describe: 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes',
246
+ })
247
+ .option('set-file', {
248
+ describe: 'Set values for templates from file, example: --set-file Storage.GoogleServiceAccount=/path/to/service-account.json',
249
+ })
250
+ .option('dry-run', {
251
+ describe: 'Set to true to simulate installation',
252
+ })
253
+ .option('in-cluster', {
254
+ describe: 'Set flag if runner is been installed from inside a cluster',
255
+ })
256
+ .option('kube-node-selector', {
257
+ describe: 'The kubernetes node selector "key=value" to be used by runner build resources (default is no node selector) (string)',
258
+ })
259
+ .option('runtime-kube-config-path', {
260
+ describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
261
+ })
262
+ .option('runtime-kube-context-name', {
263
+ describe: 'Name of the kubernetes context on which the runtime should be installed (default is current-context) [$CF_ARG_KUBE_CONTEXT_NAME]',
264
+ })
265
+ .option('runtime-kube-namespace', {
266
+ describe: 'Name of the namespace on which runtime should be installed [$CF_ARG_KUBE_NAMESPACE]',
267
+ })
268
+ .option('build-annotations', {
269
+ describe: 'The kubernetes metadata.annotations as "key=value" to be used by runner build resources (default is no node selector)',
270
+ })
271
+ .option('attach-runtime', {
272
+ describe: 'if set to true, auto attach runtime to agent (need to provide ....)',
273
+ })
274
+ .option('agent-kube-config-path', {
275
+ describe: 'Path to kubeconfig file for the agent (default is $HOME/.kube/config) (on attach)',
276
+ })
277
+ .option('agent-kube-context-name', {
278
+ describe: 'Agent kubernetes context (on attach)',
279
+ })
280
+ .option('agent-kube-namespace', {
281
+ describe: 'Agent\'s namespace (on attach)',
282
+ })
283
+ .option('cluster-service-account', {
284
+ describe: 'service account for cluster default is default',
285
+ })
286
+ .option('make-default-runtime', {
287
+ describe: 'should all pipelines run on the this runtime (default is false)',
288
+ })
289
+ .option('skip-re-creation', {
290
+ description: 'If set to true, will skip runtime creation in the platform',
291
+ })
292
+ .option('skip-cluster-creation', {
293
+ description: 'If set to true, will skip cluster integration creation for this runtime',
294
+ })
295
+ .option('platform-only', {
296
+ describe: 'Set to true to create runtime on the platform side only',
297
+ })
298
+ .option('verbose', {
299
+ describe: 'Print logs',
300
+ }),
301
+ handler: async (argv) => {
302
+ const {
303
+ runtimeName,
304
+ skipReCreation,
305
+ skipClusterCreation,
306
+ attachRuntime,
307
+ runtimeKubeConfigPath,
308
+ runtimeKubeContextName = getKubeContext(runtimeKubeConfigPath),
309
+ runtimeKubeNamespace = defaultNamespace,
310
+ agentKubeNamespace,
311
+ platformOnly,
312
+ } = argv;
313
+
314
+ if (attachRuntime && !agentKubeNamespace) {
315
+ throw new Error('agent-kube-namespace is a mandatory parameter');
316
+ }
317
+
318
+ const finalName = runtimeName || await newRuntimeName(runtimeKubeContextName, runtimeKubeNamespace);
319
+
320
+ if (!skipReCreation) {
321
+ await createRuntimeInPlatform(argv, finalName);
322
+ }
323
+
324
+ if (!skipClusterCreation) {
325
+ await createClusterInPlatform(argv);
326
+ }
327
+
328
+ if (!platformOnly) {
329
+ await installRuntimeInCluster(argv, finalName);
330
+ }
331
+
332
+ if (attachRuntime) {
333
+ await attachRuntimeToAgent(argv, finalName);
334
+ } else {
335
+ console.log('Please run agent attach in order to link agent and runtime');
336
+ }
337
+ },
338
+ });
339
+
340
+ module.exports = installRuntimeCmd;