|
| 1 | +const Command = require('../../../Command'); |
| 2 | +const { |
| 3 | + promoteChart, |
| 4 | +} = require('./../../../../../logic/api/helm'); |
| 5 | +const { printError } = require('./../../../helpers/general'); |
| 6 | +const { log, workflow } = require('../../../../../logic').api; |
| 7 | + |
| 8 | +const promote = new Command({ |
| 9 | + root: true, |
| 10 | + command: 'helm-promotion', |
| 11 | + description: 'Promote a Helm release in another environment', |
| 12 | + webDocs: { |
| 13 | + category: 'Predefined Pipelines', |
| 14 | + title: 'Promote Helm Release', |
| 15 | + weight: 20, |
| 16 | + }, |
| 17 | + builder: (yargs) => { |
| 18 | + return yargs |
| 19 | + .option('board', { |
| 20 | + description: 'Board for promotion', |
| 21 | + type: 'string', |
| 22 | + required: false, |
| 23 | + }) |
| 24 | + .option('source', { |
| 25 | + description: 'Source column', |
| 26 | + type: 'string', |
| 27 | + required: false, |
| 28 | + }) |
| 29 | + .option('target', { |
| 30 | + description: 'Target column', |
| 31 | + type: 'string', |
| 32 | + required: false, |
| 33 | + }) |
| 34 | + .option('namespace', { |
| 35 | + description: 'Promote to namespace', |
| 36 | + default: 'default', |
| 37 | + type: 'string', |
| 38 | + }) |
| 39 | + .option('source-tiller-namespace', { |
| 40 | + description: 'Where tiller has been installed in source cluster', |
| 41 | + default: 'kube-system', |
| 42 | + type: 'string', |
| 43 | + }) |
| 44 | + .option('target-tiller-namespace', { |
| 45 | + description: 'Where tiller has been installed in target cluster', |
| 46 | + default: 'kube-system', |
| 47 | + type: 'string', |
| 48 | + }) |
| 49 | + .option('source-release', { |
| 50 | + description: 'The name of source release', |
| 51 | + }) |
| 52 | + .option('revision', { |
| 53 | + description: 'Revision of source release', |
| 54 | + type: 'string', |
| 55 | + required: false, |
| 56 | + }) |
| 57 | + .option('target-release', { |
| 58 | + description: 'The name to set to the release', |
| 59 | + }) |
| 60 | + .option('context', { |
| 61 | + description: 'Contexts (yaml || secret-yaml) to be passed to the install', |
| 62 | + array: true, |
| 63 | + }) |
| 64 | + .option('set', { |
| 65 | + description: 'set of KEY=VALUE to be passed to the install', |
| 66 | + array: true, |
| 67 | + }) |
| 68 | + .option('detach', { |
| 69 | + alias: 'd', |
| 70 | + describe: 'Run pipeline and print build ID', |
| 71 | + }) |
| 72 | + .example( |
| 73 | + 'codefresh helm-promotion --board app --source dev --target test --source-release application', |
| 74 | + `Promote 'application' release on board 'app' from 'dev' to 'test' environment`); |
| 75 | + }, |
| 76 | + handler: async (argv) => { |
| 77 | + try { |
| 78 | + const workflowId = await promoteChart({ |
| 79 | + board: argv.board, |
| 80 | + sourceSection: argv.source, |
| 81 | + targetSection: argv.target, |
| 82 | + sourceCluster: argv.sourceCluster, |
| 83 | + tillerNamespace: argv.sourceTillerNamespace, |
| 84 | + releaseName: argv.sourceRelease, |
| 85 | + revision: argv.revision, |
| 86 | + targetCluster: argv.targetCluster, |
| 87 | + targetTillerNamespace: argv.targetTillerNamespace, |
| 88 | + targetNamespace: argv.namespace, |
| 89 | + targetReleaseName: argv.targetRelease, |
| 90 | + values: argv.context, |
| 91 | + setValues: argv.set, |
| 92 | + }); |
| 93 | + if (argv.detach) { |
| 94 | + console.log(workflowId); |
| 95 | + } else { |
| 96 | + await log.showWorkflowLogs(workflowId, true); |
| 97 | + const workflowInstance = await workflow.getWorkflowById(workflowId); |
| 98 | + switch (workflowInstance.getStatus()) { |
| 99 | + case 'success': |
| 100 | + process.exit(0); |
| 101 | + break; |
| 102 | + case 'error': |
| 103 | + process.exit(1); |
| 104 | + break; |
| 105 | + case 'terminated': |
| 106 | + process.exit(2); |
| 107 | + break; |
| 108 | + default: |
| 109 | + process.exit(100); |
| 110 | + break; |
| 111 | + } |
| 112 | + } |
| 113 | + } catch (err) { |
| 114 | + printError(err); |
| 115 | + process.exit(1); |
| 116 | + } |
| 117 | + }, |
| 118 | +}); |
| 119 | + |
| 120 | +module.exports = promote; |
0 commit comments