Skip to content

Commit 70a1a5c

Browse files
Saas 7579 (#516)
check node version
1 parent 3147420 commit 70a1a5c

File tree

9 files changed

+54
-22
lines changed

9 files changed

+54
-22
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ WORKDIR /cf-cli
2828
COPY package.json /cf-cli
2929
COPY yarn.lock /cf-cli
3030
COPY check-version.js /cf-cli
31+
COPY run-check-version.js /cf-cli
3132

3233
RUN yarn install --prod --frozen-lockfile && \
3334
yarn cache clean

check-version.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
const semver = require('semver');
22
const { engines } = require('./package');
33

4-
const version = engines.node;
5-
if (!semver.satisfies(process.version, version)) {
6-
throw new Error(`Required node version ${version} not satisfied with current version ${process.version}.`);
4+
function checkVersion(version = engines.node) {
5+
if (!semver.satisfies(process.version, version)) {
6+
throw new Error(`Required node version ${version} not satisfied with current version ${process.version}.`);
7+
}
78
}
9+
// checkVersion();
810

11+
module.exports = {
12+
checkVersion,
13+
};

lib/interface/cli/commands/hybrid/init.cmd.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,12 @@ const initCmd = new Command({
368368
installationPlan.addStep({
369369
name: 'create new runtime',
370370
func: async () => {
371+
const reName = installationPlan.getContext('runtimeName');
371372
const runtimeCreateOpt = {
372373
namespace: kubeNamespace,
373374
storageClassName: storageClassName || `${INSTALLATION_DEFAULTS.STORAGE_CLASS_PREFIX}-${kubeNamespace}`,
374375
clusterName: kubeContextName,
375-
runtimeEnvironmentName: installationPlan.getContext('runtimeName'),
376+
runtimeEnvironmentName: reName,
376377
agent: true,
377378
};
378379

@@ -381,6 +382,7 @@ const initCmd = new Command({
381382
}
382383

383384
await sdk.cluster.create(runtimeCreateOpt);
385+
console.log(`Runtime environment "${colors.cyan(reName)}" has been created`);
384386
},
385387
});
386388

lib/interface/cli/commands/pipeline/pipeline.sdk.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { positionalHandler } = require('./get.completion');
77
const { sdk } = require('../../../../logic');
88

99
jest.mock('../../helpers/validation'); // eslint-disable-line
10-
10+
jest.mock('../../../../../check-version');
1111
jest.mock('../../completion/helpers', () => { // eslint-disable-line
1212
return {
1313
authContextWrapper: func => func,

lib/interface/cli/helpers/helpers.sdk.spec.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jest.mock('../../../logic/entities/Context', () => ({
1515
getType: () => 'yaml',
1616
}),
1717
}));
18+
jest.mock('./../../../../check-version');
19+
const versionChecker = require('./../../../../check-version');
1820

1921
jest.mock('../../../logic/entities/Workflow', () => ({
2022
fromResponse: () => ({
@@ -65,6 +67,15 @@ describe('helpers using sdk', () => {
6567
expect(sdk.logs.showWorkflowLogs).toBeCalled();
6668
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
6769
});
70+
it('should not show logs if check version throw an exception', async () => {
71+
const workflowId = 'id';
72+
jest.spyOn(sdk.logs, 'showWorkflowLogs').mockImplementation();
73+
versionChecker.checkVersion.mockImplementationOnce(() => {
74+
throw new Error();
75+
});
76+
await followLogs(workflowId);
77+
expect(sdk.logs.showWorkflowLogs).not.toBeCalled();
78+
});
6879
});
6980

7081
describe('auth', () => {
@@ -151,12 +162,10 @@ describe('helpers using sdk', () => {
151162

152163
it('should log all contexts when filter is "all"', async () => {
153164
sdk.config.context = Config.manager().getCurrentContext();
154-
const verifyContexts = _.map(_.values(Config.MOCK_CONTEXTS), (context) => {
155-
return _.mapValues(_.pick(context, context.defaultColumns), (val, key) => {
156-
if (key === 'current') return chalk.green('*');
157-
return val;
158-
});
159-
});
165+
const verifyContexts = _.map(_.values(Config.MOCK_CONTEXTS), context => _.mapValues(_.pick(context, context.defaultColumns), (val, key) => {
166+
if (key === 'current') return chalk.green('*');
167+
return val;
168+
}));
160169

161170
await printTableForAuthContexts();
162171

lib/interface/cli/helpers/logs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const CFError = require('cf-errors');
66
const { sdk } = require('../../../logic');
77
const Workflow = require('../../../logic/entities/Workflow');
88
const Output = require('../../../output/Output');
9+
const { checkVersion } = require('./../../../../check-version');
10+
11+
const nodeVersionToValidate = '<=10.x >=8.x';
912

1013
const END_STATUSES = ['error', 'success', 'terminated'];
1114

@@ -53,6 +56,15 @@ async function _fallbackLogs(workflowId, interval, retriesLeft) {
5356
}
5457

5558
const followLogs = async (workflowId) => {
59+
try {
60+
checkVersion(nodeVersionToValidate);
61+
} catch (error) {
62+
const url = _.get(sdk, 'config.context.url', 'https://g.codefresh.io');
63+
const buildLink = `${url}/build/${workflowId}`;
64+
// eslint-disable-next-line max-len
65+
console.log(`Your node version (${process.version}) is not compatible with supported node version (${nodeVersionToValidate}) for this command, click the link to see it in codefresh UI : ${buildLink}`);
66+
return;
67+
}
5668
try {
5769
await sdk.logs.showWorkflowLogs(workflowId, true);
5870
} catch (e) {

lib/logic/entities/Agent.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ class Agent extends Entity {
1010
this.name = data.name;
1111
this.runtimes = data.runtimes;
1212
const status = _.get(data, 'status.healthStatus', 'N/A');
13-
this.status = this._pickStatusColor(status)(status);
13+
this.status = Agent._pickStatusColor(status)(status);
1414
const lastReported = _.get(data, 'status.reportedAt', 'N/A');
15-
this.reported = this._pickLastReportedColor(status)(lastReported);
15+
this.reported = Agent._pickLastReportedColor(status)(lastReported);
1616
this.defaultColumns = ['name', 'runtimes', 'status', 'reported'];
1717
}
1818

19-
// eslint-disable-next-line class-methods-use-this
20-
_pickLastReportedColor(healthStatus) {
19+
static _pickLastReportedColor(healthStatus) {
2120
switch (healthStatus) {
2221
case 'N/A':
2322
return chalk.gray;
@@ -30,19 +29,20 @@ class Agent extends Entity {
3029
}
3130
}
3231

33-
_pickStatusColor(healthStatus) {
32+
static _pickStatusColor(healthStatus) {
3433
switch (healthStatus) {
3534
case 'N/A':
36-
return chalk.white.bgGray;
35+
return chalk.white.bgGray || _.identity;
3736
case 'unhealthy':
38-
return chalk.white.bgRed;
37+
return chalk.white.bgRed || _.identity;
3938
case 'healthy':
40-
return chalk.black.bgGreen;
39+
return chalk.black.bgGreen || _.identity;
4140
default:
42-
return chalk.black.bgRed;
41+
return chalk.black.bgRed || _.identity;
4342
}
4443
}
4544

45+
4646
static fromResponse(response) {
4747
return new Agent(_.pick(response, 'id', 'name', 'runtimes', 'status', 'lastReported'));
4848
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"serve-docs-beta": "ALLOW_BETA_COMMANDS=true yarn build-local-docs && cd temp && hugo server -D",
1515
"build-local-docs": "node ./docs/index.js",
1616
"build-public-docs": "node ./docs/index.js && cd temp && hugo",
17-
"postinstall": "node check-version.js"
17+
"postinstall": "node run-check-version.js"
1818
},
1919
"bin": {
2020
"codefresh": "./lib/interface/cli/codefresh"
@@ -91,7 +91,7 @@
9191
"author": "Codefresh",
9292
"license": "ISC",
9393
"engines": {
94-
"node": ">=8.0.0"
94+
"node": ">=8.x"
9595
},
9696
"jest": {
9797
"testEnvironment": "node",

run-check-version.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { checkVersion } = require('./check-version');
2+
3+
checkVersion();

0 commit comments

Comments
 (0)