Skip to content

Commit 55486f5

Browse files
committed
Bundle Node 14 as a fallback for operating systems that cannot run Node 18
Signed-off-by: ananzh <ananzh@amazon.com> Signed-off-by: Miki <miki@amazon.com>
1 parent 1c0ffee commit 55486f5

8 files changed

+178
-13
lines changed

scripts/use_node

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ else
6262
# A bin folder at the root is only present in release builds that have a bundled Node.js binary
6363
if [ -x "OSD_HOME/bin" ]; then
6464
NODE_ERROR_SHOW=true
65+
66+
# Not all operating systems can run the latest Node.js and the fallback is for them
67+
if ("${NODE}" -v 2> /dev/null); then
68+
NODE="$OSD_HOME/node/fallback/bin/node"
69+
NODE_ERROR_MSG="fallback bundled with OpenSearch Dashboards"
70+
fi
6571
fi
6672
fi
6773

src/dev/build/lib/download.ts

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export async function download(options: DownloadOptions): Promise<void> {
7878
url,
7979
responseType: 'stream',
8080
adapter: AxiosHttpAdapter,
81+
timeout: 5000,
8182
});
8283

8384
if (response.status !== 200) {

src/dev/build/tasks/create_archives_sources_task.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030

3131
import { scanCopy, Task } from '../lib';
32-
import { getNodeDownloadInfo } from './nodejs';
32+
import { getNodeDownloadInfo, getNodeVersionDownloadInfo, NODE14_FALLBACK_VERSION } from './nodejs';
3333

3434
export const CreateArchivesSources: Task = {
3535
description: 'Creating platform-specific archive source directories',
@@ -54,6 +54,20 @@ export const CreateArchivesSources: Task = {
5454
destination: build.resolvePathForPlatform(platform, 'node'),
5555
});
5656

57+
// ToDo [NODE14]: Remove this Node.js 14 fallback download
58+
// Copy the Node.js 14 binaries into node/fallback to be used by `use_node`
59+
await scanCopy({
60+
source: (
61+
await getNodeVersionDownloadInfo(
62+
NODE14_FALLBACK_VERSION,
63+
platform.getNodeArch(),
64+
platform.isWindows(),
65+
config.resolveFromRepo()
66+
)
67+
).extractDir,
68+
destination: build.resolvePathForPlatform(platform, 'node', 'fallback'),
69+
});
70+
5771
log.debug('Node.js copied into', platform.getNodeArch(), 'specific build directory');
5872
})
5973
);

src/dev/build/tasks/nodejs/download_node_builds_task.test.ts

+49-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ jest.mock('../../lib/get_build_number');
4444

4545
expect.addSnapshotSerializer(createAnyInstanceSerializer(ToolingLog));
4646

47-
const { getNodeDownloadInfo } = jest.requireMock('./node_download_info');
47+
const { getNodeDownloadInfo, getNodeVersionDownloadInfo } = jest.requireMock(
48+
'./node_download_info'
49+
);
4850
const { getNodeShasums } = jest.requireMock('./node_shasums');
4951
const { download } = jest.requireMock('../../lib/download');
5052

@@ -76,6 +78,16 @@ async function setup({ failOnUrl }: { failOnUrl?: string } = {}) {
7678
};
7779
});
7880

81+
getNodeVersionDownloadInfo.mockImplementation((version, architecture, isWindows, repoRoot) => {
82+
return {
83+
url: `https://mirrors.nodejs.org/dist/v${version}/node-v${version}-${architecture}.tar.gz`,
84+
downloadName: `node-v${version}-${architecture}.tar.gz`,
85+
downloadPath: `/mocked/path/.node_binaries/${version}/node-v${version}-${architecture}.tar.gz`,
86+
extractDir: `/mocked/path/.node_binaries/${version}/${architecture}`,
87+
version,
88+
};
89+
});
90+
7991
getNodeShasums.mockReturnValue({
8092
'linux:downloadName': 'linux:sha256',
8193
'darwin:downloadName': 'darwin:sha256',
@@ -134,6 +146,42 @@ it('downloads node builds for each platform', async () => {
134146
"url": "win32:url",
135147
},
136148
],
149+
Array [
150+
Object {
151+
"destination": "/mocked/path/.node_binaries/14.21.3/node-v14.21.3-linux-x64.tar.gz",
152+
"log": <ToolingLog>,
153+
"retries": 3,
154+
"sha256": undefined,
155+
"url": "https://mirrors.nodejs.org/dist/v14.21.3/node-v14.21.3-linux-x64.tar.gz",
156+
},
157+
],
158+
Array [
159+
Object {
160+
"destination": "/mocked/path/.node_binaries/14.21.3/node-v14.21.3-linux-arm64.tar.gz",
161+
"log": <ToolingLog>,
162+
"retries": 3,
163+
"sha256": undefined,
164+
"url": "https://mirrors.nodejs.org/dist/v14.21.3/node-v14.21.3-linux-arm64.tar.gz",
165+
},
166+
],
167+
Array [
168+
Object {
169+
"destination": "/mocked/path/.node_binaries/14.21.3/node-v14.21.3-darwin-x64.tar.gz",
170+
"log": <ToolingLog>,
171+
"retries": 3,
172+
"sha256": undefined,
173+
"url": "https://mirrors.nodejs.org/dist/v14.21.3/node-v14.21.3-darwin-x64.tar.gz",
174+
},
175+
],
176+
Array [
177+
Object {
178+
"destination": "/mocked/path/.node_binaries/14.21.3/node-v14.21.3-win32-x64.tar.gz",
179+
"log": <ToolingLog>,
180+
"retries": 3,
181+
"sha256": undefined,
182+
"url": "https://mirrors.nodejs.org/dist/v14.21.3/node-v14.21.3-win32-x64.tar.gz",
183+
},
184+
],
137185
]
138186
`);
139187
expect(testWriter.messages).toMatchInlineSnapshot(`Array []`);

src/dev/build/tasks/nodejs/download_node_builds_task.ts

+30-5
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,25 @@
3030

3131
import { download, GlobalTask } from '../../lib';
3232
import { getNodeShasums } from './node_shasums';
33-
import { getNodeDownloadInfo, getRequiredVersion } from './node_download_info';
33+
import {
34+
getNodeDownloadInfo,
35+
getNodeVersionDownloadInfo,
36+
getRequiredVersion,
37+
NODE14_FALLBACK_VERSION,
38+
} from './node_download_info';
3439

3540
export const DownloadNodeBuilds: GlobalTask = {
3641
global: true,
3742
description: 'Downloading node.js builds for all platforms',
3843
async run(config, log) {
3944
const requiredNodeVersion = getRequiredVersion(config);
4045
const shasums = await getNodeShasums(log, requiredNodeVersion);
41-
await Promise.all(
42-
config.getTargetPlatforms().map(async (platform) => {
46+
47+
// ToDo [NODE14]: Remove this Node.js 14 fallback download
48+
const node14ShaSums = await getNodeShasums(log, NODE14_FALLBACK_VERSION);
49+
50+
await Promise.all([
51+
...config.getTargetPlatforms().map(async (platform) => {
4352
const { url, downloadPath, downloadName } = await getNodeDownloadInfo(config, platform);
4453
await download({
4554
log,
@@ -48,7 +57,23 @@ export const DownloadNodeBuilds: GlobalTask = {
4857
destination: downloadPath,
4958
retries: 3,
5059
});
51-
})
52-
);
60+
}),
61+
// ToDo [NODE14]: Remove this Node.js 14 fallback download
62+
...config.getTargetPlatforms().map(async (platform) => {
63+
const { url, downloadPath, downloadName } = await getNodeVersionDownloadInfo(
64+
NODE14_FALLBACK_VERSION,
65+
platform.getNodeArch(),
66+
platform.isWindows(),
67+
config.resolveFromRepo()
68+
);
69+
await download({
70+
log,
71+
url,
72+
sha256: node14ShaSums[downloadName],
73+
destination: downloadPath,
74+
retries: 3,
75+
});
76+
}),
77+
]);
5378
},
5479
};

src/dev/build/tasks/nodejs/extract_node_builds_task.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,27 @@ it('runs expected fs operations', async () => {
123123
"strip": 1,
124124
},
125125
],
126+
Array [
127+
<absolute path>/.node_binaries/14.21.3/node-v14.21.3-linux-x64.tar.gz,
128+
<absolute path>/.node_binaries/14.21.3/linux-x64,
129+
Object {
130+
"strip": 1,
131+
},
132+
],
133+
Array [
134+
<absolute path>/.node_binaries/14.21.3/node-v14.21.3-linux-arm64.tar.gz,
135+
<absolute path>/.node_binaries/14.21.3/linux-arm64,
136+
Object {
137+
"strip": 1,
138+
},
139+
],
140+
Array [
141+
<absolute path>/.node_binaries/14.21.3/node-v14.21.3-darwin-x64.tar.gz,
142+
<absolute path>/.node_binaries/14.21.3/darwin-x64,
143+
Object {
144+
"strip": 1,
145+
},
146+
],
126147
],
127148
"unzip": Array [
128149
Array [
@@ -132,6 +153,13 @@ it('runs expected fs operations', async () => {
132153
"strip": 1,
133154
},
134155
],
156+
Array [
157+
<absolute path>/.node_binaries/14.21.3/node-v14.21.3-win-x64.zip,
158+
<absolute path>/.node_binaries/14.21.3/win32-x64,
159+
Object {
160+
"strip": 1,
161+
},
162+
],
135163
],
136164
}
137165
`);

src/dev/build/tasks/nodejs/extract_node_builds_task.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,39 @@
2929
*/
3030

3131
import { untar, unzip, GlobalTask } from '../../lib';
32-
import { getNodeDownloadInfo } from './node_download_info';
32+
import {
33+
getNodeDownloadInfo,
34+
getNodeVersionDownloadInfo,
35+
NODE14_FALLBACK_VERSION,
36+
} from './node_download_info';
3337

3438
export const ExtractNodeBuilds: GlobalTask = {
3539
global: true,
3640
description: 'Extracting node.js builds for all platforms',
3741
async run(config) {
38-
await Promise.all(
39-
config.getTargetPlatforms().map(async (platform) => {
42+
await Promise.all([
43+
...config.getTargetPlatforms().map(async (platform) => {
4044
const { downloadPath, extractDir } = await getNodeDownloadInfo(config, platform);
4145
if (platform.isWindows()) {
4246
await unzip(downloadPath, extractDir, { strip: 1 });
4347
} else {
4448
await untar(downloadPath, extractDir, { strip: 1 });
4549
}
46-
})
47-
);
50+
}),
51+
// ToDo [NODE14]: Remove this Node.js 14 fallback download
52+
...config.getTargetPlatforms().map(async (platform) => {
53+
const { downloadPath, extractDir } = await getNodeVersionDownloadInfo(
54+
NODE14_FALLBACK_VERSION,
55+
platform.getNodeArch(),
56+
platform.isWindows(),
57+
config.resolveFromRepo()
58+
);
59+
if (platform.isWindows()) {
60+
await unzip(downloadPath, extractDir, { strip: 1 });
61+
} else {
62+
await untar(downloadPath, extractDir, { strip: 1 });
63+
}
64+
}),
65+
]);
4866
},
4967
};

src/dev/build/tasks/nodejs/node_download_info.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
* under the License.
2929
*/
3030

31-
import { basename } from 'path';
31+
import { basename, resolve } from 'path';
3232
import fetch from 'node-fetch';
3333
import semver from 'semver';
3434

3535
import { Config, Platform } from '../../lib';
3636

3737
const NODE_RANGE_CACHE: { [key: string]: string } = {};
3838

39+
export const NODE14_FALLBACK_VERSION = '14.21.3';
40+
3941
export async function getNodeDownloadInfo(config: Config, platform: Platform) {
4042
const version = getRequiredVersion(config);
4143
const arch = platform.getNodeArch();
@@ -57,6 +59,29 @@ export async function getNodeDownloadInfo(config: Config, platform: Platform) {
5759
};
5860
}
5961

62+
export async function getNodeVersionDownloadInfo(
63+
version: string,
64+
architecture: string,
65+
isWindows: boolean,
66+
repoRoot: string
67+
) {
68+
const downloadName = isWindows
69+
? `node-v${version}-win-x64.zip`
70+
: `node-v${version}-${architecture}.tar.gz`;
71+
72+
const url = `https://mirrors.nodejs.org/dist/v${version}/${downloadName}`;
73+
const downloadPath = resolve(repoRoot, '.node_binaries', version, basename(downloadName));
74+
const extractDir = resolve(repoRoot, '.node_binaries', version, architecture);
75+
76+
return {
77+
url,
78+
downloadName,
79+
downloadPath,
80+
extractDir,
81+
version,
82+
};
83+
}
84+
6085
export async function getLatestNodeVersion(config: Config) {
6186
const range = config.getNodeRange();
6287
// Check cache and return if known

0 commit comments

Comments
 (0)