Skip to content

Commit ec32fbe

Browse files
authoredNov 21, 2024
ci(NODE-6570): Test on all supported platforms and Node versions (#33)
1 parent 3145388 commit ec32fbe

12 files changed

+7594
-1403
lines changed
 

‎.github/docker/Dockerfile.glibc

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARG UBUNTU_VERSION=bionic
2+
FROM ubuntu:${UBUNTU_VERSION} AS build
3+
4+
ARG NODE_VERSION=16.20.1
5+
# Possible values: s390x, arm64, x64
6+
ARG NODE_ARCH
7+
ADD https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.gz /
8+
RUN mkdir -p /nodejs && tar -xzf /node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.gz --strip-components=1 -C /nodejs
9+
ENV PATH=$PATH:/nodejs/bin
10+
11+
WORKDIR /zstd
12+
COPY . .
13+
14+
RUN apt-get -qq update
15+
RUN apt-get -qq install -y python3 build-essential curl cmake
16+
RUN python3 --version
17+
18+
RUN npm run install-zstd
19+
RUN npm install
20+
21+
ARG RUN_TEST
22+
RUN if [ -n "$RUN_TEST" ]; then npm test ; else echo "skipping tests" ; fi

‎.github/docker/Dockerfile.musl

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
ARG PLATFORM=arm64
3+
ARG NODE_VERSION=16.20.1
4+
5+
FROM ${PLATFORM}/node:${NODE_VERSION}-alpine AS node
6+
7+
WORKDIR /zstd
8+
COPY . .
9+
10+
RUN apk --no-cache add make g++ libc-dev curl bash python3 py3-pip vim cmake
11+
RUN npm run install-zstd && npm i
12+
13+
ARG RUN_TEST
14+
RUN if [ -n "$RUN_TEST" ]; then npm test ; else echo "skipping tests" ; fi

‎.github/workflows/test.yml

+82-43
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ jobs:
1111
host_tests:
1212
strategy:
1313
matrix:
14-
# os: [macos-latest, windows-2019]
15-
os: ['ubuntu-latest']
16-
node: [16.20.1, 18.x, 20.x, 22.x]
14+
os: [macos-latest, windows-2019]
15+
node: [16.20.1, 18.x, 20.x, 22.x]
16+
fail-fast: false
1717
runs-on: ${{ matrix.os }}
1818
steps:
1919
- uses: actions/checkout@v4
2020

2121
- uses: actions/setup-node@v4
2222
with:
2323
node-version: ${{ matrix.node }}
24-
cache: 'npm'
25-
registry-url: 'https://registry.npmjs.org'
24+
cache: "npm"
25+
registry-url: "https://registry.npmjs.org"
2626

2727
- name: Install zstd
2828
run: npm run install-zstd
@@ -36,41 +36,80 @@ jobs:
3636
shell: bash
3737
run: npm test
3838

39-
# container_tests:
40-
# runs-on: ubuntu-latest
41-
# strategy:
42-
# matrix:
43-
# linux_arch: [s390x, arm64, amd64]
44-
# node: [16.x, 18.x, 20.x, 22.x]
45-
# steps:
46-
# - uses: actions/checkout@v4
47-
48-
# - uses: actions/setup-node@v4
49-
# with:
50-
# node-version: ${{ matrix.node }}
51-
52-
# - name: Get Full Node.js Version
53-
# id: get_nodejs_version
54-
# shell: bash
55-
# run: |
56-
# echo "version=$(node --print 'process.version.slice(1)')" >> "$GITHUB_OUTPUT"
57-
# echo "ubuntu_version=$(node --print '(+process.version.slice(1).split(`.`).at(0)) > 16 ? `noble` : `bionic`')" >> "$GITHUB_OUTPUT"
58-
59-
# - name: Set up QEMU
60-
# uses: docker/setup-qemu-action@v3
61-
62-
# - name: Set up Docker Buildx
63-
# uses: docker/setup-buildx-action@v3
64-
65-
# - name: Run Buildx
66-
# run: |
67-
# docker buildx create --name builder --bootstrap --use
68-
# docker buildx build \
69-
# --platform linux/${{ matrix.linux_arch }} \
70-
# --build-arg="NODE_ARCH=${{ matrix.linux_arch == 'amd64' && 'x64' || matrix.linux_arch }}" \
71-
# --build-arg="NODE_VERSION=${{ steps.get_nodejs_version.outputs.version }}" \
72-
# --build-arg="UBUNTU_VERSION=${{ steps.get_nodejs_version.outputs.ubuntu_version }}" \
73-
# --build-arg="RUN_TEST=true" \
74-
# --output type=local,dest=./prebuilds,platform-split=false \
75-
# -f ./.github/docker/Dockerfile.glibc \
76-
# .
39+
container_tests_glibc:
40+
runs-on: ubuntu-latest
41+
strategy:
42+
matrix:
43+
linux_arch: [s390x, arm64, amd64]
44+
node: [16.x, 18.x, 20.x, 22.x]
45+
fail-fast: false
46+
steps:
47+
- uses: actions/checkout@v4
48+
49+
- uses: actions/setup-node@v4
50+
with:
51+
node-version: ${{ matrix.node }}
52+
53+
- name: Get Full Node.js Version
54+
id: get_nodejs_version
55+
shell: bash
56+
run: |
57+
echo "version=$(node --print 'process.version.slice(1)')" >> "$GITHUB_OUTPUT"
58+
echo "ubuntu_version=$(node --print '(+process.version.slice(1).split(`.`).at(0)) > 16 ? `noble` : `bionic`')" >> "$GITHUB_OUTPUT"
59+
60+
- name: Set up QEMU
61+
uses: docker/setup-qemu-action@v3
62+
63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v3
65+
66+
- name: Run Buildx
67+
run: |
68+
docker buildx create --name builder --bootstrap --use
69+
docker buildx build \
70+
--platform linux/${{ matrix.linux_arch }} \
71+
--build-arg="NODE_ARCH=${{ matrix.linux_arch == 'amd64' && 'x64' || matrix.linux_arch }}" \
72+
--build-arg="NODE_VERSION=${{ steps.get_nodejs_version.outputs.version }}" \
73+
--build-arg="UBUNTU_VERSION=${{ steps.get_nodejs_version.outputs.ubuntu_version }}" \
74+
--build-arg="RUN_TEST=true" \
75+
--output type=local,dest=./prebuilds,platform-split=false \
76+
-f ./.github/docker/Dockerfile.glibc \
77+
.
78+
79+
container_tests_musl:
80+
runs-on: ubuntu-latest
81+
strategy:
82+
matrix:
83+
linux_arch: [amd64, arm64]
84+
node: [16.20.1, 18.x, 20.x, 22.x]
85+
fail-fast: false
86+
steps:
87+
- uses: actions/checkout@v4
88+
89+
- uses: actions/setup-node@v4
90+
with:
91+
node-version: ${{ matrix.node }}
92+
93+
- name: Get Full Node.js Version
94+
id: get_nodejs_version
95+
shell: bash
96+
run: |
97+
echo "version=$(node --print 'process.version.slice(1)')" >> "$GITHUB_OUTPUT"
98+
99+
- name: Set up QEMU
100+
uses: docker/setup-qemu-action@v3
101+
102+
- name: Set up Docker Buildx
103+
uses: docker/setup-buildx-action@v3
104+
105+
- name: Run Buildx
106+
run: |
107+
docker buildx create --name builder --bootstrap --use
108+
docker --debug buildx build --progress=plain --no-cache \
109+
--platform linux/${{ matrix.linux_arch }} \
110+
--build-arg="PLATFORM=${{ matrix.linux_arch == 'arm64' && 'arm64v8' || matrix.linux_arch }}" \
111+
--build-arg="NODE_VERSION=${{ steps.get_nodejs_version.outputs.version }}" \
112+
--build-arg="RUN_TEST=true" \
113+
--output type=local,dest=./prebuilds,platform-split=false \
114+
-f ./.github/docker/Dockerfile.musl \
115+
.

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ build
1919

2020
npm-debug.log
2121
deps
22+
23+
prebuilds

‎.mocharc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"extension": ["ts"],
44
"recursive": true,
55
"failZero": true,
6-
"color": true
6+
"color": true,
7+
"timeout": 0
78
}

‎addon/compression.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef MONGODB_ZSTD_COMPRESSION
22
#define MONGODB_ZSTD_COMPRESSION
33

4-
#include <exception>
4+
#include <stdexcept>
55
#include <vector>
66

77
#include "compression_worker.h"

‎binding.gyp

+32-9
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,45 @@
1717
'addon/compression.h',
1818
'addon/compression.cpp'
1919
],
20+
'conditions': [
21+
[
22+
'OS=="win"',
23+
{
24+
'link_settings': {
25+
'libraries': [
26+
'<(module_root_dir)/deps/zstd/build/cmake/lib/Debug/zstd_static.lib'
27+
]
28+
},
29+
},
30+
{ # macos and linux
31+
'link_settings': {
32+
'libraries': [
33+
'<(module_root_dir)/deps/zstd/build/cmake/lib/libzstd.a',
34+
]
35+
},
36+
}
37+
]
38+
],
39+
'cflags!': [ '-fno-exceptions' ],
40+
'cflags_cc!': [ '-fno-exceptions' ],
41+
'cflags_cc': ['-std=c++17'],
2042
'xcode_settings': {
2143
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
2244
'CLANG_CXX_LIBRARY': 'libc++',
2345
'MACOSX_DEPLOYMENT_TARGET': '11',
2446
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
47+
'OTHER_CFLAGS': [
48+
'-std=c++17',
49+
'-stdlib=libc++'
50+
],
2551
},
26-
'cflags!': [ '-fno-exceptions' ],
27-
'cflags_cc!': [ '-fno-exceptions' ],
28-
'cflags_cc': ['-std=c++17'],
2952
'msvs_settings': {
30-
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
31-
},
32-
'link_settings': {
33-
'libraries': [
34-
'<(module_root_dir)/deps/zstd/build/cmake/lib/libzstd.a',
35-
]
53+
'VCCLCompilerTool': {
54+
'ExceptionHandling': 1,
55+
'AdditionalOptions': [
56+
'-std:c++17'
57+
]
58+
}
3659
},
3760
}]
3861
}

‎etc/docker.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#! /bin/bash
2+
3+
# script to aid in local testing of linux platforms
4+
# requires a running docker instance
5+
6+
# s390x, arm64, amd64 for ubuntu
7+
# amd64 or arm64v8 for alpine
8+
LINUX_ARCH=arm64
9+
10+
# 16.20.1+, default 16.20.1
11+
NODE_VERSION=18.0.0
12+
13+
SCRIPT_DIR=$(dirname ${BASH_SOURCE:-$0})
14+
PROJECT_DIR=$SCRIPT_DIR/..
15+
16+
build_and_test_musl() {
17+
docker buildx create --name builder --bootstrap --use
18+
19+
docker --debug buildx build --load --progress=plain --no-cache \
20+
--platform linux/$LINUX_ARCH --output=type=docker \
21+
--build-arg="PLATFORM=$LINUX_ARCH" \
22+
--build-arg="NODE_VERSION=$NODE_VERSION" \
23+
--build-arg="RUN_TEST=true" \
24+
-f ./.github/docker/Dockerfile.musl -t musl-zstd-base \
25+
.
26+
}
27+
28+
build_and_test_glibc() {
29+
docker buildx create --name builder --bootstrap --use
30+
31+
UBUNTU_VERSION=ubuntu_version=$(node --print '(process.argv[1].slice(1).split(`.`).at(0)) > 16 ? `noble` : `bionic`' $NODE_VERSION)
32+
NODE_ARCH=$(node -p 'process.argv[1] === `amd64` && `x64` || process.argv[1]' $LINUX_ARCH)
33+
echo $UBUNTU_VERSION
34+
docker buildx build --progress=plain --no-cache \
35+
--platform linux/$LINUX_ARCH \
36+
--build-arg="NODE_ARCH=$NODE_ARCH" \
37+
--build-arg="NODE_VERSION=$NODE_VERSION" \
38+
--build-arg="UBUNTU_VERSION$UBUNTU_VERSION" \
39+
--build-arg="RUN_TEST=true" \
40+
--output type=local,dest=./prebuilds,platform-split=false \
41+
-f ./.github/docker/Dockerfile.glibc \
42+
$PROJECT_DIR
43+
}
44+
45+
46+
build_and_test_musl

‎etc/install-zstd.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ build_zstd() {
1717
export MACOSX_DEPLOYMENT_TARGET=11
1818
cd deps/zstd/build/cmake
1919

20-
cmake .
21-
make
20+
# CMAKE_RC_FLAGS is a workaround for a bug in 1.5.6 that breaks compilation on windows.
21+
# The fix is merged but not yet released. see https://github.com/facebook/zstd/issues/3999
22+
cmake -DCMAKE_RC_FLAGS="$(pwd)/lib" -DZSTD_MULTITHREAD_SUPPORT=OFF -DZSTD_BUILD_SHARED=OFF .
23+
cmake --build .
2224
}
2325

2426
clean_deps

0 commit comments

Comments
 (0)