Skip to content

Commit 7f8b0d2

Browse files
argocd installer cli (#547)
1 parent 78fcb35 commit 7f8b0d2

File tree

4 files changed

+142
-1
lines changed

4 files changed

+142
-1
lines changed

lib/binary/components.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,22 @@ module.exports = {
3535
repo: 'venona',
3636
},
3737
},
38+
argo: {
39+
name: 'argo',
40+
description: 'Install argocd agent',
41+
version: {
42+
prefix: '',
43+
},
44+
local: {
45+
versionFile: 'version.txt',
46+
dir: 'argo',
47+
binary: 'argocd-agent',
48+
},
49+
remote: {
50+
versionPath: 'installer',
51+
versionFile: 'VERSION',
52+
branch: 'master',
53+
repo: 'argocd-agent',
54+
},
55+
},
3856
};
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/* eslint-disable max-len */
2+
const Command = require('../../Command');
3+
const installRoot = require('../root/install.cmd');
4+
const { downloadArgo } = require('../hybrid/helper');
5+
const { Runner, components } = require('../../../../binary');
6+
7+
const installArgoCmd = new Command({
8+
root: false,
9+
parent: installRoot,
10+
command: 'argo',
11+
description: 'Install argo agent',
12+
webDocs: {
13+
category: 'Argo',
14+
title: 'Install',
15+
weight: 100,
16+
},
17+
builder: yargs => yargs
18+
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
19+
.option('token', {
20+
describe: 'Codefresh user token',
21+
})
22+
.option('kube-context-name', {
23+
describe: 'Name of the kubernetes context on which monitor should be installed [$CF_ARG_KUBE_CONTEXT_NAME]',
24+
})
25+
.option('url', {
26+
describe: 'Codefresh url, by default https://g.codefresh.io',
27+
})
28+
.option('kube-namespace', {
29+
describe: 'Name of the namespace on which monitor should be installed [$CF_ARG_KUBE_NAMESPACE]',
30+
})
31+
.option('argo-host', {
32+
describe: 'Argocd host, exaple is https://argohost.com',
33+
})
34+
.option('argo-username', {
35+
describe: 'Argocd admin username',
36+
})
37+
.option('argo-password', {
38+
describe: 'Argocd admin password',
39+
}),
40+
handler: async (argv) => {
41+
const {
42+
url,
43+
token,
44+
'kube-context-name': kubeContextName,
45+
'kube-namespace': kubeNamespace,
46+
'argo-host': argoHost,
47+
'argo-password': argoPassword,
48+
'argo-username': argoUsername,
49+
} = argv;
50+
const binLocation = await downloadArgo();
51+
const componentRunner = new Runner(binLocation);
52+
53+
const commands = [
54+
'install',
55+
];
56+
57+
if (token) {
58+
commands.push('--codefresh-token');
59+
commands.push(token);
60+
}
61+
62+
if (kubeContextName) {
63+
commands.push('--kube-context-name');
64+
commands.push(kubeContextName);
65+
}
66+
67+
if (kubeNamespace) {
68+
commands.push('--kube-namespace');
69+
commands.push(kubeNamespace);
70+
}
71+
72+
if (url) {
73+
commands.push('--codefresh-host');
74+
commands.push(url);
75+
}
76+
77+
if (argoHost) {
78+
commands.push('--argo-host');
79+
commands.push(argoHost);
80+
}
81+
82+
if (argoPassword) {
83+
commands.push('--argo-password');
84+
commands.push(argoPassword);
85+
}
86+
87+
if (argoUsername) {
88+
commands.push('--argo-username');
89+
commands.push(argoUsername);
90+
}
91+
92+
93+
await componentRunner.run(components.argo, commands);
94+
},
95+
});
96+
97+
module.exports = installArgoCmd;

lib/interface/cli/commands/hybrid/helper.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,31 @@ async function downloadVeonona(location = CODEFRESH_PATH) {
353353
}
354354
return location;
355355
}
356+
357+
async function downloadArgo(location = CODEFRESH_PATH) {
358+
const downloader = new Downloader({
359+
progress: new cliProgress.SingleBar(
360+
{
361+
stopOnComplete: true,
362+
format: CommonProgressFormat,
363+
},
364+
cliProgress.Presets.shades_classic,
365+
),
366+
location,
367+
});
368+
const [error] = await to(downloader.download(components.argo));
369+
if (error) {
370+
const newLocation = path.join(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER, components.argo.local.dir, components.argo.local.binary);
371+
if (await pathExists(newLocation)) {
372+
console.log('Failed to download installer, using binary from components folder');
373+
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
374+
}
375+
console.log('Failed to download component, aborting');
376+
throw error;
377+
}
378+
return location;
379+
}
380+
356381
async function downloadSteveDore(location = CODEFRESH_PATH) {
357382
const downloader = new Downloader({
358383
progress: new cliProgress.SingleBar(
@@ -743,6 +768,7 @@ module.exports = {
743768
downloadRelatedComponents: downloadHybridComponents,
744769
downloadSteveDore,
745770
downloadVeonona,
771+
downloadArgo,
746772
runUpgrade,
747773
detectProxy,
748774
serealizeToKeyValuePairs,

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

0 commit comments

Comments
 (0)