Skip to content

Commit d15b27d

Browse files
committed
chore: windows
1 parent b139d23 commit d15b27d

File tree

4 files changed

+93
-24
lines changed

4 files changed

+93
-24
lines changed

.github/docker/Dockerfile.win

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#escape=`
2+
FROM mcr.microsoft.com/windows/servercore:ltsc2016
3+
4+
# Set the Node.js version you want to install
5+
ENV NODE_VERSION 16.20.1
6+
7+
# Download and install Node.js
8+
RUN powershell -Command `
9+
$ErrorActionPreference = 'Stop'; `
10+
Invoke-WebRequest -Uri https://nodejs.org/dist/v$env:NODE_VERSION/node-v$env:NODE_VERSION-win-x64.zip -OutFile node.zip; `
11+
Expand-Archive -Path node.zip -DestinationPath C:\; `
12+
Rename-Item -Path C:\node-v$env:NODE_VERSION-win-x64 -NewName C:\nodejs; `
13+
Remove-Item -Force node.zip
14+
15+
# Add Node.js to PATH
16+
ENV PATH="C:\nodejs;C:\nodejs\node_modules\npm\bin;${PATH}"
17+
18+
WORKDIR "C:\mongodb-client-encryption"
19+
COPY . .
20+
21+
RUN node "C:\mongodb-client-encryption\.github\scripts\libmongocrypt.mjs"
22+
23+
CMD ["ping", "-i", "20", "localhost"]

.github/scripts/build_linux.mjs renamed to .github/scripts/buildx.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function resolveRoot(...paths) {
1313

1414
/** `xtrace` style command runner, uses spawn so that stdio is inherited */
1515
async function run(command, args = [], options = {}) {
16-
const commandDetails = `+ ${command} ${args.join(' ')}${options.cwd ? ` (in: ${options.cwd})` : ''}`
16+
const commandDetails = `+ ${command} ${args.join(' ')}${options.cwd ? ` (in: ${options.cwd})` : ''}`;
1717
console.error(commandDetails);
1818
const proc = child_process.spawn(command, args, {
1919
stdio: 'inherit',
@@ -37,16 +37,23 @@ async function main() {
3737
await run('docker', ['buildx', 'create', '--name', 'builder', '--bootstrap', '--use']);
3838
}
3939

40+
const platform =
41+
process.platform === 'win32' ? 'windows/amd64' : 'linux/s390x,linux/arm64,linux/amd64';
42+
const dockerFile =
43+
process.platform === 'win32'
44+
? resolveRoot('./.github/docker/Dockerfile.win')
45+
: resolveRoot('./.github/docker/Dockerfile.glibc');
46+
4047
await run('docker', [
4148
'buildx',
4249
'build',
4350
// '--progress=plain', // By default buildx detects tty and does some fancy collapsing, set progress=plain for debugging
4451
'--platform',
45-
'linux/s390x,linux/arm64,linux/amd64',
52+
platform,
4653
'--output',
4754
'type=local,dest=./prebuilds,platform-split=false',
4855
'-f',
49-
resolveRoot('./.github/docker/Dockerfile.glibc'),
56+
dockerFile,
5057
resolveRoot('.')
5158
]);
5259

.github/scripts/libmongocrypt.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ export async function downloadLibMongoCrypt(nodeDepsRoot, { ref }) {
174174

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

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

@@ -230,7 +233,15 @@ async function main() {
230233
await run('npm', ['install', '--ignore-scripts']);
231234
// The prebuild command will make both a .node file in `./build` (local and CI testing will run on current code)
232235
// it will also produce `./prebuild/xx.tgz`. prebuild has GH upload functionality.
236+
if (process.platform === 'win32') {
237+
await fs.writeFile(resolveRoot('.npmrc'), 'msvs_version=2017\n', 'utf8');
238+
}
239+
233240
await run('npm', ['run', 'prebuild']);
241+
242+
if (process.platform === 'win32') {
243+
await fs.rm(resolveRoot('.npmrc'), { force: true });
244+
}
234245
}
235246

236247
await main();

.github/workflows/build.yml

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,74 @@ on:
88
name: build
99

1010
jobs:
11-
builds:
11+
macos_builds:
1212
outputs:
1313
artifact_id: ${{ steps.upload.outputs.artifact-id }}
1414
strategy:
1515
matrix:
16-
os: [ubuntu-latest, windows-2019, macos-11, macos-latest]
16+
os: [macos-11, macos-latest]
1717
runs-on: ${{ matrix.os }}
1818
steps:
1919
- uses: actions/checkout@v4
2020

21-
- if: ${{ runner.os == 'Linux' }}
22-
name: Set up QEMU
21+
- name: Build ${{ matrix.os }} Prebuild
22+
run: node .github/scripts/libmongocrypt.mjs
23+
shell: bash
24+
25+
- id: upload
26+
name: Upload prebuild
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: build-${{ matrix.os }}
30+
path: prebuilds/
31+
if-no-files-found: 'error'
32+
retention-days: 1
33+
34+
linux_builds:
35+
outputs:
36+
artifact_id: ${{ steps.upload.outputs.artifact-id }}
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Set up QEMU
2342
uses: docker/setup-qemu-action@v3
2443

25-
- if: ${{ runner.os == 'Linux' }}
26-
name: Set up Docker Buildx
44+
- name: Set up Docker Buildx
2745
uses: docker/setup-buildx-action@v3
2846

29-
- if: ${{ runner.os == 'Linux' }}
30-
name: Build ${{ runner.os }} Prebuild
31-
run: node .github/scripts/build_linux.mjs
47+
- name: Run Buildx
48+
run: node .github/scripts/buildx.mjs
3249

33-
- if: ${{ runner.os != 'Linux' }}
34-
name: Setup nodejs
35-
uses: actions/setup-node@v4
50+
- id: upload
51+
name: Upload prebuild
52+
uses: actions/upload-artifact@v4
3653
with:
37-
node-version: 'lts/*'
38-
cache: 'npm'
39-
registry-url: 'https://registry.npmjs.org'
54+
name: build-linux
55+
path: prebuilds/
56+
if-no-files-found: 'error'
57+
retention-days: 1
4058

41-
- if: ${{ runner.os != 'Linux' }}
42-
name: Build ${{ runner.os }} Prebuild
43-
run: node .github/scripts/libmongocrypt.mjs
44-
shell: bash
59+
windows_builds:
60+
runs-on: windows-latest
61+
outputs:
62+
artifact_id: ${{ steps.upload.outputs.artifact-id }}
63+
steps:
64+
- uses: actions/checkout@v4
65+
66+
- name: Build Docker image
67+
run: |
68+
docker build -f .github/docker/Dockerfile.win --tag m:latest .
69+
docker run -d --name m m:latest
70+
docker cp m:C:\\mongodb-client-encryption\\prebuilds prebuilds
71+
docker stop m
72+
docker rm m:latest
4573
4674
- id: upload
4775
name: Upload prebuild
4876
uses: actions/upload-artifact@v4
4977
with:
50-
name: build-${{ matrix.os }}
78+
name: build-windows
5179
path: prebuilds/
5280
if-no-files-found: 'error'
5381
retention-days: 1

0 commit comments

Comments
 (0)