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,204 @@
1
+ const colors = require('colors');
2
+
3
+ const _ = require('lodash');
4
+ const Command = require('../../Command');
5
+ const installRoot = require('../root/install.cmd');
6
+ const {
7
+ INSTALLATION_DEFAULTS,
8
+ installAppProxy,
9
+ createErrorHandler,
10
+ drawCodefreshFiglet,
11
+ } = require('../hybrid/helper');
12
+ const { getKubeContext } = require('../../helpers/kubernetes');
13
+ const sdk = require('../../../../logic/sdk');
14
+ const { to } = require('../../../../logic/cli-config/errors/awaitTo');
15
+ const {
16
+ mergeWithValues,
17
+ selectRuntime,
18
+ selectNamespace,
19
+ selectHost,
20
+ } = require('./helper');
21
+
22
+ const openIssueMessage = 'If you had any issues with this installation process please report them at:'
23
+ + ` ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
24
+ const handleError = createErrorHandler(openIssueMessage);
25
+
26
+ function printInstallationOptionsSummary({
27
+ kubeContextName,
28
+ kubeNamespace,
29
+ host,
30
+ runtimeEnvironment,
31
+ }) {
32
+ const summary = `\n${colors.green('Installation options summary:')}
33
+ 1. Kubernetes Context: ${colors.cyan(kubeContextName)}
34
+ 2. Kubernetes Namespace: ${colors.cyan(kubeNamespace)}
35
+ 3. App-Proxy hostname: ${colors.cyan(host)}
36
+ 4. Runtime-Environment: ${colors.cyan(runtimeEnvironment)}
37
+ `;
38
+ console.log(summary);
39
+ }
40
+
41
+
42
+ const installAppProxyHandler = new Command({
43
+ root: false,
44
+ parent: installRoot,
45
+ command: 'app-proxy',
46
+ description: 'Installs the App-Proxy component on your Kubernetes cluster',
47
+ webDocs: {
48
+ category: 'App-Proxy',
49
+ title: 'Install',
50
+ weight: 100,
51
+ },
52
+
53
+ builder: yargs => yargs
54
+ .env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
55
+ .option('kube-config-path', {
56
+ describe: 'Path to kubeconfig file [$KUBECONFIG]',
57
+ default: INSTALLATION_DEFAULTS.KUBECONFIG_PATH,
58
+ type: 'string',
59
+ })
60
+ .option('kube-context-name', {
61
+ describe: 'Name of the kubernetes context on which the app-proxy should be installed'
62
+ + ' (default: current context) [$CF_ARG_KUBE_CONTEXT_NAME]',
63
+ })
64
+ .option('kube-namespace', {
65
+ describe: 'Name of the namespace on which app-proxy should be installed (default:'
66
+ + ` ${INSTALLATION_DEFAULTS.NAMESPACE}) [$CF_ARG_KUBE_NAMESPACE]`,
67
+ type: 'string',
68
+ })
69
+ .option('runtime-environment', {
70
+ describe: 'The Codefresh runtime-environment that this app-proxy will be associated with',
71
+ type: 'string',
72
+ })
73
+ .option('docker-registry', {
74
+ describe: 'The prefix for the container registry that will be used for pulling the app-proxy component image',
75
+ default: 'docker.io',
76
+ type: 'string',
77
+ })
78
+ .option('values', {
79
+ describe: 'specify values in a YAML file',
80
+ })
81
+ .option('set-value', {
82
+ describe: 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes',
83
+ type: 'array',
84
+ })
85
+ .option('verbose', {
86
+ describe: 'Print logs',
87
+ })
88
+ .option('host', {
89
+ describe: 'the hostname that will be used by the app-proxy ingress',
90
+ type: 'string',
91
+ })
92
+ .option('ingress-class', {
93
+ describe: 'the ingress class that will be used by the app-proxy ingress',
94
+ type: 'string',
95
+ })
96
+ .option('bypass-download', {
97
+ describe: 'Will bypass the attempt to download the installer. Instead, will immediately attempt to'
98
+ + ' use the binary from the components folder',
99
+ default: false,
100
+ type: 'boolean',
101
+ }),
102
+
103
+ handler: async (_argv) => {
104
+ const argv = mergeWithValues(_argv);
105
+ const {
106
+ 'kube-config-path': kubeConfigPath,
107
+ 'docker-registry': dockerRegistry,
108
+ verbose,
109
+ values,
110
+ 'set-value': setValues,
111
+ 'ingress-class': ingressClass,
112
+ noExit,
113
+ 'bypass-download': bypassDownload,
114
+ } = argv;
115
+ let {
116
+ host,
117
+ 'kube-namespace': kubeNamespace,
118
+ 'kube-context-name': kubeContextName,
119
+ 'runtime-environment': runtimeEnvironment,
120
+ } = argv;
121
+
122
+ const [listReErr, runtimes] = await to(sdk.runtimeEnvs.list({ }));
123
+ await handleError(listReErr, 'Failed to get account\'s runtime environments');
124
+ const runtimeNames = runtimes.reduce((acc, re) => {
125
+ if (_.get(re, 'metadata.agent')) {
126
+ acc.push(_.get(re, 'metadata.name'));
127
+ }
128
+ return acc;
129
+ }, []);
130
+
131
+ if (_.isEmpty(runtimeNames)) {
132
+ await handleError(
133
+ new Error('no runtime environments found'),
134
+ 'Cannot install app-proxy without a Codefresh runtime-environment',
135
+ );
136
+ }
137
+
138
+ if (!kubeContextName) {
139
+ kubeContextName = getKubeContext(kubeConfigPath);
140
+ }
141
+
142
+ if (!kubeNamespace) {
143
+ kubeNamespace = await selectNamespace();
144
+ }
145
+
146
+ if (!host) {
147
+ host = await selectHost();
148
+ }
149
+
150
+ if (!runtimeEnvironment || !runtimeNames.find(re => re === runtimeEnvironment)) {
151
+ if (runtimeEnvironment) {
152
+ console.log(colors.bold(`Runtime-environment "${colors.cyan(runtimeEnvironment)}" `
153
+ + 'was not found, please choose on of the following:'));
154
+ }
155
+ runtimeEnvironment = await selectRuntime(runtimeNames);
156
+ }
157
+
158
+ printInstallationOptionsSummary({
159
+ kubeContextName,
160
+ kubeNamespace,
161
+ host,
162
+ runtimeEnvironment,
163
+ });
164
+
165
+ console.log('installing app-proxy...');
166
+ const [installationErr] = await to(installAppProxy({
167
+ apiHost: sdk.config.context.url,
168
+ appProxyHost: host,
169
+ appProxyIngressClass: ingressClass,
170
+ kubeConfigPath,
171
+ kubeContextName,
172
+ kubeNamespace,
173
+ dockerRegistry,
174
+ bypassDownload,
175
+ valuesFile: values,
176
+ setValue: setValues,
177
+ verbose,
178
+ }));
179
+ await handleError(installationErr, 'Failed to install app-proxy');
180
+
181
+ const [getREErr, re] = await to(sdk.runtimeEnvs.get({ name: runtimeEnvironment }));
182
+ await handleError(getREErr, 'Failed to get runtime environment');
183
+
184
+ const appProxyUrl = `https://${host}${argv.pathPrefix || ''}`;
185
+
186
+ const body = {
187
+ appProxy: {
188
+ externalIP: appProxyUrl,
189
+ },
190
+ };
191
+ console.log(`updating runtime-environment ${colors.cyan(runtimeEnvironment)} with app-proxy url`);
192
+ await sdk.runtimeEnvs.update({ name: runtimeEnvironment }, _.merge(re, body));
193
+ console.log(`runtime-environment ${colors.cyan(runtimeEnvironment)} updated`);
194
+
195
+ console.log(openIssueMessage);
196
+ await drawCodefreshFiglet();
197
+ if (!noExit) {
198
+ process.exit();
199
+ }
200
+ },
201
+
202
+ });
203
+
204
+ module.exports = installAppProxyHandler;
@@ -0,0 +1,175 @@
1
+ /* eslint-disable max-len */
2
+ const Command = require('../../Command');
3
+ const uninstallRoot = require('../root/uninstall.cmd');
4
+ const inquirer = require('inquirer').default;
5
+ const {
6
+ selectRuntime,
7
+ mergeWithValues,
8
+ selectNamespace,
9
+ } = require('./helper');
10
+ const colors = require('colors');
11
+ const sdk = require('../../../../logic/sdk');
12
+ const _ = require('lodash');
13
+ const { to } = require('../../../../logic/cli-config/errors/awaitTo');
14
+ const {
15
+ createErrorHandler,
16
+ drawCodefreshFiglet,
17
+ unInstallAppProxy,
18
+ INSTALLATION_DEFAULTS,
19
+ } = require('../hybrid/helper');
20
+ const { getKubeContext } = require('../../helpers/kubernetes');
21
+
22
+ const openIssueMessage = `If you had any issues with the uninstallation process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
23
+ const handleError = createErrorHandler(openIssueMessage);
24
+
25
+ async function promptConfirmationMessage() {
26
+ const answer = await inquirer.prompt({
27
+ type: 'confirm',
28
+ name: 'deletionConfirmed',
29
+ default: false,
30
+ message: 'Are you sure you want to delete the app-proxy-component? (default is NO)',
31
+ });
32
+ if (!answer.deletionConfirmed) {
33
+ console.log('Deletion process aborted, exiting...');
34
+ process.exit(1);
35
+ }
36
+ }
37
+
38
+ const uninstallAppProxyHandler = new Command({
39
+ root: false,
40
+ parent: uninstallRoot,
41
+ command: 'app-proxy',
42
+ description: 'Deletes the App-Proxy component from your Kubernetes cluster',
43
+ webDocs: {
44
+ category: 'App-Proxy',
45
+ title: 'Uninstall',
46
+ weight: 100,
47
+ },
48
+ builder: yargs => yargs
49
+ .env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
50
+ .option('kube-context-name', {
51
+ describe: 'Name of the kubernetes context on which the app-proxy is installed'
52
+ + ' (default: current context) [$CF_ARG_KUBE_CONTEXT_NAME]',
53
+ })
54
+ .option('kube-namespace', {
55
+ describe: 'Name of the kubernetes namespace from which the App-Proxy and Runtime should be removed',
56
+ })
57
+ .option('kube-config-path', {
58
+ describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
59
+ default: INSTALLATION_DEFAULTS.KUBECONFIG_PATH,
60
+
61
+ })
62
+ .option('runtime-environment', {
63
+ describe: 'The Codefresh runtime-environment that this App-Proxy will be associated with',
64
+ type: 'string',
65
+ })
66
+ .option('force', {
67
+ describe: 'Run the delete operation without asking to confirm (use with caution!)',
68
+ alias: 'f',
69
+ type: Boolean,
70
+ })
71
+ .option('values', {
72
+ describe: 'specify values in a YAML file',
73
+ })
74
+ .option('set-value', {
75
+ describe: 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes',
76
+ type: 'array',
77
+ })
78
+ .option('verbose', {
79
+ describe: 'Print logs',
80
+ })
81
+ .option('bypass-download', {
82
+ describe: 'Will bypass the attempt to download the installer. Instead, will immediately attempt to'
83
+ + ' use the binary from the components folder',
84
+ default: false,
85
+ type: 'boolean',
86
+ }),
87
+ handler: async (_argv) => {
88
+ const argv = mergeWithValues(_argv);
89
+ const {
90
+ 'kube-config-path': kubeConfigPath,
91
+ force,
92
+ verbose,
93
+ values,
94
+ 'set-value': setValues,
95
+ noExit,
96
+ 'bypass-download': bypassDownload,
97
+ } = argv;
98
+ let {
99
+ 'kube-namespace': kubeNamespace,
100
+ 'kube-context-name': kubeContextName,
101
+ 'runtime-environment': runtimeEnvironment,
102
+ } = argv;
103
+
104
+ const [listReErr, runtimes] = await to(sdk.runtimeEnvs.list({ }));
105
+ await handleError(listReErr, 'Failed to get runtime environments');
106
+ const runtimeNames = runtimes.reduce((acc, re) => {
107
+ if (_.get(re, 'metadata.agent')) {
108
+ acc.push(_.get(re, 'metadata.name'));
109
+ }
110
+ return acc;
111
+ }, []);
112
+
113
+ if (_.isEmpty(runtimeNames)) {
114
+ await handleError(
115
+ new Error('no runtime environments found'),
116
+ 'Cannot uninstall app-proxy without a Codefresh runtime-environment',
117
+ );
118
+ }
119
+
120
+ console.log(colors.green('This uninstaller will guide you through the App-Proxy uninstallation process'));
121
+
122
+ if (!kubeContextName) {
123
+ kubeContextName = getKubeContext(kubeConfigPath);
124
+ }
125
+
126
+ if (!kubeNamespace) {
127
+ kubeNamespace = await selectNamespace();
128
+ }
129
+
130
+ if (!runtimeEnvironment || !runtimeNames.find(re => re === runtimeEnvironment)) {
131
+ if (runtimeEnvironment) {
132
+ console.log(colors.bold(`Runtime-environment "${colors.cyan(runtimeEnvironment)}" `
133
+ + 'was not found, please choose on of the following:'));
134
+ }
135
+ runtimeEnvironment = await selectRuntime(runtimeNames);
136
+ }
137
+
138
+ console.log(`\n${colors.green('Uninstallation options summary:')}
139
+ 1. Kubernetes Context: ${colors.cyan(kubeContextName)}
140
+ 2. Kubernetes Namespace: ${colors.cyan(kubeNamespace)}
141
+ 3. Runtime name: ${colors.cyan(runtimeEnvironment)}
142
+ `);
143
+
144
+ if (!force) {
145
+ await promptConfirmationMessage();
146
+ }
147
+
148
+ const [uninstallErr] = await to(unInstallAppProxy({
149
+ kubeConfigPath,
150
+ kubeContextName,
151
+ kubeNamespace,
152
+ verbose,
153
+ valuesFile: values,
154
+ setValue: setValues,
155
+ bypassDownload,
156
+ }));
157
+ await handleError(uninstallErr, 'Failed to uninstall app-proxy');
158
+
159
+ const [getREErr, re] = await to(sdk.runtimeEnvs.get({ name: runtimeEnvironment }));
160
+ await handleError(getREErr, 'Failed to get runtime environment');
161
+ delete re.appProxy;
162
+
163
+ console.log(`updating runtime-environment ${colors.cyan(runtimeEnvironment)} `);
164
+ await sdk.runtimeEnvs.update({ name: runtimeEnvironment }, re);
165
+
166
+ console.log('Successfully uninstalled App-Proxy');
167
+ console.log(openIssueMessage);
168
+ await drawCodefreshFiglet();
169
+ if (!noExit) {
170
+ process.exit(); // TODO : This is not needed - needed to be fixed
171
+ }
172
+ },
173
+ });
174
+
175
+ module.exports = uninstallAppProxyHandler;
@@ -0,0 +1,110 @@
1
+ /* eslint-disable max-len */
2
+ const Command = require('../../Command');
3
+ const upgradeRoot = require('../root/upgrade.cmd');
4
+ const {
5
+ mergeWithValues,
6
+ selectNamespace,
7
+ } = require('./helper');
8
+ const colors = require('colors');
9
+ const { to } = require('../../../../logic/cli-config/errors/awaitTo');
10
+ const {
11
+ createErrorHandler,
12
+ drawCodefreshFiglet,
13
+ upgradeAppProxy,
14
+ INSTALLATION_DEFAULTS,
15
+ } = require('../hybrid/helper');
16
+ const { getKubeContext } = require('../../helpers/kubernetes');
17
+
18
+ const openIssueMessage = `If you had any issues with the process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
19
+ const handleError = createErrorHandler(openIssueMessage);
20
+
21
+ const upgradeAppProxyHandler = new Command({
22
+ root: false,
23
+ parent: upgradeRoot,
24
+ command: 'app-proxy',
25
+ description: 'Upgrades an existing App-Proxy',
26
+ webDocs: {
27
+ category: 'App-Proxy',
28
+ title: 'Upgrade',
29
+ weight: 100,
30
+ },
31
+ builder: yargs => yargs
32
+ .env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
33
+ .option('kube-context-name', {
34
+ describe: 'Name of the kubernetes context on which the app-proxy is installed'
35
+ + ' (default: current context) [$CF_ARG_KUBE_CONTEXT_NAME]',
36
+ })
37
+ .option('kube-namespace', {
38
+ describe: 'Name of the kubernetes namespace from which the App-Proxy and Runtime should be removed',
39
+ })
40
+ .option('kube-config-path', {
41
+ describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
42
+ default: INSTALLATION_DEFAULTS.KUBECONFIG_PATH,
43
+ })
44
+ .option('values', {
45
+ describe: 'specify values in a YAML file',
46
+ })
47
+ .option('set-value', {
48
+ describe: 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes',
49
+ type: 'array',
50
+ })
51
+ .option('verbose', {
52
+ describe: 'Print logs',
53
+ })
54
+ .option('bypass-download', {
55
+ describe: 'Will bypass the attempt to download the installer. Instead, will immediately attempt to'
56
+ + ' use the binary from the components folder',
57
+ default: false,
58
+ type: 'boolean',
59
+ }),
60
+ handler: async (_argv) => {
61
+ const argv = mergeWithValues(_argv);
62
+ const {
63
+ 'kube-config-path': kubeConfigPath,
64
+ verbose,
65
+ values,
66
+ 'set-value': setValues,
67
+ noExit,
68
+ 'bypass-download': bypassDownload,
69
+ } = argv;
70
+ let {
71
+ 'kube-namespace': kubeNamespace,
72
+ 'kube-context-name': kubeContextName,
73
+ } = argv;
74
+
75
+ console.log(colors.green('This installer will guide you through the App-Proxy upgrade process'));
76
+
77
+ if (!kubeContextName) {
78
+ kubeContextName = getKubeContext(kubeConfigPath);
79
+ }
80
+
81
+ if (!kubeNamespace) {
82
+ kubeNamespace = await selectNamespace();
83
+ }
84
+
85
+ console.log(`\n${colors.green('Upgrade options summary:')}
86
+ 1. Kubernetes Context: ${colors.cyan(kubeContextName)}
87
+ 2. Kubernetes Namespace: ${colors.cyan(kubeNamespace)}
88
+ `);
89
+
90
+ const [upgradeErr] = await to(upgradeAppProxy({
91
+ kubeConfigPath,
92
+ kubeContextName,
93
+ kubeNamespace,
94
+ verbose,
95
+ valuesFile: values,
96
+ setValue: setValues,
97
+ bypassDownload,
98
+ }));
99
+ handleError(upgradeErr, 'Failed to upgrade app-proxy');
100
+
101
+ console.log('Successfully upgraded App-Proxy');
102
+ console.log(openIssueMessage);
103
+ await drawCodefreshFiglet();
104
+ if (!noExit) {
105
+ process.exit(); // TODO : This is not needed - needed to be fixed
106
+ }
107
+ },
108
+ });
109
+
110
+ module.exports = upgradeAppProxyHandler;
@@ -16,7 +16,7 @@ const command = new Command({
16
16
  describe: 'Override download folder location. Default: ~/.Codefresh',
17
17
  })
18
18
  .option('components', {
19
- describe: 'Components. List of [stevedore, venona]',
19
+ describe: 'Components. List of [stevedore, venona, argocd-agent, codefresh]',
20
20
  }),
21
21
  handler: async (argv) => {
22
22
  console.log('Downloading components');
@@ -0,0 +1,9 @@
1
+ const gitopsInstaller = require('../common/install');
2
+
3
+ class ArgoCDInstall {
4
+ // eslint-disable-next-line class-methods-use-this
5
+ async install(argv) {
6
+ return gitopsInstaller.install(argv);
7
+ }
8
+ }
9
+ module.exports = new ArgoCDInstall();
@@ -0,0 +1,11 @@
1
+ const _ = require('lodash');
2
+ const gitopsUninstaller = require('../common/uninstall');
3
+
4
+ class ArgoCDInstall {
5
+ // eslint-disable-next-line class-methods-use-this
6
+ async uninstall(argv) {
7
+ const uninstallOptions = _.pick(argv, ['kube-config-path', 'kube-context-name', 'kube-namespace', 'in-cluster']);
8
+ return gitopsUninstaller.uninstall(argv.provider, uninstallOptions);
9
+ }
10
+ }
11
+ module.exports = new ArgoCDInstall();
@@ -0,0 +1,9 @@
1
+ const gitopsUpgrader = require('../common/upgrade');
2
+
3
+ class ArgoCDUpgrade {
4
+ // eslint-disable-next-line class-methods-use-this
5
+ async upgrade(argv) {
6
+ return gitopsUpgrader.upgrade(argv);
7
+ }
8
+ }
9
+ module.exports = new ArgoCDUpgrade();
@@ -0,0 +1,50 @@
1
+ const fs = require('fs');
2
+ const _ = require('lodash');
3
+ const YAML = require('yaml');
4
+ const gitopsInstaller = require('../common/install');
5
+
6
+ const valuesMapping = {
7
+ 'kube-config-path': 'ConfigPath',
8
+ 'kube-context-name': 'Context',
9
+ 'kube-namespace': 'Namespace',
10
+ 'install-manifest': 'Manifest',
11
+ 'in-cluster': 'InCluster',
12
+
13
+ 'codefresh-host': 'CodefreshHost',
14
+ 'codefresh-token': 'Token',
15
+ 'codefresh-clusters': 'ClustersList',
16
+
17
+ 'argo-password': 'Password',
18
+
19
+ 'git-integration': 'Git',
20
+ 'git-repo-url': 'Repo',
21
+ };
22
+
23
+ function mergeValuesFromValuesFile(argv, valuesFile) {
24
+ const valuesFileStr = fs.readFileSync(valuesFile, 'utf8');
25
+ const valuesObj = YAML.parse(valuesFileStr);
26
+
27
+ Object.keys(valuesMapping)
28
+ .forEach((argvKey) => {
29
+ const valuesKey = valuesMapping[argvKey];
30
+ if (!_.has(argv, argvKey) && _.has(valuesObj, valuesKey)) {
31
+ Object.assign(argv, {
32
+ [argvKey]: _.get(valuesObj, valuesKey),
33
+ [_.camelCase(argvKey)]: _.get(valuesObj, valuesKey),
34
+ });
35
+ }
36
+ });
37
+ }
38
+
39
+ class CodefreshInstall {
40
+ // eslint-disable-next-line class-methods-use-this
41
+ async install(argv) {
42
+ const _argv = _.cloneDeep(argv);
43
+ if (argv.values) {
44
+ mergeValuesFromValuesFile(_argv, _argv.values/* , handleError */);
45
+ }
46
+ await gitopsInstaller.install(_argv);
47
+ }
48
+ }
49
+
50
+ module.exports = new CodefreshInstall();
@@ -0,0 +1,14 @@
1
+ const _ = require('lodash');
2
+ const gitopsUninstaller = require('../common/uninstall');
3
+
4
+ class CodefreshInstall {
5
+ // eslint-disable-next-line class-methods-use-this
6
+ async uninstall(argv) {
7
+ const uninstallOptions = _.pick(argv, [
8
+ 'kube-config-path', 'kube-context-name', 'kube-namespace', 'install-manifest', 'in-cluster',
9
+ ]);
10
+ await gitopsUninstaller.uninstall(argv.provider, uninstallOptions);
11
+ }
12
+ }
13
+
14
+ module.exports = new CodefreshInstall();
@@ -0,0 +1,9 @@
1
+ const gitopsUpgrader = require('../common/upgrade');
2
+
3
+ class CodefreshGitopsUpgrade {
4
+ // eslint-disable-next-line class-methods-use-this
5
+ async upgrade(argv) {
6
+ return gitopsUpgrader.upgrade(argv);
7
+ }
8
+ }
9
+ module.exports = new CodefreshGitopsUpgrade();
@@ -0,0 +1,62 @@
1
+ const { detectProxy } = require('../../../helpers/general');
2
+ const { downloadProvider } = require('../../hybrid/helper');
3
+ const { Runner, components } = require('../../../../../binary');
4
+ const _ = require('lodash');
5
+
6
+ class GitopsInstaller {
7
+ // eslint-disable-next-line class-methods-use-this
8
+ async install(argv) {
9
+ let { httpProxy, httpsProxy } = argv;
10
+ const { kubeConfigPath, provider, argoHost, argoUsername, argoPassword, bypassDownload } = argv;
11
+
12
+ const binLocation = await downloadProvider({ provider }, bypassDownload);
13
+ const componentRunner = new Runner(binLocation);
14
+
15
+ const commands = [
16
+ 'install',
17
+ ];
18
+
19
+ if (kubeConfigPath) {
20
+ commands.push('--kubeconfig');
21
+ commands.push(kubeConfigPath);
22
+ }
23
+
24
+ const installOptions = _.pick(argv, ['git-integration', 'codefresh-integration', 'argo-token', 'output',
25
+ 'update', 'kube-context-name', 'kube-namespace', 'sync-mode', 'sync-apps', 'codefresh-host',
26
+ 'codefresh-token', 'codefresh-agent-suffix', 'in-cluster']);
27
+ installOptions['argo-host'] = argoHost;
28
+ installOptions['argo-username'] = argoUsername;
29
+ installOptions['argo-password'] = argoPassword;
30
+
31
+ _.forEach(_.pickBy(installOptions, _.identity), (value, key) => {
32
+ if (_.isArray(value)) {
33
+ value.forEach((item) => {
34
+ commands.push(`--${key}`);
35
+ commands.push(item);
36
+ });
37
+ } else {
38
+ commands.push(`--${key}`);
39
+ if (value !== true) commands.push(value);
40
+ }
41
+ });
42
+
43
+ const detectedProxyVars = detectProxy();
44
+ httpProxy = httpProxy || detectedProxyVars.httpProxy;
45
+ httpsProxy = httpsProxy || detectedProxyVars.httpsProxy;
46
+
47
+ if (httpProxy) {
48
+ commands.push('--http-proxy');
49
+ commands.push(httpProxy);
50
+ }
51
+
52
+ if (httpsProxy) {
53
+ commands.push('--https-proxy');
54
+ commands.push(httpsProxy);
55
+ }
56
+
57
+
58
+ await componentRunner.run(components.gitops[provider], commands);
59
+ }
60
+ }
61
+
62
+ module.exports = new GitopsInstaller();