|
2 | 2 | const _ = require('lodash');
|
3 | 3 | const Command = require('../../Command');
|
4 | 4 | const installRoot = require('../root/install.cmd');
|
5 |
| -const { detectProxy } = require('../../helpers/general'); |
6 |
| -const { downloadProvider } = require('../hybrid/helper'); |
7 |
| -const { Runner, components } = require('../../../../binary'); |
8 |
| -const { install: installArgocd } = require('./install-codefresh'); |
| 5 | + |
| 6 | +const PROVIDERS = { |
| 7 | + codefresh: require('./codefresh/install'), |
| 8 | + 'argocd-agent': require('./argocd/install'), |
| 9 | +}; |
9 | 10 |
|
10 | 11 | const installArgoCmd = new Command({
|
11 | 12 | root: false,
|
@@ -81,78 +82,11 @@ const installArgoCmd = new Command({
|
81 | 82 | describe: 'Set password for admin user of new argocd installation',
|
82 | 83 | }),
|
83 | 84 | handler: async (argv) => {
|
84 |
| - let { provider, httpProxy, httpsProxy, argoHost, argoUsername, argoPassword } = argv; |
85 |
| - const { kubeConfigPath, installManifest, kubeNamespace, setArgoPassword } = argv; |
86 |
| - |
87 |
| - if (provider === 'codefresh') { |
88 |
| - if (!setArgoPassword) { |
89 |
| - console.error('\nMissing required argument: set-argo-password'); |
90 |
| - process.exit(1); |
91 |
| - } |
92 |
| - |
93 |
| - if (!kubeNamespace) { |
94 |
| - console.error('\nMissing required argument: kube-namespace'); |
95 |
| - process.exit(1); |
96 |
| - } |
97 |
| - |
98 |
| - const result = await installArgocd({ |
99 |
| - installManifest, |
100 |
| - kubeNamespace, |
101 |
| - setArgoPassword, |
102 |
| - }); |
103 |
| - |
104 |
| - provider = 'argocd-agent'; |
105 |
| - argoHost = result.host; |
106 |
| - argoUsername = 'admin'; |
107 |
| - argoPassword = setArgoPassword; |
108 |
| - } |
109 |
| - |
110 |
| - const binLocation = await downloadProvider({ provider }); |
111 |
| - const componentRunner = new Runner(binLocation); |
112 |
| - |
113 |
| - const commands = [ |
114 |
| - 'install', |
115 |
| - ]; |
116 |
| - |
117 |
| - if (kubeConfigPath) { |
118 |
| - commands.push('--kubeconfig'); |
119 |
| - commands.push(kubeConfigPath); |
120 |
| - } |
121 |
| - |
122 |
| - const installOptions = _.pick(argv, ['git-integration', 'codefresh-integration', 'argo-token', 'output', |
123 |
| - 'update', 'kube-context-name', 'kube-namespace', 'sync-mode', 'sync-apps']); |
124 |
| - installOptions['argo-host'] = argoHost; |
125 |
| - installOptions['argo-username'] = argoUsername; |
126 |
| - installOptions['argo-password'] = argoPassword; |
127 |
| - |
128 |
| - _.forEach(_.pickBy(installOptions, _.identity), (value, key) => { |
129 |
| - if (_.isArray(value)) { |
130 |
| - value.forEach((item) => { |
131 |
| - commands.push(`--${key}`); |
132 |
| - commands.push(item); |
133 |
| - }); |
134 |
| - } else { |
135 |
| - commands.push(`--${key}`); |
136 |
| - if (value !== true) commands.push(value); |
137 |
| - } |
138 |
| - }); |
139 |
| - |
140 |
| - const detectedProxyVars = detectProxy(); |
141 |
| - httpProxy = httpProxy || detectedProxyVars.httpProxy; |
142 |
| - httpsProxy = httpsProxy || detectedProxyVars.httpsProxy; |
143 |
| - |
144 |
| - if (httpProxy) { |
145 |
| - commands.push('--http-proxy'); |
146 |
| - commands.push(httpProxy); |
147 |
| - } |
148 |
| - |
149 |
| - if (httpsProxy) { |
150 |
| - commands.push('--https-proxy'); |
151 |
| - commands.push(httpsProxy); |
152 |
| - } |
| 85 | + const { provider } = argv; |
153 | 86 |
|
| 87 | + const providerInstaller = PROVIDERS[provider]; |
| 88 | + return providerInstaller.install(argv); |
154 | 89 |
|
155 |
| - await componentRunner.run(components.gitops[provider], commands); |
156 | 90 | },
|
157 | 91 | });
|
158 | 92 |
|
|
0 commit comments