Skip to content

Commit 4806fb7

Browse files
add new gitops installer (#612)
* add new gitops installer * add new gitops installer * fix test
1 parent 512ccd5 commit 4806fb7

File tree

8 files changed

+112
-200
lines changed

8 files changed

+112
-200
lines changed

lib/binary/components.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,23 @@ module.exports = {
5555
repo: 'argocd-agent',
5656
},
5757
},
58+
codefresh: {
59+
name: 'cf-gitops-controller',
60+
description: 'Install gitops codefresh controller',
61+
version: {
62+
prefix: '',
63+
},
64+
local: {
65+
versionFile: 'version.txt',
66+
dir: 'cf-gitops-controller',
67+
binary: 'cf-gitops-controller',
68+
},
69+
remote: {
70+
versionPath: '/',
71+
versionFile: 'VERSION',
72+
branch: 'main',
73+
repo: 'cf-gitops-controller',
74+
},
75+
},
5876
},
5977
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const gitopsInstaller = require('../common/install');
2+
const argocdInstaller = require('../argocd/install');
3+
4+
class CodefreshInstall {
5+
// eslint-disable-next-line class-methods-use-this
6+
async install(argv) {
7+
await gitopsInstaller.install(argv);
8+
return argocdInstaller.install({
9+
...argv,
10+
provider: 'argocd-agent',
11+
});
12+
}
13+
}
14+
module.exports = new CodefreshInstall();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 } = argv;
11+
12+
const binLocation = await downloadProvider({ provider });
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']);
26+
installOptions['argo-host'] = argoHost;
27+
installOptions['argo-username'] = argoUsername;
28+
installOptions['argo-password'] = argoPassword;
29+
30+
_.forEach(_.pickBy(installOptions, _.identity), (value, key) => {
31+
if (_.isArray(value)) {
32+
value.forEach((item) => {
33+
commands.push(`--${key}`);
34+
commands.push(item);
35+
});
36+
} else {
37+
commands.push(`--${key}`);
38+
if (value !== true) commands.push(value);
39+
}
40+
});
41+
42+
const detectedProxyVars = detectProxy();
43+
httpProxy = httpProxy || detectedProxyVars.httpProxy;
44+
httpsProxy = httpsProxy || detectedProxyVars.httpsProxy;
45+
46+
if (httpProxy) {
47+
commands.push('--http-proxy');
48+
commands.push(httpProxy);
49+
}
50+
51+
if (httpsProxy) {
52+
commands.push('--https-proxy');
53+
commands.push(httpsProxy);
54+
}
55+
56+
57+
await componentRunner.run(components.gitops[provider], commands);
58+
}
59+
}
60+
61+
module.exports = new GitopsInstaller();

lib/interface/cli/commands/gitops/install-codefresh.js

Lines changed: 0 additions & 114 deletions
This file was deleted.

lib/interface/cli/commands/gitops/install.cmd.js

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
const _ = require('lodash');
33
const Command = require('../../Command');
44
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+
};
910

1011
const installArgoCmd = new Command({
1112
root: false,
@@ -81,78 +82,11 @@ const installArgoCmd = new Command({
8182
describe: 'Set password for admin user of new argocd installation',
8283
}),
8384
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;
15386

87+
const providerInstaller = PROVIDERS[provider];
88+
return providerInstaller.install(argv);
15489

155-
await componentRunner.run(components.gitops[provider], commands);
15690
},
15791
});
15892

lib/interface/cli/commands/gitops/install.spec.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ const installCmd = require('./install.cmd').toCommand();
22
const { Runner } = require('../../../../binary');
33
const yargs = require('yargs');
44

5-
jest.mock('./install-codefresh', () => ({
6-
install: async () => ({ host: 'host' }),
7-
}));
8-
95
jest.mock('../hybrid/helper', () => ({
106
downloadProvider: async () => {},
117
}));
@@ -71,17 +67,11 @@ describe('install gitops', () => {
7167
const { calls } = Runner.mock.instances[0].run.mock;
7268
expect(calls).toHaveLength(1);
7369
const [component, commands] = calls[0];
74-
expect(component.name).toEqual('gitops');
70+
expect(component.name).toEqual('cf-gitops-controller');
7571
expect(commands).toEqual([
7672
'install',
7773
'--kube-namespace',
7874
'ns',
79-
'--argo-host',
80-
'host',
81-
'--argo-username',
82-
'admin',
83-
'--argo-password',
84-
'pass',
8575
]);
8676
});
8777
});

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.73.34",
3+
"version": "0.74.0",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)