forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cli): show a warning on a platform with a known bug (aws#23076)
A particular combination of software has hard-to-diagnose bug. Add a check and warning for it. Closes aws#21379. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as os from 'os'; | ||
import * as logging from './logging'; | ||
import * as fs from 'fs-extra'; | ||
|
||
export async function checkForPlatformWarnings() { | ||
if (await hasDockerCopyBug()) { | ||
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.'); | ||
} | ||
} | ||
|
||
async function hasDockerCopyBug() { | ||
return await runningInDocker() && os.platform() === 'linux' && isVersionBetween(os.release(), '5.6', '5.10'); | ||
} | ||
|
||
async function runningInDocker() { | ||
return fs.pathExists('/.dockerenv'); | ||
} | ||
|
||
export function isVersionBetween(version: string, lower: string, upper: string) { | ||
const ver = splitVersion(version); | ||
const lo = splitVersion(lower); | ||
const up = splitVersion(upper); | ||
|
||
while (lo.length < ver.length) { lo.push(0); } | ||
while (up.length < ver.length) { up.push(9999999); } | ||
|
||
let n = ver.length; | ||
for (let i = 0; i < n; i++) { | ||
if (lo[i] < ver[i] && ver[i] < up[i]) { return true; } | ||
if (lo[i] > ver[i] || ver[i] > up[i]) { return false; } | ||
} | ||
|
||
return false; | ||
|
||
} | ||
|
||
function splitVersion(version: string): number[] { | ||
return `${version}`.split('.') | ||
.map(x => parseInt(x, 10)) | ||
.map(x => isNaN(x) ? 0 : x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { isVersionBetween } from '../lib/platform-warnings'; | ||
|
||
|
||
test.each([ | ||
['2.1', false], | ||
['2.2', true], | ||
['2', false], | ||
['3', true], | ||
['4', false], | ||
['4.3', true], | ||
['4.3', true], | ||
['4.2.294-220.533.amzn2.x86_64', true], | ||
])('%p is in range: %p', (version, expected) => { | ||
expect(isVersionBetween(version, '2.1.0.6', '4.9.2')).toEqual(expected); | ||
}); |