Added script for local rpm builds

This commit is contained in:
gezimbll
2023-06-30 12:46:13 +02:00
committed by Dan Christian Bogos
parent 01d3c5d0fa
commit b838469bb5
6 changed files with 101 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
%global version 0.11.0~dev
%global go_version 1.20.5
%define debug_package %{nil}
%global _logdir /var/log/%name
@@ -12,10 +13,8 @@ Summary: Carrier Grade Real-time Charging System
License: GPLv3
URL: https://github.com/cgrates/cgrates
Source0: https://github.com/cgrates/cgrates/archive/{{{git_commit}}}.tar.gz
BuildRequires:git
BuildRequires:golang
%if 0%{?fedora} > 16 || 0%{?rhel} > 6
Requires(pre): shadow-utils
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
@@ -24,9 +23,11 @@ Requires(post): chkconfig
Requires(preun):chkconfig
Requires(preun):initscripts
%endif
%if 0%{?rhel}>7
BuildRequires: systemd-rpm-macros
%endif
Requires(pre): shadow-utils
BuildRequires:git curl tar
%{?systemd_requires}
BuildRequires: systemd-rpm-macros
%description
CGRateS is a very fast and easy scalable real-time charging system for Telecom environments.
@@ -35,6 +36,8 @@ CGRateS is a very fast and easy scalable real-time charging system for Telecom e
%setup -q -n %{name}-%{version} -c
mkdir -p src/github.com/cgrates
ln -sf ../../../$(ls |grep %{name}-) src/github.com/cgrates/cgrates
curl -LO https://golang.org/dl/go%{go_version}.linux-amd64.tar.gz
tar -xzf go%{go_version}.linux-amd64.tar.gz -C %{_builddir}
%pre
getent group %{name} >/dev/null || groupadd -r %{name}
@@ -71,8 +74,9 @@ fi
%endif
%build
export GOPATH=$RPM_BUILD_DIR/%{name}-%{version}
export GOPATH=$RPM_BUILD_DIR/%{name}-%{version}/go
cd $RPM_BUILD_DIR/%{name}-%{version}/src/github.com/cgrates/cgrates
export PATH=$PATH:%{_builddir}/go/bin
./build.sh
%install
@@ -89,11 +93,11 @@ cp -rpf src/github.com/cgrates/cgrates/data/storage/mongo $RPM_BUILD_ROOT%{_data
cp -rpf src/github.com/cgrates/cgrates/data/storage/mysql $RPM_BUILD_ROOT%{_datarootdir}/%{name}/storage
cp -rpf src/github.com/cgrates/cgrates/data/storage/postgres $RPM_BUILD_ROOT%{_datarootdir}/%{name}/storage
install -D -m 0644 -p src/github.com/cgrates/cgrates/data/conf/%{name}/%{name}.json $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/%{name}.json
install -D -m 0755 -p bin/cgr-console $RPM_BUILD_ROOT%{_bindir}/cgr-console
install -D -m 0755 -p bin/cgr-engine $RPM_BUILD_ROOT%{_bindir}/cgr-engine
install -D -m 0755 -p bin/cgr-loader $RPM_BUILD_ROOT%{_bindir}/cgr-loader
install -D -m 0755 -p bin/cgr-tester $RPM_BUILD_ROOT%{_bindir}/cgr-tester
install -D -m 0755 -p bin/cgr-migrator $RPM_BUILD_ROOT%{_bindir}/cgr-migrator
install -D -m 0755 -p go/bin/cgr-console $RPM_BUILD_ROOT%{_bindir}/cgr-console
install -D -m 0755 -p go/bin/cgr-engine $RPM_BUILD_ROOT%{_bindir}/cgr-engine
install -D -m 0755 -p go/bin/cgr-loader $RPM_BUILD_ROOT%{_bindir}/cgr-loader
install -D -m 0755 -p go/bin/cgr-tester $RPM_BUILD_ROOT%{_bindir}/cgr-tester
install -D -m 0755 -p go/bin/cgr-migrator $RPM_BUILD_ROOT%{_bindir}/cgr-migrator
mkdir -p $RPM_BUILD_ROOT%{_logdir}/cdre/csv
mkdir -p $RPM_BUILD_ROOT%{_logdir}/cdre/fwv
mkdir -p $RPM_BUILD_ROOT%{_spooldir}/cdre/csv

View File

@@ -1,9 +0,0 @@
function releaseTag {
rpmTag=$(git log -1 --format=%ci | date +%Y%m%d%H%M%S)+$(git rev-parse --short HEAD)
echo $rpmTag
}
function git_commit {
gitLastCommit=$(git rev-parse HEAD)
echo $gitLastCommit
}

View File

@@ -1,4 +1,5 @@
%global version 0.11.0~dev
%global go_version 1.20.5
%global git_commit %(echo $gitLastCommit)
%global releaseTag %(echo $rpmTag)
@@ -13,10 +14,9 @@ Release: %{releaseTag}
Summary: Carrier Grade Real-time Charging System
License: GPLv3
URL: https://github.com/cgrates/cgrates
Source0: https://github.com/cgrates/cgrates/archive/%{git_commit}.tar.gz
Source0: %{git_commit}.tar.gz
%if 0%{?fedora} > 16 || 0%{?rhel} > 6
Requires(pre): shadow-utils
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
@@ -26,13 +26,20 @@ Requires(preun):chkconfig
Requires(preun):initscripts
%endif
Requires(pre): shadow-utils
BuildRequires:git curl tar
%{?systemd_requires}
BuildRequires: systemd-rpm-macros
%description
CGRateS is a very fast and easy scalable real-time charging system for Telecom environments.
%prep
%setup -q -n %{name}-%{version} -c
mkdir -p src/github.com/cgrates
ln -sf ../../../$(ls |grep %{name}-) src/github.com/cgrates/cgrates
ln -sf ../../../$(ls |grep %{name}) src/github.com/cgrates/cgrates
curl -LO https://golang.org/dl/go%{go_version}.linux-amd64.tar.gz
tar -xzf go%{go_version}.linux-amd64.tar.gz -C %{_builddir}
%pre
getent group %{name} >/dev/null || groupadd -r %{name}
@@ -71,6 +78,7 @@ fi
%build
export GOPATH=$RPM_BUILD_DIR/%{name}-%{version}
cd $RPM_BUILD_DIR/%{name}-%{version}/src/github.com/cgrates/cgrates
export PATH=$PATH:%{_builddir}/go/bin
./build.sh
%install

View File

@@ -0,0 +1,72 @@
#!/bin/bash
set -e
# Default values
BUILD_DIR_DEFAULT=$HOME/rpmbuild
SRCDIR_DEFAULT=$HOME/go/src/github.com/cgrates/cgrates
# Parse options
while (( "$#" )); do
case "$1" in
--build-dir)
BUILD_DIR=$2
shift 2
;;
--srcdir)
SRCDIR=$2
shift 2
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
# set positional arguments in their proper place
eval set -- "$PARAMS"
# Assign defaults if variables are not set
BUILD_DIR=${BUILD_DIR:-$BUILD_DIR_DEFAULT}
SRCDIR=${SRCDIR:-$SRCDIR_DEFAULT}
prepare_environment() {
echo "Making sure dependencies are installed..."
sudo dnf install -y rpm-build wget curl tar
echo "Creating build directories in $BUILD_DIR..."
mkdir -p $BUILD_DIR/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
}
fetch_source() {
echo "Fetching source code..."
cd $SRCDIR
export gitLastCommit=$(git rev-parse HEAD)
export rpmTag=$(git log -1 --format=%ci | date +%Y%m%d%H%M%S)+$(git rev-parse --short HEAD)
if [ ! -f $BUILD_DIR/SOURCES/$gitLastCommit.tar.gz ]; then
cd $SRCDIR_DEFAULT && cd ..
tar -czvf $BUILD_DIR/SOURCES/$gitLastCommit.tar.gz cgrates
fi
}
copy_spec_file() {
echo "Copying RPM spec file..."
cp $SRCDIR/packages/redhat_fedora/cgrates.spec $BUILD_DIR/SPECS
}
build_package() {
echo "Building RPM package..."
cd $BUILD_DIR
rpmbuild -bb --define "_topdir $BUILD_DIR" SPECS/cgrates.spec
}
main() {
prepare_environment
fetch_source
copy_spec_file
build_package
}
main "$@"