Skip to content

Commit 70df5d8

Browse files
Saas 6077 (#416)
* support progress (un)install/install agent/runtime
1 parent 752e593 commit 70df5d8

File tree

8 files changed

+125
-11
lines changed

8 files changed

+125
-11
lines changed

lib/interface/cli/commands/agent/install.cmd.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const installRoot = require('../root/install.cmd');
44
const { sdk } = require('../../../../logic');
55
const installRuntimeCmd = require('../runtimeEnvironments/install.cmd');
66
const { getKubeContext } = require('../../helpers/kubernetes');
7+
const ProgressEvents = require('../../helpers/progressEvents');
8+
const cliProgress = require('cli-progress');
79

810
const installAgentCmd = new Command({
911
root: false,
@@ -107,6 +109,20 @@ const installAgentCmd = new Command({
107109
name = data.name;
108110
}
109111
const apiHost = sdk.config.context.url;
112+
const events = new ProgressEvents();
113+
const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
114+
const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
115+
let totalSize;
116+
events.onStart((size) => {
117+
progressBar.start(size, 0);
118+
totalSize = size;
119+
});
120+
events.onProgress((progress) => {
121+
progressBar.update(progress);
122+
if (progress >= totalSize) {
123+
console.log('\n');
124+
}
125+
});
110126
const agentInstallStatusCode = await sdk.agents.install({
111127
apiHost,
112128
kubeContextName,
@@ -123,6 +139,7 @@ const installAgentCmd = new Command({
123139
verbose,
124140
agentId: name,
125141
terminateProcess: !installRuntime,
142+
events,
126143
});
127144
if (agentInstallStatusCode !== 0) {
128145
throw new Error(`\nAgent installation failed with code ${agentInstallStatusCode}`);

lib/interface/cli/commands/agent/uninstall.cmd.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const deleteAgent = require('../agent/delete.cmd');
44
const unInstallRoot = require('../root/uninstall.cmd');
55
const { sdk } = require('../../../../logic');
66
const { getKubeContext } = require('../../helpers/kubernetes');
7+
const ProgressEvents = require('../../helpers/progressEvents');
8+
const cliProgress = require('cli-progress');
79

810

911
const unInstallAgentCmd = new Command({
@@ -51,12 +53,28 @@ const unInstallAgentCmd = new Command({
5153
throw new Error('Name is a mandatory parameter');
5254
}
5355

56+
const events = new ProgressEvents();
57+
const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
58+
const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
59+
let totalSize;
60+
events.onStart((size) => {
61+
progressBar.start(size, 0);
62+
totalSize = size;
63+
});
64+
events.onProgress((progress) => {
65+
progressBar.update(progress);
66+
if (progress >= totalSize) {
67+
console.log('\n');
68+
}
69+
});
70+
5471

5572
const exitCode = await sdk.agents.unInstall({
5673
kubeContextName,
5774
kubeNamespace,
5875
kubeConfigPath,
5976
terminateProcess: false,
77+
events,
6078
});
6179
if (exitCode === 0) {
6280
await deleteAgent.handler({ name, id: name });

lib/interface/cli/commands/runtimeEnvironments/attach.cmd.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
const _ = require('lodash');
33
const Command = require('../../Command');
44
const { sdk } = require('../../../../logic');
5+
const ProgressEvents = require('../../helpers/progressEvents');
6+
const cliProgress = require('cli-progress');
57

68

79
const attachAgentToRuntime = async (agent, runtime) => {
@@ -93,6 +95,20 @@ const attachRuntimeCmd = new Command({
9395

9496
// call venonactl to attach
9597

98+
const events = new ProgressEvents();
99+
const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
100+
const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
101+
let totalSize;
102+
events.onStart((size) => {
103+
progressBar.start(size, 0);
104+
totalSize = size;
105+
});
106+
events.onProgress((progress) => {
107+
progressBar.update(progress);
108+
if (progress >= totalSize) {
109+
console.log('\n');
110+
}
111+
});
96112
await sdk.runtime.attach({
97113
kubeContextName,
98114
kubeNamespace,
@@ -104,6 +120,7 @@ const attachRuntimeCmd = new Command({
104120
verbose,
105121
restartAgent,
106122
terminateProcess: false,
123+
events,
107124
});
108125
if (!restartAgent) {
109126
console.log('Please restart agent\'s pod in order that changes will take effect');

lib/interface/cli/commands/runtimeEnvironments/install.cmd.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const { sdk } = require('../../../../logic');
44
const attachRuntimeCmd = require('./attach.cmd');
55
const installRoot = require('../root/install.cmd');
66
const { getKubeContext } = require('../../helpers/kubernetes');
7+
const ProgressEvents = require('../../helpers/progressEvents');
8+
const cliProgress = require('cli-progress');
79

810

911
const _getAgentData = async (token) => {
@@ -137,6 +139,21 @@ const installRuntimeCmd = new Command({
137139
console.log(`Runtime envrionment ${runtimeName} was created`);
138140
// install RE on cluster
139141

142+
const events = new ProgressEvents();
143+
const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
144+
const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
145+
let totalSize;
146+
events.onStart((size) => {
147+
progressBar.start(size, 0);
148+
totalSize = size;
149+
});
150+
events.onProgress((progress) => {
151+
progressBar.update(progress);
152+
if (progress >= totalSize) {
153+
console.log('\n');
154+
}
155+
});
156+
140157
const installRuntimeExitCode = await sdk.runtime.install({
141158
apiHost,
142159
name: runtimeName,
@@ -149,6 +166,7 @@ const installRuntimeCmd = new Command({
149166
kubeConfigPath,
150167
verbose,
151168
terminateProcess: !attachRuntime,
169+
events,
152170
});
153171
// attach RE to agent in codefresh
154172

lib/interface/cli/commands/runtimeEnvironments/uninstall.cmd.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const unInstallRoot = require('../root/uninstall.cmd');
44
const { sdk } = require('../../../../logic');
55
const { getKubeContext } = require('../../helpers/kubernetes');
66
const _ = require('lodash');
7+
const ProgressEvents = require('../../helpers/progressEvents');
8+
const cliProgress = require('cli-progress');
79

810

911
const detachRuntimeFromAgent = async (agent, runtimeName) => {
@@ -106,6 +108,21 @@ const unInstallRuntimeCmd = new Command({
106108

107109
// Get agent
108110

111+
const events = new ProgressEvents();
112+
const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
113+
const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
114+
let totalSize;
115+
events.onStart((size) => {
116+
progressBar.start(size, 0);
117+
totalSize = size;
118+
});
119+
events.onProgress((progress) => {
120+
progressBar.update(progress);
121+
if (progress >= totalSize) {
122+
console.log('\n');
123+
}
124+
});
125+
109126
await sdk.runtime.unInstall({
110127
runtimeName,
111128
kubeContextName,
@@ -118,6 +135,7 @@ const unInstallRuntimeCmd = new Command({
118135
storageClassName,
119136
verbose,
120137
terminateProcess: true,
138+
events,
121139
});
122140
},
123141
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const EventEmitter = require('events');
2+
3+
class ProgressEvents {
4+
constructor() {
5+
this.emitter = new EventEmitter();
6+
}
7+
onStart(handler) {
8+
this.emitter.addListener('start', (args) => {
9+
handler(args);
10+
});
11+
}
12+
onProgress(handler) {
13+
this.emitter.addListener('progress', (args) => {
14+
handler(args);
15+
});
16+
}
17+
reportStart(args) {
18+
this.emitter.emit('start', args);
19+
}
20+
reportProgress(args) {
21+
this.emitter.emit('progress', args);
22+
}
23+
}
24+
25+
module.exports = ProgressEvents;

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.43.8",
3+
"version": "0.43.9",
44

55
"description": "Codefresh command line utility",
66
"main": "index.js",
@@ -37,8 +37,8 @@
3737
"bluebird": "^3.5.1",
3838
"cf-errors": "^0.1.12",
3939
"chalk": "^1.1.3",
40-
"cli-progress": "^1.6.1",
41-
"codefresh-sdk": "1.5.1",
40+
"cli-progress": "3.6.0",
41+
"codefresh-sdk": "1.5.2",
4242
"colors": "^1.1.2",
4343
"columnify": "^1.5.4",
4444
"compare-versions": "^3.4.0",

yarn.lock

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,12 +1111,13 @@ cli-cursor@^2.1.0:
11111111
dependencies:
11121112
restore-cursor "^2.0.0"
11131113

1114-
cli-progress@^1.6.1:
1115-
version "1.8.0"
1116-
resolved "https://registry.yarnpkg.com/cli-progress/-/cli-progress-1.8.0.tgz#5e8afc310f2058fbe33e9006e31c71c1c3b5da7f"
1117-
integrity sha1-Xor8MQ8gWPvjPpAG4xxxwcO12n8=
1114+
cli-progress@3.6.0:
1115+
version "3.6.0"
1116+
resolved "https://registry.yarnpkg.com/cli-progress/-/cli-progress-3.6.0.tgz#20317e6a653c3e5636fb5f03a7d67cd48ebc215a"
1117+
integrity sha512-elg6jkiDedYrvwqWSae2FGvtbMo37Lo04oI9jJ5cI43Ge3jrDPWzeL3axv7MgBLYHDY/kGio/CXa49m4MWMrNw==
11181118
dependencies:
11191119
colors "^1.1.2"
1120+
string-width "^2.1.1"
11201121

11211122
cli-spinners@^2.0.0:
11221123
version "2.2.0"
@@ -1186,10 +1187,10 @@ code-point-at@^1.0.0:
11861187
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
11871188
integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=
11881189

1189-
codefresh-sdk@1.5.1:
1190-
version "1.5.1"
1191-
resolved "https://registry.yarnpkg.com/codefresh-sdk/-/codefresh-sdk-1.5.1.tgz#7719e9d2ef9afd9472155493ba469632519b8cac"
1192-
integrity sha512-q3u/b7Q85TPc5RYs5TBzrkcmOu3U3Yc+D5ZrBT5viTNQEV4xiTUCPDKrEA+v9W4fJPFf00sMnYwB6IMAHiEicw==
1190+
codefresh-sdk@1.5.2:
1191+
version "1.5.2"
1192+
resolved "https://registry.yarnpkg.com/codefresh-sdk/-/codefresh-sdk-1.5.2.tgz#0b0515ecb46a0ccc2ea4859670b6816d8e8c527f"
1193+
integrity sha512-WZY/ziw/ksrbpQKcrI6OIjC+pNeSbDSrvU/ky5qiRGvYfu4AHZNUn5pqki4Tn9YvAYVZ3ZL1wuGqbYhqtm8wBw==
11931194
dependencies:
11941195
bluebird "^3.5.3"
11951196
cf-errors "^0.1.12"

0 commit comments

Comments
 (0)