Skip to content

Commit f552e9c

Browse files
committed
Support rpm and deb packaging
Add build_rpm.sh and build_deb.sh build scripts to produce rpm & deb package. closes scylladb/scylla-pkg#3714 closes #121 Signed-off-by: Takuya ASADA <[email protected]>
1 parent 35e2cae commit f552e9c

21 files changed

+728
-1
lines changed

README.md

+32-1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,37 @@ Now, use `--gtest_filter` to run certain integration tests:
318318

319319
##### 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.
320320

321+
# Build rpm package
322+
___
323+
324+
To build rpm package, run the following command:
325+
```shell
326+
./dist/redhat/build_rpm.sh --target rocky-8-x86_64
327+
```
328+
It will construct chrooted build environment of target distribution using mock,
329+
and build rpm in the environment.
330+
Target parameter should be mock .cfg file name.
331+
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.
332+
Build environment should be Fedora or RHEL variants + EPEL, since
333+
other distribution does not provide mock package.
334+
Built result will placed under build/redhat/{rpms,srpms}.
335+
336+
# Build deb package
337+
___
338+
339+
To build deb package, run the following command:
340+
```shell
341+
./dist/redhat/build_deb.sh --target mantic
342+
```
343+
It will construct chrooted build environment of target distribution using
344+
pbuilder, and build deb in the environment.
345+
Target parameter should be debian/ubuntu codename.
346+
On Ubuntu targets, currently tested on focal (20.04), jammy (22.04), mantic (23.10), noble (24.04).
347+
On Debian targets, currently tested on buster (10), bullseye (11), bookworm (12), trixie (13), sid (unstable).
348+
Build environment should be Fedora, Ubuntu or Debian, since these distribution
349+
provides pbuilder package.
350+
Built result will placed under build/debian/debs.
351+
321352
# Getting Help
322353
___
323354

@@ -338,4 +369,4 @@ ___
338369
# License
339370
___
340371

341-
This project is licensed under the GNU Lesser General Public License v2.1
372+
This project is licensed under the GNU Lesser General Public License v2.1

SCYLLA-VERSION-GEN

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash -e
2+
3+
USAGE="$(cat <<-END
4+
Usage: $(basename "$0") [-h|--help] [-o|--output-dir PATH] [--date-stamp DATE] -- generate Scylla version and build information files.
5+
6+
Options:
7+
-h|--help show this help message.
8+
-o|--output-dir PATH specify destination path at which the version files are to be created.
9+
-d|--date-stamp DATE manually set date for release parameter
10+
-v|--verbose also print out the version number
11+
12+
By default, the script will attempt to parse 'version' file
13+
in the current directory, which should contain a string of
14+
'\$version-\$release' form.
15+
16+
Otherwise, it will call 'git log' on the source tree (the
17+
directory, which contains the script) to obtain current
18+
commit hash and use it for building the version and release
19+
strings.
20+
21+
The script assumes that it's called from the Scylla source
22+
tree.
23+
24+
The files created are:
25+
SCYLLA-VERSION-FILE
26+
SCYLLA-RELEASE-FILE
27+
28+
By default, these files are created in the 'build'
29+
subdirectory under the directory containing the script.
30+
The destination directory can be overridden by
31+
using '-o PATH' option.
32+
END
33+
)"
34+
35+
DATE=""
36+
PRINT_VERSION=0
37+
38+
while [[ $# -gt 0 ]]; do
39+
opt="$1"
40+
case "${opt}" in
41+
-h|--help)
42+
echo "${USAGE}"
43+
exit 0
44+
;;
45+
-o|--output-dir)
46+
OUTPUT_DIR="$2"
47+
shift 2
48+
;;
49+
--date-stamp)
50+
DATE="$2"
51+
shift 2
52+
;;
53+
-v|--verbose)
54+
PRINT_VERSION=1
55+
shift 1
56+
;;
57+
*)
58+
echo "Unexpected argument found: $1"
59+
echo
60+
echo "${USAGE}"
61+
exit 1
62+
;;
63+
esac
64+
done
65+
66+
SCRIPT_DIR="$(dirname "$0")"
67+
68+
if [[ -z "${OUTPUT_DIR}" ]]; then
69+
OUTPUT_DIR="${SCRIPT_DIR}/build"
70+
fi
71+
72+
if [[ -z "${DATE}" ]]; then
73+
DATE="$(date --utc +%Y%m%d)"
74+
fi
75+
76+
# Default scylla version tags
77+
VERSION="$(sed -n -e 's/^version = \"\(.*\)\"$/\1/p' scylla-rust-wrapper/Cargo.toml)"
78+
79+
if [[ -f version ]]; then
80+
SCYLLA_VERSION="$(cat version | awk -F'-' '{print $1}')"
81+
SCYLLA_RELEASE="$(cat version | awk -F'-' '{print $2}')"
82+
else
83+
SCYLLA_VERSION="${VERSION}"
84+
if [[ -z "${SCYLLA_RELEASE}" ]]; then
85+
GIT_COMMIT="$(git -C "${SCRIPT_DIR}" log --pretty=format:'%h' -n 1 --abbrev=12)"
86+
# For custom package builds, replace "0" with "counter.your_name",
87+
# where counter starts at 1 and increments for successive versions.
88+
# This ensures that the package manager will select your custom
89+
# package over the standard release.
90+
SCYLLA_BUILD=0
91+
SCYLLA_RELEASE="${SCYLLA_BUILD}.${DATE}.${GIT_COMMIT}"
92+
elif [[ -f "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" ]]; then
93+
echo "setting SCYLLA_RELEASE only makes sense in clean builds" 1>&2
94+
exit 1
95+
fi
96+
fi
97+
98+
if [[ -f "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" ]]; then
99+
GIT_COMMIT_FILE=$(cat "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" |cut -d . -f 3)
100+
if [[ "${GIT_COMMIT}" = "${GIT_COMMIT_FILE}" ]]; then
101+
exit 0
102+
fi
103+
fi
104+
105+
if [[ ${PRINT_VERSION} -eq 1 ]]; then
106+
echo "${SCYLLA_VERSION}-${SCYLLA_RELEASE}"
107+
fi
108+
mkdir -p "${OUTPUT_DIR}"
109+
echo "${SCYLLA_VERSION}" > "${OUTPUT_DIR}/SCYLLA-VERSION-FILE"
110+
echo "${SCYLLA_RELEASE}" > "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@prefix@
2+
exec_prefix=@exec_prefix@
3+
libdir=@libdir@
4+
includedir=@includedir@
5+
6+
Name: scylla-cpp-rust-driver
7+
Description: ScyllaDB Cpp-Rust Driver
8+
Version: @version@
9+
Libs: -L${libdir} -lscylla_cpp_driver
10+
Cflags: -I${includedir}/scylladb
11+
URL: https://github.com/scylladb/cpp-rust-driver
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
prefix=@prefix@
2+
exec_prefix=@exec_prefix@
3+
libdir=@libdir@
4+
includedir=@includedir@
5+
6+
Name: scylla-cpp-rust-driver
7+
Description: ScyllaDB Cpp-Rust Driver
8+
Version: @version@
9+
Requires: openssl
10+
Libs: -L${libdir} -llibscylla_cpp_driver.a
11+
Cflags: -I${includedir}/scylladb
12+
URL: https://github.com/scylladb/cpp-rust-driver

dist/debian/build_deb.sh

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/bash -e
2+
3+
CURDIR="$(dirname "$(readlink -f "$0")")"
4+
BASEDIR="$(readlink -f "${CURDIR}"/../../)"
5+
. /etc/os-release
6+
print_usage() {
7+
echo "build_deb.sh --jobs 2 --target jammy"
8+
echo " --target target distribution codename"
9+
echo " --no-clean don't rebuild pbuilder tgz"
10+
echo " --jobs specify number of jobs"
11+
exit 1
12+
}
13+
14+
TARGET=
15+
NO_CLEAN=0
16+
JOBS="$(nproc)"
17+
while [ $# -gt 0 ]; do
18+
case "$1" in
19+
"--target")
20+
TARGET=$2
21+
shift 2
22+
;;
23+
"--no-clean")
24+
NO_CLEAN=1
25+
shift 1
26+
;;
27+
"--jobs")
28+
JOBS=$2
29+
shift 2
30+
;;
31+
*)
32+
print_usage
33+
;;
34+
esac
35+
done
36+
37+
is_redhat_variant() {
38+
[[ -f /etc/redhat-release ]]
39+
}
40+
is_debian_variant() {
41+
[[ -f /etc/debian_version ]]
42+
}
43+
is_debian() {
44+
case "$1" in
45+
buster|bullseye|bookworm|trixie|sid) return 0;;
46+
*) return 1;;
47+
esac
48+
}
49+
is_ubuntu() {
50+
case "$1" in
51+
bionic|focal|jammy|mantic|noble) return 0;;
52+
*) return 1;;
53+
esac
54+
}
55+
56+
57+
APT_UPDATED=0
58+
declare -A DEB_PKG=(
59+
["debian-keyring"]="debian-archive-keyring"
60+
["ubu-keyring"]="ubuntu-keyring"
61+
)
62+
pkg_install() {
63+
if is_redhat_variant; then
64+
sudo yum install -y "$1"
65+
elif is_debian_variant; then
66+
if [[ "${APT_UPDATED}" -eq 0 ]]; then
67+
sudo apt-get -y update
68+
APT_UPDATED=1
69+
fi
70+
if [[ -n "${DEB_PKG[$1]}" ]]; then
71+
pkg="${DEB_PKG[$1]}"
72+
else
73+
pkg="$1"
74+
fi
75+
sudo apt-get install -y "$pkg"
76+
else
77+
echo "Requires to install following command: $1"
78+
exit 1
79+
fi
80+
}
81+
82+
if [[ ! -e dist/debian/build_deb.sh ]]; then
83+
echo "run build_deb.sh in top of scylla dir"
84+
exit 1
85+
fi
86+
87+
if [[ -z "${TARGET}" ]]; then
88+
echo "Please specify target"
89+
exit 1
90+
fi
91+
92+
if [[ ! -f /usr/bin/git ]]; then
93+
pkg_install git
94+
fi
95+
if [[ ! -f /usr/sbin/pbuilder ]]; then
96+
pkg_install pbuilder
97+
fi
98+
if [[ ! -f /usr/bin/dh_testdir ]]; then
99+
pkg_install debhelper
100+
fi
101+
if is_debian "${TARGET}" && [[ ! -f /usr/share/keyrings/debian-archive-keyring.gpg ]]; then
102+
pkg_install debian-keyring
103+
fi
104+
if is_ubuntu "${TARGET}" && [[ ! -f /usr/share/keyrings/ubuntu-archive-keyring.gpg ]]; then
105+
pkg_install ubu-keyring
106+
fi
107+
108+
./SCYLLA-VERSION-GEN
109+
DRIVER_NAME=scylla-cpp-rust-driver
110+
DRIVER_VERSION="$(sed 's/-/~/' build/SCYLLA-VERSION-FILE)"
111+
DRIVER_RELEASE="$(cat build/SCYLLA-RELEASE-FILE)"
112+
ARCH="$(dpkg --print-architecture)"
113+
114+
mkdir -p build/debian/debs
115+
git archive HEAD --prefix "${DRIVER_NAME}-${DRIVER_VERSION}/" --output "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar"
116+
echo "$(cat build/SCYLLA-VERSION-FILE)-$(cat build/SCYLLA-RELEASE-FILE)" > version
117+
tar --xform "s#^#${DRIVER_NAME}-${DRIVER_VERSION}/#" -rf "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar" version
118+
gzip -f --fast "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar"
119+
120+
if is_debian "${TARGET}"; then
121+
DRIVER_REVISION="1~${TARGET}"
122+
elif is_ubuntu "${TARGET}"; then
123+
DRIVER_REVISION="0ubuntu1~${TARGET}"
124+
else
125+
echo "Unknown distribution: ${TARGET}"
126+
fi
127+
tar xpvf "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar.gz" -C build/debian
128+
129+
./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
130+
131+
# pbuilder generates files owned by root, fix this up
132+
fix_ownership() {
133+
CURRENT_UID="$(id -u)"
134+
CURRENT_GID="$(id -g)"
135+
sudo chown "${CURRENT_UID}":"${CURRENT_GID}" -R "$@"
136+
}
137+
138+
BASETGZ="/var/cache/pbuilder/${DRIVER_NAME}-${TARGET}-${ARCH}-base.tgz"
139+
# use from pbuilderrc
140+
if [[ "${NO_CLEAN}" -eq 0 ]]; then
141+
sudo rm -fv "/var/cache/pbuilder/${DRIVER_NAME}-${TARGET}-${ARCH}-base.tgz"
142+
sudo mkdir -p "/var/cache/pbuilder/${DRIVER_NAME}-${TARGET}-${ARCH}/aptcache"
143+
sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder clean --configfile ./dist/debian/pbuilderrc
144+
sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder create --configfile ./dist/debian/pbuilderrc
145+
fi
146+
sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder update --configfile ./dist/debian/pbuilderrc
147+
(cd "build/debian/${DRIVER_NAME}"-"${DRIVER_VERSION}"; dpkg-source -b .)
148+
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"
149+
fix_ownership build/debian/debs

dist/debian/changelog.template

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scylla-cpp-rust-driver (%{version}-%{release}-%{revision}) %{codename}; urgency=medium
2+
3+
* Initial release.
4+
5+
-- Takuya ASADA <[email protected]> Wed, 1 May 2024 11:02:04 +0000

dist/debian/debian/control

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Source: scylla-cpp-rust-driver
2+
Maintainer: Takuya ASADA <[email protected]>
3+
Homepage: https://github.com/scylladb/cpp-rust-driver
4+
Section: libs
5+
Priority: optional
6+
Standards-Version: 4.6.0
7+
Build-Depends: debhelper-compat (= 11),
8+
libssl-dev,
9+
libclang-dev,
10+
pkg-config,
11+
openssl,
12+
ca-certificates,
13+
curl,
14+
clang,
15+
patchelf
16+
17+
Package: libscylla-cpp-driver0
18+
Architecture: any
19+
Depends: ${misc:Depends},
20+
${shlibs:Depends},
21+
Description: ScyllaDB Cpp-Rust Driver
22+
API-compatible rewrite of https://github.com/scylladb/cpp-driver as a wrapper for Rust driver.
23+
24+
Package: libscylla-cpp-driver-dev
25+
Section: libdevel
26+
Architecture: any
27+
Depends: libscylla-cpp-driver0 (= ${binary:Version}),
28+
${misc:Depends},
29+
Description: Development libraries for ScyllaDB Cpp-Rust Driver
30+
API-compatible rewrite of https://github.com/scylladb/cpp-driver as a wrapper for Rust driver.

dist/debian/debian/copyright

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: Scylla DB
3+
Upstream-Contact: http://www.scylladb.com/
4+
Source: https://github.com/scylladb/cpp-rust-driver
5+
6+
Files: *
7+
Copyright: Copyright (C) 2024 ScyllaDB
8+
License: LGPL-2.1+
9+
10+
License: LGPL-2.1+
11+
This package is free software; you can redistribute it and/or
12+
modify it under the terms of the GNU Lesser General Public
13+
License as published by the Free Software Foundation; either
14+
version 2.1 of the License, or (at your option) any later version.
15+
.
16+
This package is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
Lesser General Public License for more details.
20+
.
21+
You should have received a copy of the GNU Lesser General Public
22+
License along with this package; if not, write to the Free Software
23+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24+
X-Comment: on Debian systems, the complete text of the GNU Lesser General
25+
Public License v2.1 can be found in `/usr/share/common-licenses/LGPL-2.1'.

dist/debian/debian/debcargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
overlay = "."
2+
uploaders = ["Takuya ASADA <[email protected]>"]
3+
4+
[source]
5+
section = "libs"

0 commit comments

Comments
 (0)