codefresh 0.84.10 → 0.86.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +12 -6
- package/Dockerfile-debian +15 -6
- package/Dockerfile-debian-rootless +15 -7
- package/Dockerfile-rootless +13 -7
- package/__mocks__/codefresh.yml +40 -0
- package/docs/index.js +19 -18
- package/lib/interface/cli/commands/agent/install.cmd.js +191 -113
- package/lib/interface/cli/commands/root/root.sdk.spec.js +1 -1
- package/lib/interface/cli/commands/runtimeEnvironments/attach.cmd.js +105 -84
- package/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js +216 -188
- package/lib/interface/cli/completion/tree.json +1 -1
- package/package.json +3 -3
- package/codefresh-arm.yml +0 -253
- package/codefresh-release.yml +0 -482
- package/codefresh.yml +0 -373
|
@@ -1,27 +1,107 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
2
|
const _ = require('lodash');
|
|
3
|
+
const cliProgress = require('cli-progress');
|
|
3
4
|
const Command = require('../../Command');
|
|
4
5
|
const { sdk } = require('../../../../logic');
|
|
5
6
|
const ProgressEvents = require('../../helpers/progressEvents');
|
|
6
|
-
const cliProgress = require('cli-progress');
|
|
7
7
|
const { getKubeContext } = require('../../helpers/kubernetes');
|
|
8
|
-
const { DefaultLogFormatter } = require('
|
|
8
|
+
const { DefaultLogFormatter } = require('../hybrid/helper');
|
|
9
|
+
|
|
10
|
+
async function attachInPlatform(argv) {
|
|
11
|
+
const {
|
|
12
|
+
agentName,
|
|
13
|
+
agentId,
|
|
14
|
+
runtimeName,
|
|
15
|
+
} = argv;
|
|
16
|
+
let agent;
|
|
17
|
+
if (_.isEmpty(runtimeName)) {
|
|
18
|
+
throw new Error('runtime name is mandatory');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (agentName) {
|
|
22
|
+
agent = await sdk.agents.getByName({ name: agentName });
|
|
23
|
+
} else if (agentId) {
|
|
24
|
+
agent = await sdk.agents.get({ agentId });
|
|
25
|
+
} else {
|
|
26
|
+
throw new Error('agent name or agent id is needed');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (agent === '' || !agent) {
|
|
30
|
+
throw new Error('agent was not found');
|
|
31
|
+
}
|
|
9
32
|
|
|
10
|
-
const
|
|
11
|
-
const rt = await sdk.runtimeEnvs.get({ name });
|
|
33
|
+
const rt = await sdk.runtimeEnvs.get({ name: runtimeName });
|
|
12
34
|
if (!rt) {
|
|
13
|
-
throw new Error(`runtime ${
|
|
35
|
+
throw new Error(`runtime ${runtimeName} does not exist on the account`);
|
|
14
36
|
}
|
|
37
|
+
|
|
15
38
|
if (!rt.metadata.agent) {
|
|
16
39
|
throw new Error('cannot attach non hybrid runtime');
|
|
17
40
|
}
|
|
41
|
+
|
|
18
42
|
const runtimes = _.get(agent, 'runtimes', []);
|
|
19
|
-
const existingRT = _.find(runtimes, value => value ===
|
|
43
|
+
const existingRT = _.find(runtimes, (value) => value === runtimeName);
|
|
20
44
|
if (!existingRT) {
|
|
21
|
-
runtimes.push(
|
|
45
|
+
runtimes.push(runtimeName);
|
|
22
46
|
await sdk.agents.update({ agentId: agent.id, runtimes });
|
|
23
47
|
}
|
|
24
|
-
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function attachInCluster(argv) {
|
|
51
|
+
const {
|
|
52
|
+
runtimeName,
|
|
53
|
+
runtimeKubeConfigPath,
|
|
54
|
+
runtimeKubeContextName = getKubeContext(runtimeKubeConfigPath),
|
|
55
|
+
runtimeKubeNamespace,
|
|
56
|
+
agentKubeConfigPath,
|
|
57
|
+
agentKubeContextName = runtimeKubeContextName,
|
|
58
|
+
agentKubeNamespace,
|
|
59
|
+
runtimeKubeServiceAccount,
|
|
60
|
+
restartAgent,
|
|
61
|
+
verbose,
|
|
62
|
+
} = argv;
|
|
63
|
+
if (_.isNull(runtimeName) || _.isUndefined(runtimeName) || runtimeName === '') {
|
|
64
|
+
throw new Error('runtime name is mandatory');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!runtimeKubeNamespace) {
|
|
68
|
+
throw new Error('runtime-kube-namespace is mandatory parameter');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// call venonactl to attach
|
|
72
|
+
const events = new ProgressEvents();
|
|
73
|
+
const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
|
|
74
|
+
const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
|
|
75
|
+
let totalSize;
|
|
76
|
+
events.onStart((size) => {
|
|
77
|
+
progressBar.start(size, 0);
|
|
78
|
+
totalSize = size;
|
|
79
|
+
});
|
|
80
|
+
events.onProgress((progress) => {
|
|
81
|
+
progressBar.update(progress);
|
|
82
|
+
if (progress >= totalSize) {
|
|
83
|
+
console.log('\n');
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
await sdk.runtime.attach({
|
|
87
|
+
runtimeName,
|
|
88
|
+
kubeConfigPath: runtimeKubeConfigPath,
|
|
89
|
+
kubeContextName: runtimeKubeContextName,
|
|
90
|
+
kubeNamespace: runtimeKubeNamespace,
|
|
91
|
+
kubeServiceAccount: runtimeKubeServiceAccount,
|
|
92
|
+
agentKubeConfigPath,
|
|
93
|
+
agentKubeContextName,
|
|
94
|
+
agentKubeNamespace,
|
|
95
|
+
verbose,
|
|
96
|
+
restartAgent,
|
|
97
|
+
terminateProcess: false,
|
|
98
|
+
events,
|
|
99
|
+
logFormatting: DefaultLogFormatter,
|
|
100
|
+
});
|
|
101
|
+
if (!restartAgent) {
|
|
102
|
+
console.log('Please restart agent\'s pod in order that changes will take effect');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
25
105
|
|
|
26
106
|
const attachRuntimeCmd = new Command({
|
|
27
107
|
root: true,
|
|
@@ -33,7 +113,7 @@ const attachRuntimeCmd = new Command({
|
|
|
33
113
|
title: 'Attach Runtime-Environments',
|
|
34
114
|
weight: 100,
|
|
35
115
|
},
|
|
36
|
-
builder: yargs => yargs
|
|
116
|
+
builder: (yargs) => yargs
|
|
37
117
|
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
|
|
38
118
|
.option('runtime-name', {
|
|
39
119
|
describe: 'Runtime\'s name',
|
|
@@ -59,101 +139,42 @@ const attachRuntimeCmd = new Command({
|
|
|
59
139
|
.option('agent-kube-namespace', {
|
|
60
140
|
describe: 'Agent\'s namespace',
|
|
61
141
|
})
|
|
142
|
+
.option('agent-kube-service-account', {
|
|
143
|
+
describe: 'The service account to use for the agent pod',
|
|
144
|
+
})
|
|
62
145
|
.option('agent-kube-config-path', {
|
|
63
146
|
describe: 'Path to kubeconfig file for the agent (default is $HOME/.kube/config)',
|
|
64
147
|
})
|
|
65
148
|
.option('restart-agent', {
|
|
66
149
|
describe: 'restart agent afte install - default false',
|
|
67
150
|
})
|
|
151
|
+
.option('platform-only', {
|
|
152
|
+
describe: 'Set to true to attach runtime to agent on the platform side only',
|
|
153
|
+
})
|
|
68
154
|
.option('verbose', {
|
|
69
155
|
describe: 'Print logs',
|
|
70
156
|
}),
|
|
71
157
|
handler: async (argv) => {
|
|
72
158
|
const {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
'runtime-kube-namespace': kubeNamespace,
|
|
77
|
-
'runtime-kube-config-path': kubeConfigPath,
|
|
78
|
-
'agent-kube-namespace': agentKubeNamespace,
|
|
79
|
-
'agent-kube-config-path': agentKubeConfigPath,
|
|
80
|
-
'runtime-kube-serviceaccount': kubeServiceAccount,
|
|
81
|
-
'restart-agent': restartAgent,
|
|
82
|
-
verbose,
|
|
83
|
-
|
|
159
|
+
runtimeKubeNamespace,
|
|
160
|
+
platformOnly,
|
|
161
|
+
terminateProcess,
|
|
84
162
|
} = argv;
|
|
85
|
-
|
|
86
|
-
'runtime-kube-context-name': kubeContextName,
|
|
87
|
-
'agent-kube-context-name': agentKubeContextName,
|
|
88
|
-
} = argv;
|
|
89
|
-
const { terminateProcess } = argv;
|
|
90
|
-
let agent;
|
|
91
|
-
if (_.isNull(runtimeName) || _.isUndefined(runtimeName) || runtimeName === '') {
|
|
92
|
-
throw new Error('runtime name is mandatory');
|
|
93
|
-
}
|
|
94
|
-
if (agentName) {
|
|
95
|
-
agent = await sdk.agents.getByName({ name: agentName });
|
|
96
|
-
} else if (agentId) {
|
|
97
|
-
agent = await sdk.agents.get({ agentId });
|
|
98
|
-
} else {
|
|
99
|
-
throw new Error('agent name or agent id is needed');
|
|
100
|
-
}
|
|
101
|
-
if (agent === '' || !agent) {
|
|
102
|
-
throw new Error('agent was not found');
|
|
103
|
-
}
|
|
104
|
-
if (!kubeNamespace) {
|
|
163
|
+
if (!runtimeKubeNamespace && !platformOnly) {
|
|
105
164
|
throw new Error('runtime-kube-namespace is mandatory parameter');
|
|
106
165
|
}
|
|
107
|
-
if (!kubeContextName) {
|
|
108
|
-
kubeContextName = getKubeContext(kubeConfigPath);
|
|
109
|
-
}
|
|
110
|
-
if (!agentKubeContextName) {
|
|
111
|
-
agentKubeContextName = kubeContextName;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
await attachAgentToRuntime(agent, runtimeName);
|
|
115
|
-
|
|
116
|
-
// call venonactl to attach
|
|
117
166
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
let totalSize;
|
|
122
|
-
events.onStart((size) => {
|
|
123
|
-
progressBar.start(size, 0);
|
|
124
|
-
totalSize = size;
|
|
125
|
-
});
|
|
126
|
-
events.onProgress((progress) => {
|
|
127
|
-
progressBar.update(progress);
|
|
128
|
-
if (progress >= totalSize) {
|
|
129
|
-
console.log('\n');
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
await sdk.runtime.attach({
|
|
133
|
-
kubeContextName,
|
|
134
|
-
kubeServiceAccount,
|
|
135
|
-
kubeNamespace,
|
|
136
|
-
kubeConfigPath,
|
|
137
|
-
agentKubeContextName,
|
|
138
|
-
agentKubeNamespace,
|
|
139
|
-
agentKubeConfigPath,
|
|
140
|
-
runtimeName,
|
|
141
|
-
verbose,
|
|
142
|
-
restartAgent,
|
|
143
|
-
terminateProcess: false,
|
|
144
|
-
events,
|
|
145
|
-
logFormatting: DefaultLogFormatter,
|
|
146
|
-
});
|
|
147
|
-
if (!restartAgent) {
|
|
148
|
-
console.log('Please restart agent\'s pod in order that changes will take effect');
|
|
167
|
+
await attachInPlatform(argv);
|
|
168
|
+
if (!platformOnly) {
|
|
169
|
+
await attachInCluster(argv);
|
|
149
170
|
}
|
|
171
|
+
|
|
150
172
|
if (terminateProcess || terminateProcess === undefined) {
|
|
151
173
|
process.exit();
|
|
152
|
-
} else {
|
|
153
|
-
return 0;
|
|
154
174
|
}
|
|
175
|
+
|
|
176
|
+
return 0;
|
|
155
177
|
},
|
|
156
178
|
});
|
|
157
179
|
|
|
158
|
-
|
|
159
180
|
module.exports = attachRuntimeCmd;
|