Skip to content

Commit f8e41ac

Browse files
authored
chore(cli): show a warning on a platform with a known bug (#23076)
A particular combination of software has hard-to-diagnose bug. Add a check and warning for it. Closes #21379. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1a11938 commit f8e41ac

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

packages/aws-cdk/lib/cli.ts

+8
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,13 @@ async function initCommandLine() {
294295
if (argv.ci) {
295296
setCI(true);
296297
}
298+
299+
try {
300+
await checkForPlatformWarnings();
301+
} catch (e) {
302+
debug(`Error while checking for platform warnings: ${e}`);
303+
}
304+
297305
debug('CDK toolkit version:', version.DISPLAY_VERSION);
298306
debug('Command line arguments:', argv);
299307

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
let n = ver.length;
28+
for (let i = 0; i < n; i++) {
29+
if (lo[i] < ver[i] && ver[i] < up[i]) { return true; }
30+
if (lo[i] > ver[i] || ver[i] > up[i]) { return false; }
31+
}
32+
33+
return false;
34+
35+
}
36+
37+
function splitVersion(version: string): number[] {
38+
return `${version}`.split('.')
39+
.map(x => parseInt(x, 10))
40+
.map(x => isNaN(x) ? 0 : x);
41+
}
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)