Skip to content

Commit

Permalink
add test release command
Browse files Browse the repository at this point in the history
  • Loading branch information
olegs-codefresh authored Jan 14, 2018
1 parent c29c554 commit c863895
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
installChart,
} = require('./../../../../../logic/api/helm');
const { printError } = require('./../../../helpers/general');
const { log } = require('../../../../../logic').api;

const install = new Command({
root: true,
Expand Down Expand Up @@ -62,6 +63,8 @@ const install = new Command({
tillerNamespace: argv.tillerNamespace,
});
console.log(`Started with id: ${workflowId}`);
log.showWorkflowLogs(workflowId, true);
process.exit(0);
} catch (err) {
printError(err);
process.exit(1);
Expand Down
53 changes: 53 additions & 0 deletions lib/interface/cli/commands/pipeline/dynamic/test-release.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const Command = require('../../../Command');
const {
testRelease,
} = require('./../../../../../logic/api/helm');
const { printError } = require('./../../../helpers/general');
const { log } = require('../../../../../logic').api;

const install = new Command({
root: true,
command: 'test-release [name]',
description: 'Test helm releaes',
builder: (yargs) => {
return yargs
.usage('Test helm relaese')
.option('cluster', {
description: 'Install on cluster',
type: 'string',
required: true,
})
.option('timeout', {
description: 'time in seconds to wait for any individual kubernetes operation (like Jobs for hooks) (default 300)',
default: '300',
type: 'number',
})
.option('cleanup', {
description: 'delete test pods upon completion (default false)',
default: 'false',
type: 'boolean',
});
},
handler: async (argv) => {
const releaseName = argv.name;
if (!releaseName) {
throw new Error('Release name is required');
}
try {
const workflowId = await testRelease({
releaseName,
cluster: argv.cluster,
cleanup: argv.cleanup,
timeout: argv.timeout,
});
console.log(`Started with id: ${workflowId}`);
await log.showWorkflowLogs(workflowId, true);
process.exit(0);
} catch (err) {
printError(err);
process.exit(1);
}
},
});

module.exports = install;
31 changes: 29 additions & 2 deletions lib/logic/api/helm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const Promise = require('bluebird');
const _ = require('lodash');
const CFError = require('cf-errors'); // eslint-disable-line
const { sendHttpRequest } = require('./helper');
const { getContextByName } = require('./context');
const {
sendHttpRequest,
} = require('./helper');
const {
getContextByName,
} = require('./context');

const SUPPORTED_TYPES = [
'yaml',
Expand Down Expand Up @@ -65,6 +69,29 @@ const installChart = async ({
return res.id;
};

const testRelease = async ({
releaseName,
cluster,
cleanup,
timeout,
}) => {
const options = {
url: `/api/kubernetes/release/test/${releaseName}`,
method: 'POST',
qs: {
selector: cluster,
},
body: {
cleanup,
timeout,
},
};

const res = await sendHttpRequest(options);
return res.id;
};

module.exports = {
installChart,
testRelease,
};
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.6.91",
"version": "0.7.0",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit c863895

Please sign in to comment.