diff --git a/packages/copr.fedorainfracloud.org/cgrates.spec b/packages/copr.fedorainfracloud.org/cgrates.spec index dd7335903..d785b797a 100644 --- a/packages/copr.fedorainfracloud.org/cgrates.spec +++ b/packages/copr.fedorainfracloud.org/cgrates.spec @@ -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 diff --git a/packages/copr.fedorainfracloud.org/rpkg.macros b/packages/copr.fedorainfracloud.org/rpkg.macros deleted file mode 100644 index 0978bf90a..000000000 --- a/packages/copr.fedorainfracloud.org/rpkg.macros +++ /dev/null @@ -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 -} diff --git a/packages/redhat_fedora/cgrates.spec b/packages/redhat_fedora/cgrates.spec index c20a5b25b..b3be3d8d7 100644 --- a/packages/redhat_fedora/cgrates.spec +++ b/packages/redhat_fedora/cgrates.spec @@ -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 diff --git a/packages/redhat_fedora/generate-package.sh b/packages/redhat_fedora/generate-package.sh new file mode 100755 index 000000000..57d98c36e --- /dev/null +++ b/packages/redhat_fedora/generate-package.sh @@ -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 "$@" \ No newline at end of file diff --git a/packit.yaml b/packit.yaml index 6b7943098..3018bccc6 100644 --- a/packit.yaml +++ b/packit.yaml @@ -16,6 +16,8 @@ jobs: - epel-9-x86_64 actions: + create-archive: + - bash -c "git_last_commit=$(git rev-parse HEAD) && tar -czvf /tmp/${git_last_commit}.tar.gz . && echo /tmp/${git_last_commit}.tar.gz" fix-spec-file: - bash -c "git_last_commit=$(git rev-parse HEAD) && sed -i 's|{{{git_commit}}}|'\"${git_last_commit}\"'|' packages/copr.fedorainfracloud.org/cgrates.spec" - bash -c "release_tag=$(git log -1 --format=%ci | date +%Y%m%d%H%M%S)+$(git rev-parse --short HEAD) && sed -i 's|{{{releaseTag}}}|'\"${release_tag}\"'|' packages/copr.fedorainfracloud.org/cgrates.spec" diff --git a/rpkg.conf b/rpkg.conf deleted file mode 100644 index 1e3ff7c7b..000000000 --- a/rpkg.conf +++ /dev/null @@ -1,2 +0,0 @@ -[rpkg] -user_macros = "${git_props:root}/packages/copr.fedorainfracloud.org/rpkg.macros"