-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathupdateAWSEnvironment.ts
72 lines (55 loc) · 1.98 KB
/
updateAWSEnvironment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Update the list of libraries included in the AWS Lambda environment
import { spawnSync } from 'child_process';
import { writeFileSync } from 'fs-extra';
import * as path from 'path';
import * as config from './config';
import * as ld from './ld';
import * as version from './version';
const EXPORT_FILE_NAME = path.resolve(__dirname, 'AWSEnvironment.ts');
function commandOutput(cmd: string, args: string[]): string {
const result = spawnSync(
'docker',
[
'run',
'--rm',
'--entrypoint', cmd,
config.DOCKER_IMAGE,
...args,
]
);
if (result.error || result.status && result.status > 0) {
const stderr = result.stderr.toString().trim();
throw new Error(`Error calling ${cmd} in the AWS image: ${stderr}`);
}
return result.stdout.toString().trim();
}
function getLibraries(): string[] {
const lddOutput = commandOutput('/usr/sbin/ldconfig', [
'-c', 'new',
'-p'
]);
const libraries = Object.keys(ld.parseLdOutput(lddOutput));
return libraries;
}
function getGlibcVersion(): version.Version {
const lddOutput = commandOutput('/usr/bin/ldd', ['--version']);
const glibcVersionMatch = lddOutput.match(/((\d+.)+\d+)/);
if (!glibcVersionMatch) {
throw new Error(`Unexpected output from ldd: ${lddOutput}`);
}
const glibcVersion = version.parse(glibcVersionMatch[0]);
return glibcVersion;
}
function main(): void {
spawnSync('docker', ['pull', config.DOCKER_IMAGE]);
let content = "// This file is autogenerated.\n" +
"// Please use 'npm run updateAWSEnvironment' to update.\n";
function addExport(name: string, value: unknown): string {
return "export const " + name + " = " +
JSON.stringify(value, null, 4) + ";\n";
}
content += addExport("libraries", getLibraries());
content += addExport("glibcVersion", getGlibcVersion());
writeFileSync(EXPORT_FILE_NAME, content);
}
main();