Skip to content

Commit c44aea6

Browse files
committed
chore(cli): show a warning on a platform with a known bug
A particular combination of software has hard-to-recover bug. Add a check and warning for it. Closes #21379.
1 parent 52edf29 commit c44aea6

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

packages/aws-cdk/lib/cli.ts

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Command, Configuration, Settings } from '../lib/settings';
2525
import * as version from '../lib/version';
2626
import { DeploymentMethod } from './api';
2727
import { enableTracing } from './util/tracing';
28+
import { checkForPlatformWarnings } from './platform-warnings';
2829

2930
// https://github.com/yargs/yargs/issues/1929
3031
// https://github.com/evanw/esbuild/issues/1492
@@ -294,6 +295,9 @@ async function initCommandLine() {
294295
if (argv.ci) {
295296
setCI(true);
296297
}
298+
299+
await checkForPlatformWarnings();
300+
297301
debug('CDK toolkit version:', version.DISPLAY_VERSION);
298302
debug('Command line arguments:', argv);
299303

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as os from 'os';
2+
import * as logging from './logging';
3+
import * as fs from 'fs-extra';
4+
5+
export async function checkForPlatformWarnings() {
6+
if (await hasDockerCopyBug()) {
7+
logging.warning('`cdk synth` may hang in Docker on Linux 5.6-5.10. See https://github.com/aws/aws-cdk/issues/21379 for workarounds.');
8+
}
9+
}
10+
11+
async function hasDockerCopyBug() {
12+
return await runningInDocker() && os.platform() === 'linux' && isVersionBetween(os.release(), '5.6', '5.10');
13+
}
14+
15+
async function runningInDocker() {
16+
return fs.pathExists('/.dockerenv');
17+
}
18+
19+
export function isVersionBetween(version: string, lower: string, upper: string) {
20+
const ver = splitVersion(version);
21+
const lo = splitVersion(lower);
22+
const up = splitVersion(upper);
23+
24+
while (lo.length < ver.length) { lo.push(0); }
25+
while (up.length < ver.length) { up.push(9999999); }
26+
27+
console.log(version);
28+
29+
let n = ver.length;
30+
for (let i = 0; i < n; i++) {
31+
if (lo[i] < ver[i] && ver[i] < up[i]) { return true; }
32+
if (lo[i] > ver[i] || ver[i] > up[i]) { return false; }
33+
}
34+
35+
return false;
36+
37+
// return lo[n-1] <= ver[n-1] && ver[n-1] <= up[n-1];
38+
}
39+
40+
function splitVersion(version: string): number[] {
41+
return `${version}`.split('.')
42+
.map(x => parseInt(x, 10))
43+
.map(x => isNaN(x) ? 0 : x);
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { isVersionBetween } from '../lib/platform-warnings';
2+
3+
4+
test.each([
5+
['2.1', false],
6+
['2.2', true],
7+
['2', false],
8+
['3', true],
9+
['4', false],
10+
['4.3', true],
11+
['4.3', true],
12+
['4.2.294-220.533.amzn2.x86_64', true],
13+
])('%p is in range: %p', (version, expected) => {
14+
expect(isVersionBetween(version, '2.1.0.6', '4.9.2')).toEqual(expected);
15+
});

0 commit comments

Comments
 (0)