-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcxcloud-deploy.js
More file actions
65 lines (54 loc) · 1.76 KB
/
cxcloud-deploy.js
File metadata and controls
65 lines (54 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
'use strict';
const chalk = require('chalk');
const program = require('commander');
const { showError, logOperation, sleep } = require('./utils');
const env = require('./utils/env');
const docker = require('./utils/docker');
const kube = require('./utils/kube');
async function deploy(cmd) {
try {
await env.checkEnvironment();
const config = await env.readDeploymentManifest();
const hasDockerRepository = Boolean(
config.deployment && config.deployment.image.repository
);
// Purge action
if (cmd.purge || cmd.purgeAll) {
logOperation('Purging deployment...');
await kube.deleteService(config, cmd.env, cmd.purgeAll);
return;
}
// Deployment action
await env.ensureDeployEnvironment(hasDockerRepository);
// Build and tag container if repository is defined
if (hasDockerRepository) {
await docker.dockerLogin();
await docker.dockerTag(config);
}
await kube.deployService(config, cmd.env);
logOperation('Waiting for deployment to be complete...');
await sleep(5000); // 5 seconds
if (config.routing) {
console.log(`\n${chalk.green('Success! Your routing is now set up.')}`);
}
if (config.deployment) {
console.log(`\n${chalk.green('Success! Your service is now deployed.')}`);
console.log('You can see more information about it below:\n\n');
await kube.getIngressInfo(config);
}
} catch (err) {
console.log(err);
showError(err);
}
}
program
.option(
'-e, --env <env>',
'Comma separated list of environment variables',
input => input.split(',')
)
.option('-p, --purge', 'Purge the deployment')
.option('-x, --purge-all', 'Purge the deployment and namespace')
.action(deploy)
.parse(process.argv);