Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions lib/binary/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ class Runner {
});
});
}

runAndAttach(component, args) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not portable :(

const dir = join(this.location, component.local.dir);
const path = component.local.alternateBinary || join(dir, component.local.binary);
const cp = spawn(path, args, {
stdio: [process.stdin, process.stdout, process.stderr, 'pipe'],
});
return cp;
}
}

module.exports = { Runner };
22 changes: 22 additions & 0 deletions lib/interface/cli/commands/app-proxy/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ const selectRuntime = async (runtimes) => {
return ans.re;
};

const selectNamespace = async () => {
const ans = await inquirer.prompt({
type: 'input',
name: 'namespace',
message: 'Name of Kubernetes namespace to use',
default: INSTALLATION_DEFAULTS.NAMESPACE,
});
return ans.namespace;
};

const selectHost = async () => {
const ans = await inquirer.prompt({
type: 'input',
name: 'host',
message: 'The hostname that will be used by the app-proxy ingress',
default: INSTALLATION_DEFAULTS.NAMESPACE,
});
return ans.host;
};

const setIfNotDefined = (obj, prop, value) => {
_.set(obj, prop, _.get(obj, prop, value));
};
Expand All @@ -38,4 +58,6 @@ const mergeWithValues = (argv) => {
module.exports = {
selectRuntime,
mergeWithValues,
selectNamespace,
selectHost,
};
35 changes: 27 additions & 8 deletions lib/interface/cli/commands/app-proxy/install.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ const {
const { getKubeContext } = require('../../helpers/kubernetes');
const sdk = require('../../../../logic/sdk');
const { to } = require('../../../../logic/cli-config/errors/awaitTo');
const { mergeWithValues, selectRuntime } = require('./helper');
const {
mergeWithValues,
selectRuntime,
selectNamespace,
selectHost,
} = require('./helper');

const openIssueMessage = 'If you had any issues with this installation process please report them at:'
+ ` ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
Expand All @@ -38,7 +43,7 @@ const installAppProxyHandler = new Command({
root: false,
parent: installRoot,
command: 'app-proxy',
description: 'Install the App-Proxy component on your Kubernetes cluster',
description: 'Installs the App-Proxy component on your Kubernetes cluster',
webDocs: {
category: 'App-Proxy',
title: 'Install',
Expand All @@ -54,7 +59,7 @@ const installAppProxyHandler = new Command({
})
.option('kube-context-name', {
describe: 'Name of the kubernetes context on which the app-proxy should be installed'
+ ` (default: ${getKubeContext()}) [$CF_ARG_KUBE_CONTEXT_NAME]`,
+ ' (default: current context) [$CF_ARG_KUBE_CONTEXT_NAME]',
})
.option('kube-namespace', {
describe: 'Name of the namespace on which app-proxy should be installed (default:'
Expand Down Expand Up @@ -93,17 +98,17 @@ const installAppProxyHandler = new Command({
const argv = mergeWithValues(_argv);
const {
'kube-config-path': kubeConfigPath,
'kube-context-name': kubeContextName,
'kube-namespace': kubeNamespace,
'docker-registry': dockerRegistry,
verbose,
values,
'set-value': setValues,
host,
'ingress-class': ingressClass,
noExit,
} = argv;
let {
host,
'kube-namespace': kubeNamespace,
'kube-context-name': kubeContextName,
'runtime-environment': runtimeEnvironment,
} = argv;

Expand All @@ -122,6 +127,19 @@ const installAppProxyHandler = new Command({
'Cannot install app-proxy without a Codefresh runtime-environment',
);
}

if (!kubeContextName) {
kubeContextName = getKubeContext(kubeConfigPath);
}

if (!kubeNamespace) {
kubeNamespace = await selectNamespace();
}

if (!host) {
host = await selectHost();
}

if (!runtimeEnvironment || !runtimeNames.find(re => re === runtimeEnvironment)) {
if (runtimeEnvironment) {
console.log(colors.bold(`Runtime-environment "${colors.cyan(runtimeEnvironment)}" `
Expand All @@ -138,7 +156,7 @@ const installAppProxyHandler = new Command({
});

console.log('installing app-proxy...');
const appProxyUrl = await installAppProxy({
const [installationErr, appProxyUrl] = await to(installAppProxy({
apiHost: sdk.config.context.url,
appProxyHost: host,
appProxyIngressClass: ingressClass,
Expand All @@ -149,7 +167,8 @@ const installAppProxyHandler = new Command({
valuesFile: values,
setValue: setValues,
verbose,
});
}));
await handleError(installationErr, 'Failed to install app-proxy');

const [getREErr, re] = await to(sdk.runtimeEnvs.get({ name: runtimeEnvironment }));
await handleError(getREErr, 'Failed to get runtime environment');
Expand Down
28 changes: 22 additions & 6 deletions lib/interface/cli/commands/app-proxy/uninstall.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
const Command = require('../../Command');
const uninstallRoot = require('../root/uninstall.cmd');
const inquirer = require('inquirer');
const { selectRuntime, mergeWithValues } = require('./helper');
const {
selectRuntime,
mergeWithValues,
selectNamespace,
} = require('./helper');
const colors = require('colors');
const sdk = require('../../../../logic/sdk');
const _ = require('lodash');
Expand All @@ -13,6 +17,7 @@ const {
unInstallAppProxy,
INSTALLATION_DEFAULTS,
} = require('../hybrid/helper');
const { getKubeContext } = require('../../helpers/kubernetes');

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')}`;
const handleError = createErrorHandler(openIssueMessage);
Expand Down Expand Up @@ -43,7 +48,8 @@ const uninstallAppProxyHandler = new Command({
builder: yargs => yargs
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
.option('kube-context-name', {
describe: 'Name of the kubernetes context from which the App-Proxy and Runtime should be removed',
describe: 'Name of the kubernetes context on which the app-proxy is installed'
+ ' (default: current context) [$CF_ARG_KUBE_CONTEXT_NAME]',
})
.option('kube-namespace', {
describe: 'Name of the kubernetes namespace from which the App-Proxy and Runtime should be removed',
Expand Down Expand Up @@ -75,8 +81,6 @@ const uninstallAppProxyHandler = new Command({
handler: async (_argv) => {
const argv = mergeWithValues(_argv);
const {
'kube-context-name': kubeContextName,
'kube-namespace': kubeNamespace,
'kube-config-path': kubeConfigPath,
force,
verbose,
Expand All @@ -85,6 +89,8 @@ const uninstallAppProxyHandler = new Command({
noExit,
} = argv;
let {
'kube-namespace': kubeNamespace,
'kube-context-name': kubeContextName,
'runtime-environment': runtimeEnvironment,
} = argv;

Expand All @@ -106,6 +112,14 @@ const uninstallAppProxyHandler = new Command({

console.log(colors.green('This uninstaller will guide you through the App-Proxy uninstallation process'));

if (!kubeContextName) {
kubeContextName = getKubeContext(kubeConfigPath);
}

if (!kubeNamespace) {
kubeNamespace = await selectNamespace();
}

if (!runtimeEnvironment || !runtimeNames.find(re => re === runtimeEnvironment)) {
if (runtimeEnvironment) {
console.log(colors.bold(`Runtime-environment "${colors.cyan(runtimeEnvironment)}" `
Expand All @@ -124,15 +138,17 @@ const uninstallAppProxyHandler = new Command({
await promptConfirmationMessage();
}

await unInstallAppProxy({
const [uninstallErr] = await to(unInstallAppProxy({
kubeConfigPath,
kubeContextName,
kubeNamespace,
verbose,
valuesFile: values,
setValue: setValues,

});
}));
await handleError(uninstallErr, 'Failed to uninstall app-proxy');

const [getREErr, re] = await to(sdk.runtimeEnvs.get({ name: runtimeEnvironment }));
await handleError(getREErr, 'Failed to get runtime environment');
delete re.appProxy;
Expand Down
102 changes: 102 additions & 0 deletions lib/interface/cli/commands/app-proxy/upgrade.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* eslint-disable max-len */
const Command = require('../../Command');
const upgradeRoot = require('../root/upgrade.cmd');
const {
mergeWithValues,
selectNamespace,
} = require('./helper');
const colors = require('colors');
const { to } = require('../../../../logic/cli-config/errors/awaitTo');
const {
createErrorHandler,
drawCodefreshFiglet,
upgradeAppProxy,
INSTALLATION_DEFAULTS,
} = require('../hybrid/helper');
const { getKubeContext } = require('../../helpers/kubernetes');

const openIssueMessage = `If you had any issues with the process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
const handleError = createErrorHandler(openIssueMessage);

const upgradeAppProxyHandler = new Command({
root: false,
parent: upgradeRoot,
command: 'app-proxy',
description: 'Upgrades an existing App-Proxy',
webDocs: {
category: 'App-Proxy',
title: 'Upgrade',
weight: 100,
},
builder: yargs => yargs
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
.option('kube-context-name', {
describe: 'Name of the kubernetes context on which the app-proxy is installed'
+ ' (default: current context) [$CF_ARG_KUBE_CONTEXT_NAME]',
})
.option('kube-namespace', {
describe: 'Name of the kubernetes namespace from which the App-Proxy and Runtime should be removed',
})
.option('kube-config-path', {
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
default: INSTALLATION_DEFAULTS.KUBECONFIG_PATH,
})
.option('values', {
describe: 'specify values in a YAML file',
})
.option('set-value', {
describe: 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes',
type: 'array',
})
.option('verbose', {
describe: 'Print logs',
}),
handler: async (_argv) => {
const argv = mergeWithValues(_argv);
const {
'kube-config-path': kubeConfigPath,
verbose,
values,
'set-value': setValues,
noExit,
} = argv;
let {
'kube-namespace': kubeNamespace,
'kube-context-name': kubeContextName,
} = argv;

console.log(colors.green('This installer will guide you through the App-Proxy upgrade process'));

if (!kubeContextName) {
kubeContextName = getKubeContext(kubeConfigPath);
}

if (!kubeNamespace) {
kubeNamespace = await selectNamespace();
}

console.log(`\n${colors.green('Upgrade options summary:')}
1. Kubernetes Context: ${colors.cyan(kubeContextName)}
2. Kubernetes Namespace: ${colors.cyan(kubeNamespace)}
`);

const [upgradeErr] = await to(upgradeAppProxy({
kubeConfigPath,
kubeContextName,
kubeNamespace,
verbose,
valuesFile: values,
setValue: setValues,
}));
handleError(upgradeErr, 'Failed to upgrade app-proxy');

console.log('Successfully upgraded App-Proxy');
console.log(openIssueMessage);
await drawCodefreshFiglet();
if (!noExit) {
process.exit(); // TODO : This is not needed - needed to be fixed
}
},
});

module.exports = upgradeAppProxyHandler;
Loading