You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by te...@apache.org on 2022/08/15 15:09:36 UTC

[pulsar] branch master updated: [fix][C++ client] Fix rpm and deb packaging (#17064)

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

technoboy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new d88933a27e6 [fix][C++ client] Fix rpm and deb packaging (#17064)
d88933a27e6 is described below

commit d88933a27e679a6458b6938f8b969beb6d295d05
Author: Yunze Xu <xy...@163.com>
AuthorDate: Mon Aug 15 23:09:25 2022 +0800

    [fix][C++ client] Fix rpm and deb packaging (#17064)
---
 .github/workflows/ci-cpp-deb-pkg.yaml           | 97 +++++++++++++++++++++++++
 .github/workflows/ci-cpp-rpm-pkg.yaml           | 97 +++++++++++++++++++++++++
 pulsar-client-cpp/pkg/deb/Dockerfile            | 47 ++++++------
 pulsar-client-cpp/pkg/deb/build-deb.sh          |  5 +-
 pulsar-client-cpp/pkg/deb/build-docker-image.sh | 21 ------
 pulsar-client-cpp/pkg/deb/docker-build-deb.sh   | 12 ++-
 pulsar-client-cpp/pkg/rpm/Dockerfile            | 44 +++++------
 pulsar-client-cpp/pkg/rpm/build-docker-image.sh | 21 ------
 pulsar-client-cpp/pkg/rpm/docker-build-rpm.sh   | 12 ++-
 9 files changed, 260 insertions(+), 96 deletions(-)

diff --git a/.github/workflows/ci-cpp-deb-pkg.yaml b/.github/workflows/ci-cpp-deb-pkg.yaml
new file mode 100644
index 00000000000..b6c75c4c727
--- /dev/null
+++ b/.github/workflows/ci-cpp-deb-pkg.yaml
@@ -0,0 +1,97 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+name: CI - CPP DEB packaging
+on:
+  pull_request:
+    branches:
+      - master
+    paths:
+      - '.github/workflows/**'
+      - 'pulsar-client-cpp/**'
+  push:
+    branches:
+      - branch-*
+    paths:
+      - '.github/workflows/**'
+      - 'pulsar-client-cpp/**'
+
+concurrency:
+  group: ${{ github.workflow }}-${{ github.ref }}
+  cancel-in-progress: true
+
+jobs:
+
+  cpp-deb-packaging:
+    name:
+    runs-on: ubuntu-latest
+    timeout-minutes: 120
+
+    steps:
+      - name: checkout
+        uses: actions/checkout@v2
+
+      - name: Tune Runner VM
+        uses: ./.github/actions/tune-runner-vm
+
+      - name: Detect changed files
+        id:   changes
+        uses: apache/pulsar-test-infra/paths-filter@master
+        with:
+          filters: .github/changes-filter.yaml
+          list-files: csv
+
+      - name: Check changed files
+        id: check_changes
+        run: echo "::set-output name=docs_only::${{ fromJSON(steps.changes.outputs.all_count) == fromJSON(steps.changes.outputs.docs_count) && fromJSON(steps.changes.outputs.docs_count) > 0 }}"
+
+      - name: Cache local Maven repository
+        if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
+        uses: actions/cache@v2
+        with:
+          path: |
+            ~/.m2/repository/*/*/*
+            !~/.m2/repository/org/apache/pulsar
+          key: ${{ runner.os }}-m2-dependencies-core-modules-${{ hashFiles('**/pom.xml') }}
+          restore-keys: |
+            ${{ runner.os }}-m2-dependencies-core-modules-
+
+      - name: Set up JDK 17
+        uses: actions/setup-java@v2
+        if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
+        with:
+          distribution: 'temurin'
+          java-version: 17
+
+      - name: clean disk
+        if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
+        run: |
+          sudo apt clean
+          docker rmi $(docker images -q) -f
+          df -h
+
+      - name: Package Pulsar source
+        if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
+        run: mvn -B -ntp -q clean package -pl pulsar-client-api -am -DskipTests
+
+      - name: Build Debian packages
+        if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
+        run: |
+          echo "Build Debian packages"
+          BUILD_IMAGE=1 pulsar-client-cpp/pkg/deb/docker-build-deb.sh
diff --git a/.github/workflows/ci-cpp-rpm-pkg.yaml b/.github/workflows/ci-cpp-rpm-pkg.yaml
new file mode 100644
index 00000000000..b8da1eac99d
--- /dev/null
+++ b/.github/workflows/ci-cpp-rpm-pkg.yaml
@@ -0,0 +1,97 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+name: CI - CPP RPM packaging
+on:
+  pull_request:
+    branches:
+      - master
+    paths:
+      - '.github/workflows/**'
+      - 'pulsar-client-cpp/**'
+  push:
+    branches:
+      - branch-*
+    paths:
+      - '.github/workflows/**'
+      - 'pulsar-client-cpp/**'
+
+concurrency:
+  group: ${{ github.workflow }}-${{ github.ref }}
+  cancel-in-progress: true
+
+jobs:
+
+  cpp-rpm-packaging:
+    name:
+    runs-on: ubuntu-latest
+    timeout-minutes: 120
+
+    steps:
+      - name: checkout
+        uses: actions/checkout@v2
+
+      - name: Tune Runner VM
+        uses: ./.github/actions/tune-runner-vm
+
+      - name: Detect changed files
+        id:   changes
+        uses: apache/pulsar-test-infra/paths-filter@master
+        with:
+          filters: .github/changes-filter.yaml
+          list-files: csv
+
+      - name: Check changed files
+        id: check_changes
+        run: echo "::set-output name=docs_only::${{ fromJSON(steps.changes.outputs.all_count) == fromJSON(steps.changes.outputs.docs_count) && fromJSON(steps.changes.outputs.docs_count) > 0 }}"
+
+      - name: Cache local Maven repository
+        if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
+        uses: actions/cache@v2
+        with:
+          path: |
+            ~/.m2/repository/*/*/*
+            !~/.m2/repository/org/apache/pulsar
+          key: ${{ runner.os }}-m2-dependencies-core-modules-${{ hashFiles('**/pom.xml') }}
+          restore-keys: |
+            ${{ runner.os }}-m2-dependencies-core-modules-
+
+      - name: Set up JDK 17
+        uses: actions/setup-java@v2
+        if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
+        with:
+          distribution: 'temurin'
+          java-version: 17
+
+      - name: clean disk
+        if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
+        run: |
+          sudo apt clean
+          docker rmi $(docker images -q) -f
+          df -h
+
+      - name: Package Pulsar source
+        if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
+        run: mvn -B -ntp -q clean package -pl pulsar-client-api -am -DskipTests
+
+      - name: Build RPM packages
+        if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
+        run: |
+          echo "Build RPM packages"
+          BUILD_IMAGE=1 pulsar-client-cpp/pkg/rpm/docker-build-rpm.sh
diff --git a/pulsar-client-cpp/pkg/deb/Dockerfile b/pulsar-client-cpp/pkg/deb/Dockerfile
index def8bdb55d0..925f2bb7d8b 100644
--- a/pulsar-client-cpp/pkg/deb/Dockerfile
+++ b/pulsar-client-cpp/pkg/deb/Dockerfile
@@ -19,38 +19,37 @@
 
 # Build pulsar client library in Centos with tools to
 
-FROM debian:9
+FROM --platform=linux/amd64 debian:9
 
+# perl is required to install OpenSSL
 RUN apt-get update -y && \
-     apt-get install -y curl g++ make python-dev \
-                libxml2-utils git
+     apt-get install -y curl g++ make perl dpkg-dev python3
 
 # Download and compile boost
-RUN curl -O -L https://boostorg.jfrog.io/artifactory/main/release/1.64.0/source/boost_1_64_0.tar.gz && \
-    tar xvfz boost_1_64_0.tar.gz && \
-    cd /boost_1_64_0 && \
-    ./bootstrap.sh --with-libraries=program_options,filesystem,regex,thread,system,python && \
+RUN curl -O -L https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz && \
+    tar xfz boost_1_79_0.tar.gz && \
+    cd boost_1_79_0 && \
+    ./bootstrap.sh && \
     ./b2 address-model=64 cxxflags=-fPIC link=static threading=multi variant=release install && \
-    rm -rf /boost_1_64_0.tar.gz /boost_1_64_0
+    rm -rf /boost_1_79_0.tar.gz /boost_1_79_0
 
-RUN curl -O -L https://github.com/Kitware/CMake/archive/v3.8.2.tar.gz && \
-    tar xvfz v3.8.2.tar.gz && \
-    cd CMake-3.8.2 && \
-    ./configure && \
-    make && make install && \
-    rm -rf /v3.8.2.tar.gz /CMake-3.8.2
+RUN curl -O -L https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0-linux-x86_64.tar.gz && \
+    tar xfz cmake-3.24.0-linux-x86_64.tar.gz && \
+    cp cmake-3.24.0-linux-x86_64/bin/* /usr/bin/ && \
+    cp -r cmake-3.24.0-linux-x86_64/share/cmake-3.24 /usr/share/ && \
+    rm -rf cmake-3.24.0-linux-x86_64 cmake-3.24.0-linux-x86_64.tar.gz
 
 # Download and copile protoubf
 RUN curl -O -L  https://github.com/google/protobuf/releases/download/v3.20.0/protobuf-cpp-3.20.0.tar.gz && \
-    tar xvfz protobuf-cpp-3.20.0.tar.gz && \
+    tar xfz protobuf-cpp-3.20.0.tar.gz && \
     cd protobuf-3.20.0/ && \
     CXXFLAGS=-fPIC ./configure && \
-    make && make install && ldconfig && \
+    make -j8 && make install && ldconfig && \
     rm -rf /protobuf-cpp-3.20.0.tar.gz /protobuf-3.20.0
 
 # ZLib
 RUN curl -O -L https://github.com/madler/zlib/archive/v1.2.12.tar.gz && \
-    tar xvfz v1.2.12.tar.gz && \
+    tar xfz v1.2.12.tar.gz && \
     cd zlib-1.2.12 && \
     CFLAGS="-fPIC -O3" ./configure && \
     make && make install && \
@@ -58,7 +57,7 @@ RUN curl -O -L https://github.com/madler/zlib/archive/v1.2.12.tar.gz && \
 
 # Zstandard
 RUN curl -O -L https://github.com/facebook/zstd/releases/download/v1.3.7/zstd-1.3.7.tar.gz && \
-    tar xvfz zstd-1.3.7.tar.gz && \
+    tar xfz zstd-1.3.7.tar.gz && \
     cd zstd-1.3.7 && \
     CFLAGS="-fPIC -O3" make -j8 && \
     make install && \
@@ -66,27 +65,25 @@ RUN curl -O -L https://github.com/facebook/zstd/releases/download/v1.3.7/zstd-1.
 
 # Snappy
 RUN curl -O -L https://github.com/google/snappy/releases/download/1.1.3/snappy-1.1.3.tar.gz && \
-    tar xvfz snappy-1.1.3.tar.gz && \
+    tar xfz snappy-1.1.3.tar.gz && \
     cd snappy-1.1.3 && \
     CXXFLAGS="-fPIC -O3" ./configure && \
     make && make install && \
     rm -rf /snappy-1.1.3 /snappy-1.1.3.tar.gz
 
 RUN curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_0j.tar.gz && \
-    tar xvfz OpenSSL_1_1_0j.tar.gz && \
+    tar xfz OpenSSL_1_1_0j.tar.gz && \
     cd openssl-OpenSSL_1_1_0j/ && \
     ./Configure -fPIC --prefix=/usr/local/ssl/ linux-x86_64 && \
-    make && make install && \
+    make -j8 && make install && \
     rm -rf /OpenSSL_1_1_0j.tar.gz /openssl-OpenSSL_1_1_0j
 
 # LibCurl
 RUN curl -O -L  https://github.com/curl/curl/releases/download/curl-7_61_0/curl-7.61.0.tar.gz && \
-    tar xvfz curl-7.61.0.tar.gz && \
+    tar xfz curl-7.61.0.tar.gz && \
     cd curl-7.61.0 && \
     CFLAGS=-fPIC ./configure --with-ssl=/usr/local/ssl/ && \
-    make && make install && \
+    make -j8 && make install && \
     rm -rf /curl-7.61.0.tar.gz /curl-7.61.0
 
-RUN apt-get install -y dpkg-dev
-
 ENV OPENSSL_ROOT_DIR /usr/local/ssl/
diff --git a/pulsar-client-cpp/pkg/deb/build-deb.sh b/pulsar-client-cpp/pkg/deb/build-deb.sh
index 3f2dc5113eb..b7409de535a 100755
--- a/pulsar-client-cpp/pkg/deb/build-deb.sh
+++ b/pulsar-client-cpp/pkg/deb/build-deb.sh
@@ -37,8 +37,11 @@ cd BUILD
 tar xfz $SRC_ROOT_DIR/target/apache-pulsar-$POM_VERSION-src.tar.gz
 pushd $CPP_DIR
 
+# link libraries for protoc
+export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
+
 chmod +x $(find . -name "*.sh")
-cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON
+cmake . -DBUILD_TESTS=OFF -DBUILD_PYTHON_WRAPPER=OFF -DBUILD_PERF_TOOLS=OFF -DLINK_STATIC=ON
 make pulsarShared pulsarSharedNossl pulsarStatic pulsarStaticWithDeps  -j 3
 popd
 
diff --git a/pulsar-client-cpp/pkg/deb/build-docker-image.sh b/pulsar-client-cpp/pkg/deb/build-docker-image.sh
deleted file mode 100755
index 4173912cf78..00000000000
--- a/pulsar-client-cpp/pkg/deb/build-docker-image.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-docker build -t apachepulsar/pulsar-build:debian-9 .
diff --git a/pulsar-client-cpp/pkg/deb/docker-build-deb.sh b/pulsar-client-cpp/pkg/deb/docker-build-deb.sh
index 55289cc069b..bc7f42234b3 100755
--- a/pulsar-client-cpp/pkg/deb/docker-build-deb.sh
+++ b/pulsar-client-cpp/pkg/deb/docker-build-deb.sh
@@ -18,11 +18,17 @@
 # under the License.
 #
 
-set -e
+set -ex
 
 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../../.. &> /dev/null && pwd )"
+IMAGE_NAME=apachepulsar/pulsar-build:debian-9-2.11
 
-docker pull apachepulsar/pulsar-build:debian-9
+if [[ -z $BUILD_IMAGE ]]; then
+    # pull the image from DockerHub by default
+    docker pull $IMAGE_NAME
+else
+    docker build --platform linux/amd64 -t $IMAGE_NAME $ROOT_DIR/pulsar-client-cpp/pkg/deb
+fi
 
-docker run -i -v $ROOT_DIR:/pulsar apachepulsar/pulsar-build:debian-9 \
+docker run --platform linux/amd64 -v $ROOT_DIR:/pulsar $IMAGE_NAME \
         /pulsar/pulsar-client-cpp/pkg/deb/build-deb.sh
diff --git a/pulsar-client-cpp/pkg/rpm/Dockerfile b/pulsar-client-cpp/pkg/rpm/Dockerfile
index b3cf4323182..8d1693e053d 100644
--- a/pulsar-client-cpp/pkg/rpm/Dockerfile
+++ b/pulsar-client-cpp/pkg/rpm/Dockerfile
@@ -19,38 +19,38 @@
 
 # Build pulsar client library in Centos with tools to build static RPM
 
-FROM centos:7
+FROM --platform=linux/amd64 centos:7
 
 RUN yum update -y && \
-    yum install -y gcc-c++ make cmake git rpm-build \
-                python-devel createrepo libstdc++-static.x86_64
+    yum install -y gcc-c++ make rpm-build which \
+                createrepo libstdc++-static.x86_64 python3
 
 # Download and compile boost
-RUN curl -O -L https://boostorg.jfrog.io/artifactory/main/release/1.64.0/source/boost_1_64_0.tar.gz && \
-    tar xvfz boost_1_64_0.tar.gz && \
-    cd /boost_1_64_0 && \
-    ./bootstrap.sh --with-libraries=program_options,filesystem,regex,thread,system,python && \
+# GCC 4.8.2 implementation of std::regex is buggy, so we install boost::regex here
+RUN curl -O -L https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz && \
+    tar xfz boost_1_79_0.tar.gz && \
+    cd boost_1_79_0 && \
+    ./bootstrap.sh --with-libraries=regex && \
     ./b2 address-model=64 cxxflags=-fPIC link=static threading=multi variant=release install && \
-    rm -rf /boost_1_64_0.tar.gz /boost_1_64_0
+    rm -rf /boost_1_79_0.tar.gz /boost_1_79_0
 
-RUN curl -O -L https://github.com/Kitware/CMake/archive/v3.8.2.tar.gz && \
-    tar xvfz v3.8.2.tar.gz && \
-    cd CMake-3.8.2 && \
-    ./configure && \
-    make && make install && \
-    rm -rf /v3.8.2.tar.gz /CMake-3.8.2
+RUN curl -O -L https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0-linux-x86_64.tar.gz && \
+    tar xfz cmake-3.24.0-linux-x86_64.tar.gz && \
+    cp cmake-3.24.0-linux-x86_64/bin/* /usr/bin/ && \
+    cp -r cmake-3.24.0-linux-x86_64/share/cmake-3.24 /usr/share/ && \
+    rm -rf cmake-3.24.0-linux-x86_64 cmake-3.24.0-linux-x86_64.tar.gz
 
 # Download and copile protoubf
 RUN curl -O -L  https://github.com/google/protobuf/releases/download/v3.20.0/protobuf-cpp-3.20.0.tar.gz && \
-    tar xvfz protobuf-cpp-3.20.0.tar.gz && \
+    tar xfz protobuf-cpp-3.20.0.tar.gz && \
     cd protobuf-3.20.0/ && \
     CXXFLAGS=-fPIC ./configure && \
-    make && make install && ldconfig && \
+    make -j8 && make install && ldconfig && \
     rm -rf /protobuf-cpp-3.20.0.tar.gz /protobuf-3.20.0
 
 # ZLib
 RUN curl -O -L https://github.com/madler/zlib/archive/v1.2.12.tar.gz && \
-    tar xvfz v1.2.12.tar.gz && \
+    tar xfz v1.2.12.tar.gz && \
     cd zlib-1.2.12 && \
     CFLAGS="-fPIC -O3" ./configure && \
     make && make install && \
@@ -58,7 +58,7 @@ RUN curl -O -L https://github.com/madler/zlib/archive/v1.2.12.tar.gz && \
 
 # Zstandard
 RUN curl -O -L https://github.com/facebook/zstd/releases/download/v1.3.7/zstd-1.3.7.tar.gz && \
-    tar xvfz zstd-1.3.7.tar.gz && \
+    tar xfz zstd-1.3.7.tar.gz && \
     cd zstd-1.3.7 && \
     CFLAGS="-fPIC -O3" make -j8 && \
     make install && \
@@ -66,22 +66,22 @@ RUN curl -O -L https://github.com/facebook/zstd/releases/download/v1.3.7/zstd-1.
 
 # Snappy
 RUN curl -O -L https://github.com/google/snappy/releases/download/1.1.3/snappy-1.1.3.tar.gz && \
-    tar xvfz snappy-1.1.3.tar.gz && \
+    tar xfz snappy-1.1.3.tar.gz && \
     cd snappy-1.1.3 && \
     CXXFLAGS="-fPIC -O3" ./configure && \
     make && make install && \
     rm -rf /snappy-1.1.3 /snappy-1.1.3.tar.gz
 
 RUN curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_0j.tar.gz && \
-    tar xvfz OpenSSL_1_1_0j.tar.gz && \
+    tar xfz OpenSSL_1_1_0j.tar.gz && \
     cd openssl-OpenSSL_1_1_0j/ && \
     ./Configure -fPIC --prefix=/usr/local/ssl/ linux-x86_64 && \
-    make && make install && \
+    make -j8 && make install && \
     rm -rf /OpenSSL_1_1_0j.tar.gz /openssl-OpenSSL_1_1_0j
 
 # LibCurl
 RUN curl -O -L  https://github.com/curl/curl/releases/download/curl-7_61_0/curl-7.61.0.tar.gz && \
-    tar xvfz curl-7.61.0.tar.gz && \
+    tar xfz curl-7.61.0.tar.gz && \
     cd curl-7.61.0 && \
     CFLAGS=-fPIC ./configure --with-ssl=/usr/local/ssl/ && \
     make && make install && \
diff --git a/pulsar-client-cpp/pkg/rpm/build-docker-image.sh b/pulsar-client-cpp/pkg/rpm/build-docker-image.sh
deleted file mode 100755
index faf7ff50bbb..00000000000
--- a/pulsar-client-cpp/pkg/rpm/build-docker-image.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-docker build -t apachepulsar/pulsar-build:centos-7 .
diff --git a/pulsar-client-cpp/pkg/rpm/docker-build-rpm.sh b/pulsar-client-cpp/pkg/rpm/docker-build-rpm.sh
index e72114d7840..4ba02afc3dc 100755
--- a/pulsar-client-cpp/pkg/rpm/docker-build-rpm.sh
+++ b/pulsar-client-cpp/pkg/rpm/docker-build-rpm.sh
@@ -18,11 +18,17 @@
 # under the License.
 #
 
-set -e
+set -ex
 
 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../../.. &> /dev/null && pwd )"
+IMAGE_NAME=apachepulsar/pulsar-build:centos-7-2.11
 
-docker pull apachepulsar/pulsar-build:centos-7
+if [[ -z $BUILD_IMAGE ]]; then
+    # pull the image from DockerHub by default
+    docker pull $IMAGE_NAME
+else
+    docker build --platform linux/amd64 -t $IMAGE_NAME $ROOT_DIR/pulsar-client-cpp/pkg/rpm
+fi
 
-docker run -it -v $ROOT_DIR:/pulsar apachepulsar/pulsar-build:centos-7 \
+docker run --platform linux/amd64 -v $ROOT_DIR:/pulsar $IMAGE_NAME \
         /pulsar/pulsar-client-cpp/pkg/rpm/build-rpm.sh