dist/redhat: use relocatable package to produce .rpm

This commit is contained in:
Takuya ASADA 2018-10-24 02:04:47 +00:00
parent 92847e3381
commit 5edfedf642
3 changed files with 58 additions and 47 deletions

View File

@ -4,15 +4,15 @@ PRODUCT=scylla
. /etc/os-release . /etc/os-release
print_usage() { print_usage() {
echo "build_rpm.sh -target epel-7-x86_64 --configure-user" echo "build_rpm.sh --reloc-pkg build/scylla-jmx-package.tar.gz"
echo " --target target distribution in mock cfg name" echo " --target target distribution in mock cfg name"
exit 1 exit 1
} }
TARGET= RELOC_PKG=
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
"--target") "--reloc-pkg")
TARGET=$2 RELOC_PKG=$2
shift 2 shift 2
;; ;;
*) *)
@ -33,34 +33,20 @@ pkg_install() {
fi fi
} }
if [ ! -e SCYLLA-RELOCATABLE-FILE ]; then
if [ ! -e dist/redhat/build_rpm.sh ]; then echo "do not directly execute build_rpm.sh, use reloc/build_rpm.sh instead."
echo "run build_rpm.sh in top of scylla-jmx dir"
exit 1 exit 1
fi fi
if [ "$(arch)" != "x86_64" ]; then if [ -z "$RELOC_PKG" ]; then
echo "Unsupported architecture: $(arch)" print_usage
exit 1 exit 1
fi fi
if [ -z "$TARGET" ]; then if [ ! -f "$RELOC_PKG" ]; then
if [ "$ID" = "centos" -o "$ID" = "rhel" ] && [ "$VERSION_ID" = "7" ]; then echo "$RELOC_PKG is not found."
TARGET=./dist/redhat/mock/scylla-jmx-epel-7-x86_64.cfg exit 1
elif [ "$ID" = "fedora" ]; then
TARGET=$ID-$VERSION_ID-x86_64
else
echo "Please specify target"
exit 1
fi
fi fi
if [[ "$TARGET" = epel-7-x86_64 ]]; then
TARGET=./dist/redhat/mock/scylla-jmx-epel-7-x86_64.cfg
fi
if [ ! -f /usr/bin/mock ]; then
pkg_install mock
fi
if [ ! -f /usr/bin/git ]; then if [ ! -f /usr/bin/git ]; then
pkg_install git pkg_install git
fi fi
@ -72,18 +58,15 @@ if [ ! -f /usr/bin/pystache ]; then
fi fi
fi fi
VERSION=$(./SCYLLA-VERSION-GEN) SCYLLA_VERSION=$(cat SCYLLA-VERSION-FILE)
SCYLLA_VERSION=$(cat build/SCYLLA-VERSION-FILE) SCYLLA_RELEASE=$(cat SCYLLA-RELEASE-FILE)
SCYLLA_RELEASE=$(cat build/SCYLLA-RELEASE-FILE) VERSION=$SCYLLA_VERSION-$SCYLLA_RELEASE
git archive --format=tar --prefix=$PRODUCT-jmx-$SCYLLA_VERSION/ HEAD -o build/$PRODUCT-jmx-$VERSION.tar
pystache dist/redhat/scylla-jmx.spec.mustache "{ \"version\": \"$SCYLLA_VERSION\", \"release\": \"$SCYLLA_RELEASE\", \"product\": \"$PRODUCT\", \"$PRODUCT\": true }" > build/scylla-jmx.spec
# mock generates files owned by root, fix this up RPMBUILD=$(readlink -f ../)
fix_ownership() { mkdir -p $RPMBUILD/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
sudo chown "$(id -u):$(id -g)" -R "$@"
}
sudo mock --buildsrpm --root=$TARGET --resultdir=`pwd`/build/srpms --spec=build/scylla-jmx.spec --sources=build/$PRODUCT-jmx-$VERSION.tar ln -fv $RELOC_PKG $RPMBUILD/SOURCES/
fix_ownership build/srpms pystache dist/redhat/scylla-jmx.spec.mustache "{ \"version\": \"$SCYLLA_VERSION\", \"release\": \"$SCYLLA_RELEASE\", \"product\": \"$PRODUCT\", \"$PRODUCT\": true }" > $RPMBUILD/SPECS/scylla-jmx.spec
sudo mock --rebuild --root=$TARGET --resultdir=`pwd`/build/rpms build/srpms/$PRODUCT-jmx-$VERSION*.src.rpm
fix_ownership build/rpms # this rpm can be install on both fedora / centos7, so drop distribution name from the file name
rpmbuild -ba --define "_topdir $RPMBUILD" --undefine "dist" $RPM_JOBS_OPTS $RPMBUILD/SPECS/scylla-jmx.spec

View File

@ -6,10 +6,10 @@ Group: Applications/Databases
License: AGPLv3 License: AGPLv3
URL: http://www.scylladb.com/ URL: http://www.scylladb.com/
Source0: %{name}-{{version}}-{{release}}.tar Source0: scylla-jmx-package.tar.gz
BuildArch: noarch BuildArch: noarch
BuildRequires: maven systemd-units java-1.8.0-openjdk-devel BuildRequires: systemd-units
%{?fedora:BuildRequires: python2-pystache} %{?fedora:BuildRequires: python2-pystache}
%{?rhel:BuildRequires: pystache python-setuptools} %{?rhel:BuildRequires: pystache python-setuptools}
Requires: {{product}}-server java-1.8.0-openjdk-headless Requires: {{product}}-server java-1.8.0-openjdk-headless
@ -18,14 +18,12 @@ Requires: {{product}}-server java-1.8.0-openjdk-headless
%prep %prep
%setup -q %setup -c
%build %build
mvn -B install
mkdir build
MUSTACHE_DIST="\"redhat\": true" MUSTACHE_DIST="\"redhat\": true"
pystache dist/common/systemd/scylla-jmx.service.mustache "{ $MUSTACHE_DIST }" > build/scylla-jmx.service pystache dist/common/systemd/scylla-jmx.service.mustache "{ $MUSTACHE_DIST }" > scylla-jmx.service
%install %install
rm -rf $RPM_BUILD_ROOT rm -rf $RPM_BUILD_ROOT
@ -34,12 +32,12 @@ mkdir -p $RPM_BUILD_ROOT%{_unitdir}
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/scylla/ mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/scylla/
install -m644 dist/common/sysconfig/scylla-jmx $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ install -m644 dist/common/sysconfig/scylla-jmx $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/
install -m644 build/*.service $RPM_BUILD_ROOT%{_unitdir}/ install -m644 scylla-jmx.service $RPM_BUILD_ROOT%{_unitdir}/
install -d -m755 $RPM_BUILD_ROOT%{_prefix}/lib/scylla install -d -m755 $RPM_BUILD_ROOT%{_prefix}/lib/scylla
install -d -m755 $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx install -d -m755 $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx
install -d -m755 $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx/symlinks install -d -m755 $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx/symlinks
install -m644 target/scylla-jmx-1.0.jar $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx/ install -m644 scylla-jmx-1.0.jar $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx/
install -m755 scripts/scylla-jmx $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx install -m755 scylla-jmx $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx
ln -sf /usr/bin/java $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx/symlinks/scylla-jmx ln -sf /usr/bin/java $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx/symlinks/scylla-jmx
%pre %pre

30
reloc/build_rpm.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash -e
. /etc/os-release
print_usage() {
echo "build_rpm.sh --reloc-pkg build/scylla-jmx-package.tar.gz"
echo " --reloc-pkg specify relocatable package path"
exit 1
}
RELOC_PKG=$(readlink -f build/scylla-jmx-package.tar.gz)
OPTS=""
while [ $# -gt 0 ]; do
case "$1" in
"--reloc-pkg")
OPTS="$OPTS $1 $(readlink -f $2)"
RELOC_PKG=$2
shift 2
;;
*)
print_usage
;;
esac
done
if [[ ! $OPTS =~ --reloc-pkg ]]; then
OPTS="$OPTS --reloc-pkg $RELOC_PKG"
fi
mkdir -p build/redhat/scylla-package
tar -C build/redhat/scylla-package -xpf $RELOC_PKG SCYLLA-RELEASE-FILE SCYLLA-RELOCATABLE-FILE SCYLLA-VERSION-FILE dist/redhat
cd build/redhat/scylla-package
exec ./dist/redhat/build_rpm.sh $OPTS