Skip to content

Commit

Permalink
argocd installer cli (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
pasha-codefresh authored Aug 3, 2020
1 parent 78fcb35 commit 7f8b0d2
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lib/binary/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,22 @@ module.exports = {
repo: 'venona',
},
},
argo: {
name: 'argo',
description: 'Install argocd agent',
version: {
prefix: '',
},
local: {
versionFile: 'version.txt',
dir: 'argo',
binary: 'argocd-agent',
},
remote: {
versionPath: 'installer',
versionFile: 'VERSION',
branch: 'master',
repo: 'argocd-agent',
},
},
};
97 changes: 97 additions & 0 deletions lib/interface/cli/commands/argocd/install.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* eslint-disable max-len */
const Command = require('../../Command');
const installRoot = require('../root/install.cmd');
const { downloadArgo } = require('../hybrid/helper');
const { Runner, components } = require('../../../../binary');

const installArgoCmd = new Command({
root: false,
parent: installRoot,
command: 'argo',
description: 'Install argo agent',
webDocs: {
category: 'Argo',
title: 'Install',
weight: 100,
},
builder: yargs => yargs
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
.option('token', {
describe: 'Codefresh user token',
})
.option('kube-context-name', {
describe: 'Name of the kubernetes context on which monitor should be installed [$CF_ARG_KUBE_CONTEXT_NAME]',
})
.option('url', {
describe: 'Codefresh url, by default https://g.codefresh.io',
})
.option('kube-namespace', {
describe: 'Name of the namespace on which monitor should be installed [$CF_ARG_KUBE_NAMESPACE]',
})
.option('argo-host', {
describe: 'Argocd host, exaple is https://argohost.com',
})
.option('argo-username', {
describe: 'Argocd admin username',
})
.option('argo-password', {
describe: 'Argocd admin password',
}),
handler: async (argv) => {
const {
url,
token,
'kube-context-name': kubeContextName,
'kube-namespace': kubeNamespace,
'argo-host': argoHost,
'argo-password': argoPassword,
'argo-username': argoUsername,
} = argv;
const binLocation = await downloadArgo();
const componentRunner = new Runner(binLocation);

const commands = [
'install',
];

if (token) {
commands.push('--codefresh-token');
commands.push(token);
}

if (kubeContextName) {
commands.push('--kube-context-name');
commands.push(kubeContextName);
}

if (kubeNamespace) {
commands.push('--kube-namespace');
commands.push(kubeNamespace);
}

if (url) {
commands.push('--codefresh-host');
commands.push(url);
}

if (argoHost) {
commands.push('--argo-host');
commands.push(argoHost);
}

if (argoPassword) {
commands.push('--argo-password');
commands.push(argoPassword);
}

if (argoUsername) {
commands.push('--argo-username');
commands.push(argoUsername);
}


await componentRunner.run(components.argo, commands);
},
});

module.exports = installArgoCmd;
26 changes: 26 additions & 0 deletions lib/interface/cli/commands/hybrid/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,31 @@ async function downloadVeonona(location = CODEFRESH_PATH) {
}
return location;
}

async function downloadArgo(location = CODEFRESH_PATH) {
const downloader = new Downloader({
progress: new cliProgress.SingleBar(
{
stopOnComplete: true,
format: CommonProgressFormat,
},
cliProgress.Presets.shades_classic,
),
location,
});
const [error] = await to(downloader.download(components.argo));
if (error) {
const newLocation = path.join(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER, components.argo.local.dir, components.argo.local.binary);
if (await pathExists(newLocation)) {
console.log('Failed to download installer, using binary from components folder');
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
}
console.log('Failed to download component, aborting');
throw error;
}
return location;
}

async function downloadSteveDore(location = CODEFRESH_PATH) {
const downloader = new Downloader({
progress: new cliProgress.SingleBar(
Expand Down Expand Up @@ -743,6 +768,7 @@ module.exports = {
downloadRelatedComponents: downloadHybridComponents,
downloadSteveDore,
downloadVeonona,
downloadArgo,
runUpgrade,
detectProxy,
serealizeToKeyValuePairs,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.71.7",
"version": "0.71.8",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit 7f8b0d2

Please sign in to comment.