Skip to content

Commit 09ccdd3

Browse files
authored
chore(NODE-6176): add prebuilds in CI (#7)
1 parent edc5f26 commit 09ccdd3

File tree

3 files changed

+81
-15
lines changed

3 files changed

+81
-15
lines changed

.github/docker/Dockerfile.glibc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 /mongodb-client-encryption/.github/scripts/libmongocrypt.mjs
8+
9+
FROM scratch
10+
11+
COPY --from=build /mongodb-client-encryption/prebuilds/ /

.github/scripts/libmongocrypt.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ async function run(command, args = [], options = {}) {
5959
const commandDetails = `+ ${command} ${args.join(' ')}${options.cwd ? ` (in: ${options.cwd})` : ''}`;
6060
console.error(commandDetails);
6161
const proc = child_process.spawn(command, args, {
62+
shell: process.platform === 'win32',
6263
stdio: 'inherit',
6364
cwd: resolveRoot('.'),
6465
...options
@@ -171,9 +172,12 @@ export async function downloadLibMongoCrypt(nodeDepsRoot, { ref }) {
171172

172173
console.error(`Platform: ${detectedPlatform} Prebuild: ${prebuild}`);
173174

174-
const unzipArgs = ['-xzv', '-C', destination, `${prebuild}/nocrypto`];
175+
const unzipArgs = ['-xzv', '-C', `_libmongocrypt-${ref}`, `${prebuild}/nocrypto`];
175176
console.error(`+ tar ${unzipArgs.join(' ')}`);
176-
const unzip = child_process.spawn('tar', unzipArgs, { stdio: ['pipe', 'inherit'] });
177+
const unzip = child_process.spawn('tar', unzipArgs, {
178+
stdio: ['pipe', 'inherit'],
179+
cwd: resolveRoot('.')
180+
});
177181

178182
const [response] = await events.once(https.get(downloadURL), 'response');
179183

@@ -228,7 +232,7 @@ async function main() {
228232
// install with "ignore-scripts" so that we don't attempt to download a prebuild
229233
await run('npm', ['install', '--ignore-scripts']);
230234
// The prebuild command will make both a .node file in `./build` (local and CI testing will run on current code)
231-
// it will also produce `./prebuild/xx.tgz`. prebuild has GH upload functionality.
235+
// it will also produce `./prebuilds/mongodb-client-encryption-vVERSION-napi-vNAPI_VERSION-OS-ARCH.tar.gz`.
232236
await run('npm', ['run', 'prebuild']);
233237
}
234238

.github/workflows/build.yml

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,74 @@ on:
88
name: build
99

1010
jobs:
11-
build:
11+
host_builds:
12+
strategy:
13+
matrix:
14+
os: [macos-11, macos-latest, windows-2019]
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Build ${{ matrix.os }} Prebuild
20+
run: node .github/scripts/libmongocrypt.mjs ${{ runner.os == 'Windows' && '--build' || '' }}
21+
shell: bash
22+
23+
- id: upload
24+
name: Upload prebuild
25+
uses: actions/upload-artifact@v4
26+
with:
27+
name: build-${{ matrix.os }}
28+
path: prebuilds/
29+
if-no-files-found: 'error'
30+
retention-days: 1
31+
compression-level: 0
32+
33+
container_builds:
34+
outputs:
35+
artifact_id: ${{ steps.upload.outputs.artifact-id }}
1236
runs-on: ubuntu-latest
1337
strategy:
14-
matrix:
15-
node: ['20.x'] # '16.x', '18.x',
16-
name: Node.js ${{ matrix.node }} build
38+
matrix:
39+
linux_arch: [s390x, arm64, amd64]
1740
steps:
1841
- uses: actions/checkout@v4
1942

20-
- uses: actions/setup-node@v4
43+
- name: Set up QEMU
44+
uses: docker/setup-qemu-action@v3
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Run Buildx
50+
run: |
51+
docker buildx create --name builder --bootstrap --use
52+
docker buildx build --platform linux/${{ matrix.linux_arch }} --output type=local,dest=./prebuilds,platform-split=false -f ./.github/docker/Dockerfile.glibc .
53+
54+
- id: upload
55+
name: Upload prebuild
56+
uses: actions/upload-artifact@v4
2157
with:
22-
node-version: ${{ matrix.node }}
23-
cache: 'npm'
24-
registry-url: 'https://registry.npmjs.org'
58+
name: build-linux-${{ matrix.linux_arch }}
59+
path: prebuilds/
60+
if-no-files-found: 'error'
61+
retention-days: 1
62+
compression-level: 0
2563

26-
- run: npm install -g npm@latest
27-
shell: bash
64+
collect:
65+
needs: [host_builds, container_builds]
66+
runs-on: ubunutu-latest
67+
steps:
68+
- uses: actions/download-artifact@v4
2869

29-
- run: node .github/scripts/libmongocrypt.mjs
30-
shell: bash
70+
- name: Display structure of downloaded files
71+
run: ls -R
72+
73+
- id: upload
74+
name: Upload all prebuilds
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: all-build
78+
path: '*.tar.gz'
79+
if-no-files-found: 'error'
80+
retention-days: 1
81+
compression-level: 0

0 commit comments

Comments
 (0)