Skip to content

Commit

Permalink
[fix][C++ client] Fix rpm and deb packaging
Browse files Browse the repository at this point in the history
### Motivation

For branch-2.11 and master branches, the rpm and deb packaging is
broken.

> /usr/bin/env: 'python3': No such file or directory

It's caused by [PIP-155](apache#15376),
which removes the Python2 support. In addition, the Dockerfiles of `rpm`
and `deb` subdirectories of `pulsar-client-cpp/pkg` don't install Boost
for Python3 well. But the rpm build disables the
`BUILD_PYTHON_WRAPPER` option while the deb build doesn't.

### Modifications

- Fix Dockerfiles under `pkg` and `rpm` subdirectories and speed up the
  `docker build` process:
   - Install python3 to fix the bug
   - Download the CMake 3.24.0 binaries directly instead of building
     from source
   - Upgrade Boost to 1.79 so that only headers are required (the
     boost::regex module is required for CentOS 7 because the default
     GCC is 4.8 that there is something wrong with std::regex)
   - Add `-j8` option when compiling some large dependencies that uses 8
     threads to speed the compilation
   - Remove the `-v` option of `tar` to avoid showing too many info
- Check the `BUILD_IMAGE` environment variable in `docker-build-xxx.sh`
  under `rpm` and `deb` subdirectories. If it's defined, build the image
  rather than pull the image from DockerHub before executing the build
  script. Because currently only a few committers have the permission to
  push the Docker images.
- Add two workflows to build RPM and DEB packages if the files under
  `pulsar-client-cpp` changed. They build the docker images and run the
  build script for RPM and DEB packaging.
- Specify the platform to `linux/amd64` so that the scripts can be used
  in ARM64 machines like Mac M1.
  • Loading branch information
BewareMyPower committed Aug 15, 2022
1 parent 70020f1 commit 96fb9d0
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 96 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/ci-cpp-deb-pkg.yaml
Original file line number Diff line number Diff line change
@@ -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
97 changes: 97 additions & 0 deletions .github/workflows/ci-cpp-rpm-pkg.yaml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 22 additions & 25 deletions pulsar-client-cpp/pkg/deb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,74 +19,71 @@

# 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 && \
rm -rf /v1.2.12.tar.gz /zlib-1.2.12

# 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 && \
rm -rf /zstd-1.3.7 /zstd-1.3.7.tar.gz

# 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/
5 changes: 4 additions & 1 deletion pulsar-client-cpp/pkg/deb/build-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 0 additions & 21 deletions pulsar-client-cpp/pkg/deb/build-docker-image.sh

This file was deleted.

12 changes: 9 additions & 3 deletions pulsar-client-cpp/pkg/deb/docker-build-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 96fb9d0

Please sign in to comment.