Skip to content

Commit

Permalink
chore: windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed May 24, 2024
1 parent b139d23 commit b4e5489
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 27 deletions.
23 changes: 23 additions & 0 deletions .github/docker/Dockerfile.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2016

# Set the Node.js version you want to install
ENV NODE_VERSION 16.20.1

# Download and install Node.js
RUN powershell -Command `
$ErrorActionPreference = 'Stop'; `
Invoke-WebRequest -Uri https://nodejs.org/dist/v$env:NODE_VERSION/node-v$env:NODE_VERSION-win-x64.zip -OutFile node.zip; `
Expand-Archive -Path node.zip -DestinationPath C:\; `
Rename-Item -Path C:\node-v$env:NODE_VERSION-win-x64 -NewName C:\nodejs; `
Remove-Item -Force node.zip

# Add Node.js to PATH
ENV PATH="C:\nodejs;C:\nodejs\node_modules\npm\bin;${PATH}"

WORKDIR "C:\mongodb-client-encryption"
COPY . .

RUN node "C:\mongodb-client-encryption\.github\scripts\libmongocrypt.mjs"

CMD ["ping", "-i", "20", "localhost"]
13 changes: 10 additions & 3 deletions .github/scripts/build_linux.mjs → .github/scripts/buildx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function resolveRoot(...paths) {

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

const platform =
process.platform === 'win32' ? 'windows/amd64' : 'linux/s390x,linux/arm64,linux/amd64';
const dockerFile =
process.platform === 'win32'
? resolveRoot('./.github/docker/Dockerfile.win')
: resolveRoot('./.github/docker/Dockerfile.glibc');

await run('docker', [
'buildx',
'build',
// '--progress=plain', // By default buildx detects tty and does some fancy collapsing, set progress=plain for debugging
'--platform',
'linux/s390x,linux/arm64,linux/amd64',
platform,
'--output',
'type=local,dest=./prebuilds,platform-split=false',
'-f',
resolveRoot('./.github/docker/Dockerfile.glibc'),
dockerFile,
resolveRoot('.')
]);

Expand Down
5 changes: 4 additions & 1 deletion .github/scripts/libmongocrypt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ export async function downloadLibMongoCrypt(nodeDepsRoot, { ref }) {

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

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

Expand Down
50 changes: 27 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,50 @@ on:
name: build

jobs:
builds:
macos_windows_builds:
outputs:
artifact_id: ${{ steps.upload.outputs.artifact-id }}
strategy:
matrix:
os: [ubuntu-latest, windows-2019, macos-11, macos-latest]
os: [macos-11, macos-latest, windows-2019]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- if: ${{ runner.os == 'Linux' }}
name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Build ${{ matrix.os }} Prebuild
run: node .github/scripts/libmongocrypt.mjs ${{ runner.os == 'Windows' && '--build' || '' }}
shell: bash

- if: ${{ runner.os == 'Linux' }}
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- id: upload
name: Upload prebuild
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.os }}
path: prebuilds/
if-no-files-found: 'error'
retention-days: 1

- if: ${{ runner.os == 'Linux' }}
name: Build ${{ runner.os }} Prebuild
run: node .github/scripts/build_linux.mjs
linux_builds:
outputs:
artifact_id: ${{ steps.upload.outputs.artifact-id }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- if: ${{ runner.os != 'Linux' }}
name: Setup nodejs
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- if: ${{ runner.os != 'Linux' }}
name: Build ${{ runner.os }} Prebuild
run: node .github/scripts/libmongocrypt.mjs
shell: bash
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Run Buildx
run: node .github/scripts/buildx.mjs

- id: upload
name: Upload prebuild
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.os }}
name: build-linux
path: prebuilds/
if-no-files-found: 'error'
retention-days: 1

0 comments on commit b4e5489

Please sign in to comment.