Skip to content

Commit

Permalink
PMM-13487 Refactor and clean up build-client-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Nov 16, 2024
1 parent e82ec43 commit 4f490a0
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 146 deletions.
2 changes: 1 addition & 1 deletion build/packages/deb/control
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Breaks: pmm-client
Conflicts: pmm2-client
Replaces: pmm2-client
Description: Percona Monitoring and Management Client
Percona Monitoring and Management (PMM) is an open-source platform for managing and monitoring MySQL and MongoDB
Percona Monitoring and Management (PMM) is an open-source platform for managing and monitoring MySQL, PostgreSQL and MongoDB
performance. It is developed by Percona in collaboration with experts in the field of managed database services,
support and consulting.
PMM is a free and open-source solution that you can run in your own environment for maximum security and reliability.
Expand Down
200 changes: 74 additions & 126 deletions build/scripts/build-client-packages
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# NOTE: this script is always executed in a container environment.
# NOTE: this script must be executed in a container environment.

set -o errexit
set -o xtrace
Expand All @@ -8,9 +8,9 @@ usage () {
cat <<EOF
Usage: $0 [OPTIONS]
The following options may be given :
--build_src_rpm Build RPM packages
--build_source_deb Build debian source packages
--build_src_rpm Build source RPM packages
--build_rpm Build RPM packages
--build_source_deb Build debian source packages
--build_deb Build debian packages
--help) Display this help
Example $0 --build_src_rpm --build_rpm
Expand All @@ -19,13 +19,25 @@ EOF
exit 1
}

parse_arguments() {
run() {
for arg do
case "$arg" in
--build_src_rpm) SRPM=1 ;;
--build_rpm) RPM=1 ;;
--build_source_deb=*) SDEB=1 ;;
--build_deb) DEB=1 ;;
--build_src_rpm)
echo "Building srpm packages..."
build_srpm
;;
--build_rpm)
echo "Building rpm packages..."
build_rpm
;;
--build_source_deb=*)
echo "Building source deb packages..."
build_source_deb
;;
--build_deb)
echo "Building deb packages..."
build_deb
;;
--help) usage ;;
*) usage ;;
esac
Expand All @@ -43,73 +55,45 @@ check_workdir(){
fi
}

get_system(){
if [ -f /etc/redhat-release ]; then
RHEL=$(rpm --eval %rhel)
ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g')
OS_NAME="el$RHEL"
OS="rpm"
else
ARCH=$(uname -m)
OS_NAME="$(lsb_release -sc)"
OS="deb"
fi
}

# Find the tarball and copy it to WORKDIR
get_tar(){
local TARBALL=$1
local TARFILE=$(basename $(find $CURDIR/$TARBALL -name "${PACKAGE_NAME}*.tar.gz" | sort | tail -n1) || :)
if [ -n $TARFILE ]; then
cp $CURDIR/$TARBALL/$TARFILE $WORKDIR/$TARFILE
return
local TARBALL_DIR=$1
local TARFILE=$(basename $(find "$CURDIR/$TARBALL_DIR" -name "${PACKAGE_NAME}*.tar.gz" | sort | tail -n1))
if [ ! -f "$CURDIR/$TARBALL_DIR/$TARFILE" ]; then
echo "Error: $TARBALL_DIR could not be found, exiting..."
exit 1
fi

echo "Error: $TARBALL could not be found, exiting..."
exit 1
cp "$CURDIR/$TARBALL_DIR/$TARFILE" "$WORKDIR/$TARFILE"
echo "$TARFILE"
}

get_deb_sources(){
local param=$1
echo $param
local FILE=$(basename $(find $WORKDIR/source_deb -name "${PACKAGE_NAME}*.$param" | sort | tail -n1) || :)
if [ -z $FILE ]; then
FILE=$(basename $(find $CURDIR/source_deb -name "${PACKAGE_NAME}*.$param" | sort | tail -n1) || :)
if [ -z $FILE ]; then
echo "There is no sources for build"
exit 1
else
cp $CURDIR/source_deb/$FILE $WORKDIR/
fi
else
cp $WORKDIR/source_deb/$FILE $WORKDIR/
fi
return
}

build_srpm(){
if [ "$OS" = "deb" ]; then
echo "Error: it is not possible to build source RPM on a debian based OS, exiting..."
local param=$1
local FILE=$(basename $(find $CURDIR/source_deb -name "${PACKAGE_NAME}*.$param" | sort | tail -n1))
if [ -z $FILE ]; then
echo "There is no source to build from"
exit 1
else
cp $CURDIR/source_deb/$FILE $WORKDIR/
fi
cd $WORKDIR
get_tar "tarball"

rm -fr rpmbuild
ls | grep -v tar.gz | xargs rm -rf
}

local TARFILE=$(basename $(find . -name "${PACKAGE_NAME}-*.tar.gz" | sort | tail -n1))
build_srpm(){
local TARFILE=$(get_tar "tarball")
# local TARFILE=$(basename $(find . -name "${PACKAGE_NAME}-*.tar.gz" | sort | tail -n1))
local NAME=$(echo ${TARFILE}| awk -F '-' '{print $1"-"$2}')
local VERSION_TMP=$(echo ${TARFILE}| awk -F '-' '{print $3}')
local VERSION=${VERSION_TMP%.tar.gz}

cd $WORKDIR
mkdir -vp rpmbuild/{SOURCES,SPECS,BUILD,SRPMS,RPMS}

tar -C ${WORKDIR} -zxpf ${TARFILE} ${NAME}-${VERSION}/rpm

cd ${WORKDIR}/rpmbuild/SPECS
cp ${WORKDIR}/${NAME}-${VERSION}/rpm/*.spec .
cp ${WORKDIR}/${NAME}-${VERSION}/rpm/*.spec ${WORKDIR}/rpmbuild/SPECS/
cp ${WORKDIR}/${TARFILE} ../SOURCES/
cd ${WORKDIR}

rpmbuild -bs \
--define "_topdir ${WORKDIR}/rpmbuild" \
--define "version $VERSION" \
Expand All @@ -122,15 +106,11 @@ build_srpm(){
}

build_rpm(){
if [ "$OS" = "deb" ]; then
echo "It is not possible to build rpm here"
exit 1
fi

local SRC_RPM=$(basename $(find $CURDIR/srpm -name "${PACKAGE_NAME}*.src.rpm" | sort | tail -n1) || :)
local RHEL=$(rpm --eval %rhel)
if [ -z "$SRC_RPM" ]; then
echo "Error: no source RPM could be found, exiting..."
echo "You can create SRPM using the parameter --build_src_rpm"
echo "You can build source RPM using the parameter --build_src_rpm"
exit 1
fi

Expand All @@ -146,7 +126,7 @@ build_rpm(){
rpmbuild --define "_topdir ${WORKDIR}/rpmbuild" \
--define "version $pmm_version" \
--define "release $RPM_RELEASE" \
--define "dist .$OS_NAME" \
--define "dist .el${RHEL}" \
--rebuild rpmbuild/SRPMS/$SRC_RPM

return_code=$?
Expand All @@ -160,18 +140,14 @@ build_rpm(){
}

build_source_deb(){
if [ "$OS" = "rpm" ]; then
echo "It is not possible to build source deb here"
exit 1
fi
rm -rf pmm-client*
get_tar "tarball"
rm -f *.dsc *.orig.tar.gz *.debian.tar.gz *.changes

TARFILE=$(basename $(find . -name "${PACKAGE_NAME}-*.tar.gz" | sort | tail -n1))
NAME=$(echo ${TARFILE}| awk -F '-' '{print $1"-"$2}')
VERSION_TMP=$(echo ${TARFILE}| awk -F '-' '{print $3}')
VERSION=${VERSION_TMP%.tar.gz}
local TARFILE=$(get_tar "tarball")
# TARFILE=$(basename $(find . -name "${PACKAGE_NAME}-*.tar.gz" | sort | tail -n1))
local NAME=$(echo ${TARFILE}| awk -F '-' '{print $1"-"$2}')
local VERSION_TMP=$(echo ${TARFILE}| awk -F '-' '{print $3}')
local VERSION=${VERSION_TMP%.tar.gz}

rm -fr ${NAME}-${VERSION}

Expand All @@ -181,7 +157,7 @@ build_source_deb(){
git clone $REPO ${NAME}-${VERSION}_all
pushd ${NAME}-${VERSION}_all
git fetch origin
if [ ! -z ${BRANCH} ]; then
if [ -n ${BRANCH} ]; then
git reset --hard
git clean -xdf
git checkout ${BRANCH}
Expand Down Expand Up @@ -218,7 +194,7 @@ build_source_deb(){

cd ../

dch -D unstable --force-distribution -v "${VERSION}-${DEB_RELEASE}" "Update to new upstream release PMM-client ${VERSION}-${DEB_RELEASE}"
dch -D unstable --force-distribution -v "${VERSION}-${DEB_RELEASE}" "Update to new upstream release of PMM Client ${VERSION}-${DEB_RELEASE}"
dpkg-buildpackage -S
cd ../
mkdir -p $WORKDIR/source_deb
Expand All @@ -234,10 +210,6 @@ build_source_deb(){
}

build_deb(){
if [ "$OS" = "rpm" ]; then
echo "It is not possible to build deb here"
exit 1
fi
for file in 'dsc' 'orig.tar.gz' 'changes' 'diff.gz'; do
get_deb_sources $file
done
Expand All @@ -258,55 +230,31 @@ build_deb(){

dpkg-buildpackage -rfakeroot -uc -us -b
mkdir -p $CURDIR/deb
mkdir -p $WORKDIR/deb
cp $WORKDIR/*.deb $WORKDIR/deb
cp $WORKDIR/*.deb $CURDIR/deb
}

#main

# CURDIR is set to `/home/builder/build` inside the container, which is mapped to `pmm-submodules/build`
CURDIR=$(pwd)
WORKDIR=/tmp/pmm
PACKAGE_NAME=pmm-client
VERSION_FILE=$CURDIR/pmm-client.properties
SRPM=0
SDEB=0
RPM=0
DEB=0
OS_NAME=
ARCH=
OS=
RPM_RELEASE=1
DEB_RELEASE=1
REVISION=0
BRANCH="v3"
REPO="https://github.com/Percona-Lab/pmm-submodules.git"

if [ -n "$pmm_release" ]; then
RPM_RELEASE="$RPM_RELEASE.$pmm_release"
DEB_RELEASE="$DEB_RELEASE.$pmm_release"
fi

parse_arguments "$@"
get_system

check_workdir
if [ "$SRPM" != 0 ]; then
echo "Building srpm packages..."
build_srpm
fi
if [ "$SDEB" != 0 ]; then
echo "Building source deb packages..."
build_source_deb
fi
if [ "$RPM" != 0 ]; then
echo "Building rpm packages..."
build_rpm
fi
if [ "$DEB" != 0 ]; then
echo "Building deb packages..."
build_deb
fi
main() {
# CURDIR points to `/home/builder/build` inside the container, which is mapped to `pmm-submodules/build`
CURDIR=$(pwd)
WORKDIR=/tmp/pmm
PACKAGE_NAME=pmm-client
VERSION_FILE=${CURDIR}/${PACKAGE_NAME}.properties
RPM_RELEASE=1
DEB_RELEASE=1
REVISION=0
BRANCH="v3"
REPO="https://github.com/Percona-Lab/pmm-submodules.git"

if [ -n "$pmm_release" ]; then
RPM_RELEASE="$RPM_RELEASE.$pmm_release"
DEB_RELEASE="$DEB_RELEASE.$pmm_release"
fi

check_workdir

run "$@"
}

main "$@"

# vim: expandtab shiftwidth=2 tabstop=2
20 changes: 1 addition & 19 deletions build/scripts/build-client-rpm
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,11 @@ set -o errexit
set -o xtrace

main() {
echo -----------------------------------------
echo "Building PMM Client source RPM packages..."
echo -----------------------------------------

local IMAGE=${1:-${rpmbuild_docker_image}}
docker run --rm \
--platform=${platform} \
-v ${bin_dir}:/home/builder/bin \
-v ${build_dir}:/home/builder/build \
${IMAGE} sh -c "
set -o errexit
set -o xtrace
export pmm_release=$pmm_release
cd /home/builder/build
/home/builder/bin/build-client-packages --build_src_rpm
"

echo -----------------------------------------
echo "Building PMM Client RPM packages..."
echo -----------------------------------------

local IMAGE=${1:-${rpmbuild_docker_image}}
docker run --rm \
--platform=${platform} \
-v ${bin_dir}:/home/builder/bin \
Expand Down
31 changes: 31 additions & 0 deletions build/scripts/build-client-srpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

. $(dirname $0)/vars

set -o errexit
set -o xtrace

main() {
echo -----------------------------------------
echo "Building PMM Client source RPM packages..."
echo -----------------------------------------

local IMAGE=${1:-${rpmbuild_docker_image}}
docker run --rm \
--platform=${platform} \
-v ${bin_dir}:/home/builder/bin \
-v ${build_dir}:/home/builder/build \
${IMAGE} sh -c "
set -o errexit
set -o xtrace
export pmm_release=$pmm_release
cd /home/builder/build
/home/builder/bin/build-client-packages --build_src_rpm
"
}

main $*

# vim: expandtab shiftwidth=2 tabstop=2

0 comments on commit 4f490a0

Please sign in to comment.