Skip to content

Commit

Permalink
Merge pull request #122 from syuu1228/rpm_deb_packaging
Browse files Browse the repository at this point in the history
Support rpm and deb packaging
  • Loading branch information
wprzytula authored Jun 3, 2024
2 parents 2dc346c + 58f1408 commit 879c6ab
Show file tree
Hide file tree
Showing 22 changed files with 740 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ scylla-rust-wrapper/target/
.idea/
cmake-build-debug/
.cache/

version
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,37 @@ Now, use `--gtest_filter` to run certain integration tests:

##### Note: Tests that pass with ScyllaDB and Cassandra clusters can be found in GitHub Actions [`build.yml`](https://github.com/scylladb/cpp-rust-driver/blob/master/.github/workflows/build.yml) and [`cassandra.yml`](https://github.com/scylladb/cpp-rust-driver/blob/master/.github/workflows/cassandra.yml) workflows.

# Build rpm package
___

To build rpm package, run the following command:
```shell
./dist/redhat/build_rpm.sh --target rocky-8-x86_64
```
It will construct chrooted build environment of target distribution using mock,
and build rpm in the environment.
Target parameter should be mock .cfg file name.
Currently tested on rocky-8-x86_64, rocky-9-x86_64, fedora-38-x86_64, fedora-39-x86_64, fedora-40-x86_64, fedora-rawhide-x86_64.
Build environment should be Fedora or RHEL variants + EPEL, since
other distribution does not provide mock package.
Built result will placed under build/redhat/{rpms,srpms}.

# Build deb package
___

To build deb package, run the following command:
```shell
./dist/redhat/build_deb.sh --target mantic
```
It will construct chrooted build environment of target distribution using
pbuilder, and build deb in the environment.
Target parameter should be debian/ubuntu codename.
On Ubuntu targets, currently tested on focal (20.04), jammy (22.04), mantic (23.10), noble (24.04).
On Debian targets, currently tested on buster (10), bullseye (11), bookworm (12), trixie (13), sid (unstable).
Build environment should be Fedora, Ubuntu or Debian, since these distribution
provides pbuilder package.
Built result will placed under build/debian/debs.

# Getting Help
___

Expand All @@ -338,4 +369,4 @@ ___
# License
___

This project is licensed under the GNU Lesser General Public License v2.1
This project is licensed under the GNU Lesser General Public License v2.1
110 changes: 110 additions & 0 deletions SCYLLA-VERSION-GEN
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash -e

USAGE="$(cat <<-END
Usage: $(basename "$0") [-h|--help] [-o|--output-dir PATH] [--date-stamp DATE] -- generate Scylla version and build information files.
Options:
-h|--help show this help message.
-o|--output-dir PATH specify destination path at which the version files are to be created.
-d|--date-stamp DATE manually set date for release parameter
-v|--verbose also print out the version number
By default, the script will attempt to parse 'version' file
in the current directory, which should contain a string of
'\$version-\$release' form.
Otherwise, it will call 'git log' on the source tree (the
directory, which contains the script) to obtain current
commit hash and use it for building the version and release
strings.
The script assumes that it's called from the Scylla source
tree.
The files created are:
SCYLLA-VERSION-FILE
SCYLLA-RELEASE-FILE
By default, these files are created in the 'build'
subdirectory under the directory containing the script.
The destination directory can be overridden by
using '-o PATH' option.
END
)"

DATE=""
PRINT_VERSION=0

while [[ $# -gt 0 ]]; do
opt="$1"
case "${opt}" in
-h|--help)
echo "${USAGE}"
exit 0
;;
-o|--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
--date-stamp)
DATE="$2"
shift 2
;;
-v|--verbose)
PRINT_VERSION=1
shift 1
;;
*)
echo "Unexpected argument found: $1"
echo
echo "${USAGE}"
exit 1
;;
esac
done

SCRIPT_DIR="$(dirname "$0")"

if [[ -z "${OUTPUT_DIR}" ]]; then
OUTPUT_DIR="${SCRIPT_DIR}/build"
fi

if [[ -z "${DATE}" ]]; then
DATE="$(date --utc +%Y%m%d)"
fi

# Default scylla version tags
VERSION="$(sed -n -e 's/^version = \"\(.*\)\"$/\1/p' scylla-rust-wrapper/Cargo.toml)"

if [[ -f version ]]; then
SCYLLA_VERSION="$(cat version | awk -F'-' '{print $1}')"
SCYLLA_RELEASE="$(cat version | awk -F'-' '{print $2}')"
else
SCYLLA_VERSION="${VERSION}"
if [[ -z "${SCYLLA_RELEASE}" ]]; then
GIT_COMMIT="$(git -C "${SCRIPT_DIR}" log --pretty=format:'%h' -n 1 --abbrev=12)"
# For custom package builds, replace "0" with "counter.your_name",
# where counter starts at 1 and increments for successive versions.
# This ensures that the package manager will select your custom
# package over the standard release.
SCYLLA_BUILD=0
SCYLLA_RELEASE="${SCYLLA_BUILD}.${DATE}.${GIT_COMMIT}"
elif [[ -f "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" ]]; then
echo "setting SCYLLA_RELEASE only makes sense in clean builds" 1>&2
exit 1
fi
fi

if [[ -f "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" ]]; then
GIT_COMMIT_FILE=$(cat "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" |cut -d . -f 3)
if [[ "${GIT_COMMIT}" = "${GIT_COMMIT_FILE}" ]]; then
exit 0
fi
fi

if [[ ${PRINT_VERSION} -eq 1 ]]; then
echo "${SCYLLA_VERSION}-${SCYLLA_RELEASE}"
fi
mkdir -p "${OUTPUT_DIR}"
echo "${SCYLLA_VERSION}" > "${OUTPUT_DIR}/SCYLLA-VERSION-FILE"
echo "${SCYLLA_RELEASE}" > "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE"
11 changes: 11 additions & 0 deletions dist/common/pkgconfig/scylla-cpp-driver.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: scylla-cpp-rust-driver
Description: ScyllaDB Cpp-Rust Driver
Version: @version@
Libs: -L${libdir} -lscylla-cpp-driver
Cflags: -I${includedir}
URL: https://github.com/scylladb/cpp-rust-driver/
12 changes: 12 additions & 0 deletions dist/common/pkgconfig/scylla-cpp-driver_static.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: scylla-cpp-rust-driver
Description: ScyllaDB Cpp-Rust Driver
Version: @version@
Requires: openssl
Libs: -L${libdir} -lscylla-cpp-driver_static
Cflags: -I${includedir}
URL: https://github.com/scylladb/cpp-rust-driver/
146 changes: 146 additions & 0 deletions dist/debian/build_deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/bin/bash -e

. /etc/os-release
print_usage() {
echo "build_deb.sh --jobs 2 --target jammy"
echo " --target target distribution codename"
echo " --no-clean don't rebuild pbuilder tgz"
echo " --jobs specify number of jobs"
exit 1
}

TARGET=
NO_CLEAN=0
JOBS="$(nproc)"
while [ $# -gt 0 ]; do
case "$1" in
"--target")
TARGET=$2
shift 2
;;
"--no-clean")
NO_CLEAN=1
shift 1
;;
"--jobs")
JOBS=$2
shift 2
;;
*)
print_usage
;;
esac
done

is_redhat_variant() {
[[ -f /etc/redhat-release ]]
}
is_debian_variant() {
[[ -f /etc/debian_version ]]
}
is_debian() {
case "$1" in
buster|bullseye|bookworm|trixie|sid) return 0;;
*) return 1;;
esac
}
is_ubuntu() {
case "$1" in
bionic|focal|jammy|mantic|noble) return 0;;
*) return 1;;
esac
}


APT_UPDATED=0
declare -A DEB_PKG=(
["debian-keyring"]="debian-archive-keyring"
["ubu-keyring"]="ubuntu-keyring"
)
pkg_install() {
if is_redhat_variant; then
sudo yum install -y "$1"
elif is_debian_variant; then
if [[ "${APT_UPDATED}" -eq 0 ]]; then
sudo apt-get -y update
APT_UPDATED=1
fi
if [[ -n "${DEB_PKG[$1]}" ]]; then
pkg="${DEB_PKG[$1]}"
else
pkg="$1"
fi
sudo apt-get install -y "$pkg"
else
echo "Requires to install following command: $1"
exit 1
fi
}

if [[ ! -e dist/debian/build_deb.sh ]]; then
echo "run build_deb.sh in top of scylla dir"
exit 1
fi

if [[ -z "${TARGET}" ]]; then
echo "Please specify target"
exit 1
fi

if [[ ! -f /usr/bin/git ]]; then
pkg_install git
fi
if [[ ! -f /usr/sbin/pbuilder ]]; then
pkg_install pbuilder
fi
if [[ ! -f /usr/bin/dh_testdir ]]; then
pkg_install debhelper
fi
if is_debian "${TARGET}" && [[ ! -f /usr/share/keyrings/debian-archive-keyring.gpg ]]; then
pkg_install debian-keyring
fi
if is_ubuntu "${TARGET}" && [[ ! -f /usr/share/keyrings/ubuntu-archive-keyring.gpg ]]; then
pkg_install ubu-keyring
fi

./SCYLLA-VERSION-GEN
DRIVER_NAME=scylla-cpp-rust-driver
DRIVER_VERSION="$(sed 's/-/~/' build/SCYLLA-VERSION-FILE)"
DRIVER_RELEASE="$(cat build/SCYLLA-RELEASE-FILE)"
ARCH="$(dpkg --print-architecture)"

mkdir -p build/debian/debs
git archive HEAD --prefix "${DRIVER_NAME}-${DRIVER_VERSION}/" --output "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar"
echo "$(cat build/SCYLLA-VERSION-FILE)-$(cat build/SCYLLA-RELEASE-FILE)" > version
tar --xform "s#^#${DRIVER_NAME}-${DRIVER_VERSION}/#" -rf "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar" version
gzip -f --fast "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar"

if is_debian "${TARGET}"; then
DRIVER_REVISION="1~${TARGET}"
elif is_ubuntu "${TARGET}"; then
DRIVER_REVISION="0ubuntu1~${TARGET}"
else
echo "Unknown distribution: ${TARGET}"
fi
tar xpvf "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar.gz" -C build/debian

./dist/debian/debian_files_gen.py --version "${DRIVER_VERSION}" --release "${DRIVER_RELEASE}" --revision "${DRIVER_REVISION}" --codename "${TARGET}" --output-dir "build/debian/${DRIVER_NAME}"-"${DRIVER_VERSION}"/debian

# pbuilder generates files owned by root, fix this up
fix_ownership() {
CURRENT_UID="$(id -u)"
CURRENT_GID="$(id -g)"
sudo chown "${CURRENT_UID}":"${CURRENT_GID}" -R "$@"
}

# use from pbuilderrc
if [[ "${NO_CLEAN}" -eq 0 ]]; then
sudo rm -fv "/var/cache/pbuilder/${DRIVER_NAME}-${TARGET}-${ARCH}-base.tgz"
sudo mkdir -p "/var/cache/pbuilder/${DRIVER_NAME}-${TARGET}-${ARCH}/aptcache"
sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder clean --configfile ./dist/debian/pbuilderrc
sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder create --configfile ./dist/debian/pbuilderrc
fi
sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder update --configfile ./dist/debian/pbuilderrc
(cd "build/debian/${DRIVER_NAME}"-"${DRIVER_VERSION}"; dpkg-source -b .)
sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder build --configfile ./dist/debian/pbuilderrc --buildresult build/debian/debs "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}-${DRIVER_REVISION}.dsc"
fix_ownership build/debian/debs
5 changes: 5 additions & 0 deletions dist/debian/changelog.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scylla-cpp-rust-driver (%{version}-%{release}-%{revision}) %{codename}; urgency=medium

* Initial release.

-- Takuya ASADA <syuu@scylladb.com> Wed, 1 May 2024 11:02:04 +0000
31 changes: 31 additions & 0 deletions dist/debian/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Source: scylla-cpp-rust-driver
Maintainer: Takuya ASADA <syuu@scylladb.com>
Homepage: https://github.com/scylladb/cpp-rust-driver
Section: libs
Priority: optional
Standards-Version: 4.6.0
Build-Depends: debhelper-compat (= 11),
libssl-dev,
libclang-dev,
pkg-config,
openssl,
ca-certificates,
curl,
clang

Package: libscylla-cpp-driver0
Architecture: any
Depends: ${misc:Depends},
${shlibs:Depends},
Conflicts: scylla-cpp-driver
Description: ScyllaDB Cpp-Rust Driver
API-compatible rewrite of https://github.com/scylladb/cpp-driver as a wrapper for Rust driver.

Package: libscylla-cpp-driver-dev
Section: libdevel
Architecture: any
Depends: libscylla-cpp-driver0 (= ${binary:Version}),
${misc:Depends},
Conflicts: scylla-cpp-driver-dev
Description: Development libraries for ScyllaDB Cpp-Rust Driver
API-compatible rewrite of https://github.com/scylladb/cpp-driver as a wrapper for Rust driver.
25 changes: 25 additions & 0 deletions dist/debian/debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Scylla DB
Upstream-Contact: http://www.scylladb.com/
Source: https://github.com/scylladb/cpp-rust-driver

Files: *
Copyright: Copyright (C) 2024 ScyllaDB
License: LGPL-2.1+

License: LGPL-2.1+
This package is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
.
You should have received a copy of the GNU Lesser General Public
License along with this package; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
X-Comment: on Debian systems, the complete text of the GNU Lesser General
Public License v2.1 can be found in `/usr/share/common-licenses/LGPL-2.1'.
Loading

0 comments on commit 879c6ab

Please sign in to comment.