Skip to content

Commit 8d521b8

Browse files
committed
chore(NODE-6176): add prebuilds in CI
1 parent edc5f26 commit 8d521b8

File tree

3 files changed

+99
-10
lines changed

3 files changed

+99
-10
lines changed

.github/docker/Dockerfile.glibc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ARG NODE_BUILD_IMAGE=node:16.20.1-bullseye
2+
FROM $NODE_BUILD_IMAGE AS build
3+
4+
WORKDIR /mongodb-client-encryption
5+
COPY . .
6+
7+
RUN node ./.github/scripts/libmongocrypt.mjs
8+
RUN mkdir -p /out && cp -R /mongodb-client-encryption/prebuilds/ /out
9+
10+
FROM scratch
11+
12+
COPY --from=build /out /

.github/scripts/build_linux.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import child_process from 'node:child_process';
2+
import events from 'node:events';
3+
import fs from 'node:fs/promises';
4+
import path from 'node:path';
5+
import url from 'node:url';
6+
7+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
8+
9+
/** Resolves to the root of this repository */
10+
function resolveRoot(...paths) {
11+
return path.resolve(__dirname, '..', '..', ...paths);
12+
}
13+
14+
/** `xtrace` style command runner, uses spawn so that stdio is inherited */
15+
async function run(command, args = [], options = {}) {
16+
const commandDetails = `+ ${command} ${args.join(' ')}${options.cwd ? ` (in: ${options.cwd})` : ''}`
17+
console.error(commandDetails);
18+
const proc = child_process.spawn(command, args, {
19+
stdio: 'inherit',
20+
cwd: resolveRoot('.'),
21+
...options
22+
});
23+
await events.once(proc, 'exit');
24+
25+
if (proc.exitCode != 0) throw new Error(`CRASH(${proc.exitCode}): ${commandDetails}`);
26+
}
27+
28+
async function main() {
29+
await fs.rm(resolveRoot('build'), { recursive: true, force: true });
30+
await fs.rm(resolveRoot('prebuilds'), { recursive: true, force: true });
31+
32+
try {
33+
// Locally you probably already have this
34+
await run('docker', ['buildx', 'use', 'builder']);
35+
} catch {
36+
// But if not, create one
37+
await run('docker', ['buildx', 'create', '--name', 'builder', '--bootstrap', '--use']);
38+
}
39+
40+
await run('docker', [
41+
'buildx',
42+
'build',
43+
// '--progress=plain', // By default buildx detects tty and does some fancy collapsing, set progress=plain for debugging
44+
'--platform',
45+
'linux/s390x,linux/arm64,linux/amd64',
46+
'--output',
47+
'type=local,dest=.,platform-split=false',
48+
'-f',
49+
resolveRoot('./.github/docker/Dockerfile.glibc'),
50+
resolveRoot('.')
51+
]);
52+
}
53+
54+
await main();

.github/workflows/build.yml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,46 @@ on:
88
name: build
99

1010
jobs:
11-
build:
12-
runs-on: ubuntu-latest
11+
builds:
12+
outputs:
13+
artifact_id: ${{ steps.upload.outputs.artifact-id }}
1314
strategy:
14-
matrix:
15-
node: ['20.x'] # '16.x', '18.x',
16-
name: Node.js ${{ matrix.node }} build
15+
matrix:
16+
os: [ubuntu-latest, windows-2019, macos-11, macos-latest]
17+
runs-on: ${{ matrix.os }}
1718
steps:
1819
- uses: actions/checkout@v4
1920

20-
- uses: actions/setup-node@v4
21+
- if: ${{ runner.os == 'Linux' }}
22+
name: Set up QEMU
23+
uses: docker/setup-qemu-action@v3
24+
25+
- if: ${{ runner.os == 'Linux' }}
26+
name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- if: ${{ runner.os == 'Linux' }}
30+
name: Build ${{ runner.os }} Prebuild
31+
run: node .github/scripts/build_linux.mjs
32+
33+
- if: ${{ runner.os != 'Linux' }}
34+
name: Setup nodejs
35+
uses: actions/setup-node@v3
2136
with:
22-
node-version: ${{ matrix.node }}
37+
node-version: 'lts/*'
2338
cache: 'npm'
2439
registry-url: 'https://registry.npmjs.org'
2540

26-
- run: npm install -g npm@latest
41+
- if: ${{ runner.os != 'Linux' }}
42+
name: Build ${{ runner.os }} Prebuild
43+
run: node .github/scripts/libmongocrypt.mjs
2744
shell: bash
2845

29-
- run: node .github/scripts/libmongocrypt.mjs
30-
shell: bash
46+
- id: upload
47+
name: Upload prebuild
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: build-${{ matrix.os }}
51+
path: prebuilds/
52+
if-no-files-found: 'error'
53+
retention-days: 1

0 commit comments

Comments
 (0)