Skip to content

Commit

Permalink
download node from our proxy-cache (#49081)
Browse files Browse the repository at this point in the history
* download node from our proxy-cache

* download node with axios to support redirects

* fix test assertion now that we're using axios
  • Loading branch information
Spencer authored Oct 23, 2019
1 parent c718972 commit b54c1a1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/dev/build/tasks/nodejs/__tests__/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('src/dev/build/tasks/nodejs/download', () => {
} catch (error) {
expect(error)
.to.have.property('message')
.contain('Unexpected status code 500');
.contain('Request failed with status code 500');
expect(reqCount).to.be(6);
}
});
Expand Down
17 changes: 10 additions & 7 deletions src/dev/build/tasks/nodejs/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { dirname } from 'path';

import chalk from 'chalk';
import { createHash } from 'crypto';
import wreck from '@hapi/wreck';
import Axios from 'axios';

import { mkdirp } from '../../lib';

Expand Down Expand Up @@ -51,21 +51,24 @@ export async function download(options) {
try {
log.debug(`Attempting download of ${url}`, chalk.dim(sha256));

const response = await wreck.request('GET', url);
const response = await Axios.request({
url: url,
responseType: 'stream'
});

if (response.statusCode !== 200) {
throw new Error(`Unexpected status code ${response.statusCode} when downloading ${url}`);
if (response.status !== 200) {
throw new Error(`Unexpected status code ${response.status} when downloading ${url}`);
}

const hash = createHash('sha256');
await new Promise((resolve, reject) => {
response.on('data', chunk => {
response.data.on('data', chunk => {
hash.update(chunk);
writeSync(fileHandle, chunk);
});

response.on('error', reject);
response.on('end', resolve);
response.data.on('error', reject);
response.data.on('end', resolve);
});

const downloadedSha256 = hash.digest('hex');
Expand Down
2 changes: 1 addition & 1 deletion src/dev/build/tasks/nodejs/node_download_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getNodeDownloadInfo(config, platform) {
? 'win-x64/node.exe'
: `node-v${version}-${arch}.tar.gz`;

const url = `https://nodejs.org/dist/v${version}/${downloadName}`;
const url = `https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/dist/v${version}/${downloadName}`;
const downloadPath = config.resolveFromRepo('.node_binaries', version, basename(downloadName));
const extractDir = config.resolveFromRepo('.node_binaries', version, arch);

Expand Down
4 changes: 3 additions & 1 deletion src/dev/build/tasks/nodejs/node_shasums.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ c4edece2c0aa68e816c4e067f397eb12e9d0c81bb37b3d349dbaf47cf246b0b7 win-x86/node.l

jest.mock('axios', () => ({
async get(url: string) {
expect(url).toBe('https://nodejs.org/dist/v8.9.4/SHASUMS256.txt');
expect(url).toBe(
'https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/dist/v8.9.4/SHASUMS256.txt'
);
return {
status: 200,
data: mockResponse,
Expand Down
2 changes: 1 addition & 1 deletion src/dev/build/tasks/nodejs/node_shasums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import axios from 'axios';

export async function getNodeShasums(nodeVersion: string) {
const url = `https://nodejs.org/dist/v${nodeVersion}/SHASUMS256.txt`;
const url = `https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/dist/v${nodeVersion}/SHASUMS256.txt`;

const { status, data } = await axios.get(url);

Expand Down
4 changes: 2 additions & 2 deletions src/dev/ci_setup/setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ nodeDir="$cacheDir/node/$nodeVersion"

if [[ "$OS" == "win" ]]; then
nodeBin="$HOME/node"
nodeUrl="https://nodejs.org/dist/v$nodeVersion/node-v$nodeVersion-win-x64.zip"
nodeUrl="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/dist/v$nodeVersion/node-v$nodeVersion-win-x64.zip"
else
nodeBin="$nodeDir/bin"
nodeUrl="https://nodejs.org/dist/v$nodeVersion/node-v$nodeVersion-linux-x64.tar.gz"
nodeUrl="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/dist/v$nodeVersion/node-v$nodeVersion-linux-x64.tar.gz"
fi

if [[ "$installNode" == "true" ]]; then
Expand Down

0 comments on commit b54c1a1

Please sign in to comment.