This is an automated email from the ASF dual-hosted git repository.

baodi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-node.git


The following commit(s) were added to refs/heads/master by this push:
     new cd2a307  Make it compatible with GLIBCXX_3.4.19 (CentOS 7) (#288)
cd2a307 is described below

commit cd2a307d99c1a4ae650d31a1f25371bf22bd2d6b
Author: Yunze Xu <[email protected]>
AuthorDate: Fri Feb 10 17:53:34 2023 +0800

    Make it compatible with GLIBCXX_3.4.19 (CentOS 7) (#288)
    
    * Make it compatible with GLIBCXX_3.4.19 (CentOS 7)
    
    Fixes https://github.com/apache/pulsar-client-node/issues/286
    
    ### Motivation
    
    The maximum GLIBCXX version on CentOS 7 is 3.4.19. If we want to use the
    Pulsar Node client on CentOS 7, we have to upgrade the libstdc++.so. The
    reason is the libstdc++ version is too high for some systems.
    https://github.com/apache/pulsar-client-node/pull/285 downgrades the
    base image to `node:18-buster` but it still requires the
    `GLIBCXX_3.4.22`.
    
    ### Modifications
    - Use `centos:7` as the base image to build `Pulsar.node` for
      glibc-based Linux distributions.
    - Add `load_test.sh` to verify `Pulsar.node` can be loaded by other
      docker images and test Node.js 16 and 19 on Debian buster and
      bullseye.
    
    * Avoid modifying the Node.js scripts
    
    * Remove the TAR each time the script is executed
    
    * Fix the binary name changed in 
https://github.com/apache/pulsar-client-node/pull/290
---
 .github/workflows/ci-pr-validation.yml             |  8 ++++++
 .gitignore                                         |  2 ++
 pkg/linux/Dockerfile_linux_glibc                   | 20 +++++++++------
 pkg/linux/download-cpp-client.sh                   |  2 ++
 pkg/load_test.js                                   |  4 +++
 .../docker-load-test.sh                            | 22 +++++++++-------
 .../Dockerfile_linux_glibc => tests/load-test.sh   | 30 +++++++++++++++-------
 7 files changed, 62 insertions(+), 26 deletions(-)

diff --git a/.github/workflows/ci-pr-validation.yml 
b/.github/workflows/ci-pr-validation.yml
index d8881c1..c966d02 100644
--- a/.github/workflows/ci-pr-validation.yml
+++ b/.github/workflows/ci-pr-validation.yml
@@ -167,6 +167,14 @@ jobs:
           docker run -i -v $PWD:/pulsar-client-node build:latest \
               /pulsar-client-node/pkg/linux/build-napi-inside-docker.sh
 
+      - name: Test NAPI file in other containers
+        if: matrix.image == 'linux_glibc'
+        run: |
+          ./tests/load-test.sh node:16-buster ${{matrix.cpu.platform}}
+          ./tests/load-test.sh node:16-bullseye ${{matrix.cpu.platform}}
+          ./tests/load-test.sh node:19-buster ${{matrix.cpu.platform}}
+          ./tests/load-test.sh node:19-bullseye ${{matrix.cpu.platform}}
+
   windows-napi:
     name: Build NAPI windows - Node ${{matrix.nodejs}} - ${{matrix.arch}}
     runs-on: windows-2022
diff --git a/.gitignore b/.gitignore
index 5f985b3..8936209 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,5 @@ report/
 .vscode
 *.tar.gz
 *.tgz
+pkg/linux/pulsar-cpp/
+lib/
diff --git a/pkg/linux/Dockerfile_linux_glibc b/pkg/linux/Dockerfile_linux_glibc
index b8a2687..f4c9f48 100644
--- a/pkg/linux/Dockerfile_linux_glibc
+++ b/pkg/linux/Dockerfile_linux_glibc
@@ -17,15 +17,19 @@
 # under the License.
 #
 
-ARG NODE_VERSION
+FROM centos:7
 
-FROM node:${NODE_VERSION}-buster
+RUN yum update -y
+RUN yum install -y gcc gcc-c++ make python3
 
-RUN apt-get update -y && \
-     apt-get install -y \
-        curl \
-        g++ \
-        make \
-        python3
+WORKDIR /app
+ARG PLATFORM
+RUN SUFFIX=$(echo ${PLATFORM} | sed 's/86_//') && \
+  echo $SUFFIX && \
+  curl -O -L 
https://nodejs.org/download/release/v16.19.0/node-v16.19.0-linux-$SUFFIX.tar.gz 
&& \
+  tar zxf node-v16.19.0-linux-$SUFFIX.tar.gz && \
+  mv node-v16.19.0-linux-$SUFFIX node-v16.19.0
+
+ENV PATH="/app/node-v16.19.0/bin:$PATH"
 
 CMD ["sh"]
diff --git a/pkg/linux/download-cpp-client.sh b/pkg/linux/download-cpp-client.sh
index 51c14dc..3c1ddcf 100755
--- a/pkg/linux/download-cpp-client.sh
+++ b/pkg/linux/download-cpp-client.sh
@@ -36,7 +36,9 @@ else
   PLATFORM=x86_64
 fi
 
+rm -rf $ROOT_DIR/pkg/linux/pulsar-cpp
 mkdir $ROOT_DIR/pkg/linux/pulsar-cpp
+rm -rf $ROOT_DIR/pkg/linux/tmp
 mkdir $ROOT_DIR/pkg/linux/tmp
 cd $ROOT_DIR/pkg/linux/tmp
 
diff --git a/pkg/load_test.js b/pkg/load_test.js
index 7ecb34a..98228c0 100644
--- a/pkg/load_test.js
+++ b/pkg/load_test.js
@@ -20,6 +20,10 @@
 const Pulsar = require('../index.js');
 
 (async () => {
+  Pulsar.Client.setLogHandler((level, file, line, message) => {
+    console.log('[%s][%s:%d] %s', Pulsar.LogLevel.toString(level), file, line, 
message);
+  });
+
   // Create a client
   const clientConfig = {
     serviceUrl: 'pulsar://localhost:6650',
diff --git a/pkg/linux/Dockerfile_linux_glibc b/tests/docker-load-test.sh
old mode 100644
new mode 100755
similarity index 63%
copy from pkg/linux/Dockerfile_linux_glibc
copy to tests/docker-load-test.sh
index b8a2687..84a91d9
--- a/pkg/linux/Dockerfile_linux_glibc
+++ b/tests/docker-load-test.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
@@ -17,15 +18,18 @@
 # under the License.
 #
 
-ARG NODE_VERSION
+# NOTE: This script should only run inside a Node.js docker container.
+# See ./load-test.sh for details.
+set -ex
 
-FROM node:${NODE_VERSION}-buster
+# Create an empty directory to test
+mkdir -p /app && cd /app
+tar zxf /pulsar-client-node/pulsar-client-node.tar.gz
 
-RUN apt-get update -y && \
-     apt-get install -y \
-        curl \
-        g++ \
-        make \
-        python3
+# Use the existing Pulsar.node built in a specific container
+mkdir -p lib/binding
+cp /pulsar-client-node/build/Release/pulsar.node lib/binding/
+npm install
 
-CMD ["sh"]
+# Test if Pulsar.node can be loaded
+node pkg/load_test.js
diff --git a/pkg/linux/Dockerfile_linux_glibc b/tests/load-test.sh
old mode 100644
new mode 100755
similarity index 57%
copy from pkg/linux/Dockerfile_linux_glibc
copy to tests/load-test.sh
index b8a2687..47d9c54
--- a/pkg/linux/Dockerfile_linux_glibc
+++ b/tests/load-test.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
@@ -17,15 +18,26 @@
 # under the License.
 #
 
-ARG NODE_VERSION
+# Test if the Pulsar.node built from ../pkg/linux/build-napi-inside-docker.sh
+# can be loaded in other Linux distributions.
 
-FROM node:${NODE_VERSION}-buster
+set -e
 
-RUN apt-get update -y && \
-     apt-get install -y \
-        curl \
-        g++ \
-        make \
-        python3
+if [[ $# -lt 2 ]]; then
+    echo "Usage $0 <node-image-name> <platform>
 
-CMD ["sh"]
+See https://hub.docker.com/_/node for valid images"
+    exit 1
+fi
+IMAGE=$1
+PLATFORM=$2
+
+ROOT_DIR=${ROOT_DIR:-$(git rev-parse --show-toplevel)}
+cd $ROOT_DIR
+
+git archive -o pulsar-client-node.tar.gz HEAD
+
+docker run --platform $PLATFORM -v $PWD:/pulsar-client-node $IMAGE \
+    /bin/bash /pulsar-client-node/tests/docker-load-test.sh
+
+rm pulsar-client-node.tar.gz

Reply via email to