#!/bin/bash
set -uex
# Run from: docker run -it --name rocky-rpm-builder -v ~/workspace/devops/packaging:/root/rpmbuild rockylinux:8 /bin/bash
# sudo docker rm rocky-rpm-builder
setup_rpm_build_env() {
el_version=${1:-8} # default to '8'
# Update and install required packages
dnf install -y \
git \
rpm-build \
rpmdevtools \
dnf-plugins-core \
gcc \
gcc-c++ \
make \
cmake \
python3 \
python3-pip \
openssl-devel \
libuuid-devel \
epel-release
# Install build tools and dependencies
dnf groupinstall -y "Development Tools"
dnf install -y mock epel-release
# enable Power Tools or CodeReady Builder depending on el version
if [[ "$el_version" == "8" ]]; then
dnf config-manager --set-enabled powertools
elif [[ "$el_version" == "9" ]]; then
dnf config-manager --set-enabled crb # CodeReady Builder
else
echo "Unsupported EL Version: $el_version"
exit 1
fi
# ignore dpdk because want to use rpms build from daos-stack/dpdk
dnf update -y --exclude=dpdk --exclude=dpdk-devel
}
# Function to clone, build, and install RPMs with packaging repos inside daos-stack
build_and_install_rpm() {
local repo_name=$1
local rpm_build_options=${2:-""}
# Check if the directory exists - helps if running script many times while troubleshooting
if [ ! -d "$repo_name" ]; then
git clone https://github.com/daos-stack/$repo_name.git
cd $repo_name
dnf builddep -y $repo_name.spec
make rpms RPM_BUILD_OPTIONS="$rpm_build_options"
dnf install -y _topdir/RPMS/*/*.rpm
cp -r _topdir/RPMS/* $rpms_dst/
cd -
else
echo "The '$repo_name' folder already exists. Skipping clone and build steps."
fi
}
get_el_version() {
VERSION_ID=$(grep "^VERSION_ID" /etc/os-release | cut -d'=' -f2 | tr -d '"' | cut -d'.' -f1)
echo $VERSION_ID
}
# ---- #
# MAIN #
# ---- #
rpms_dst=${1:-"~$HOME/rpmbuild/"}
build_dst="/tmp/rpmbuild/" # temp location to do the building
echo "Building RPMs for EL $(get_el_version)."
echo "RPMS will be located in $rpms_dst (built in $build_dst)"
# make sure rpm and build folders are created
mkdir -p $rpms_dst
mkdir -p $build_dst
# ------------------------------
# Build Dependency and DAOS RPMS
# ------------------------------
setup_rpm_build_env $(get_el_version)
cd $build_dst
# Call the function with the repository name as an argument
build_and_install_rpm "isa-l_crypto"
build_and_install_rpm "argobots"
build_and_install_rpm "mercury"
build_and_install_rpm "mercury"
build_and_install_rpm "dpdk" # dependency of spdk.
build_and_install_rpm "spdk"
build_and_install_rpm "pmdk" "--define '_skip_check 1'"
# DAOS and Raft (Submodule)
if [ ! -d "daos" ]; then
git clone --recursive https://github.com/daos-stack/daos.git
# RAFT
cd daos/src/rdb/raft
dnf builddep -y raft.spec
make -f Makefile-rpm.mk
dnf install -y _topdir/RPMS/*/*.rpm
cp -r _topdir/RPMS/* $rpms_dst/
cd -
# DAOS
cd daos
dnf builddep -y ./utils/rpms/daos.spec
make -C utils/rpms rpms
cp -r utils/rpms/_topdir/RPMS/* $rpms_dst/
cd -
fi
# --------
# Clean up
# --------
rm -rf $build_dst
|