From 9e2beac6251967dd4c34bbacb463ccdc5343d2f7 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Wed, 22 Oct 2025 23:52:58 +0800 Subject: [PATCH] fix: suport bulding multi-arch rpm deb (#23569) Co-authored-by: Qiu Jian --- build/build.sh | 20 ++++++++++++++++--- build/build_deb.sh | 48 +++++++++++++++++++++++++++++++++++++++++----- build/glance/vars | 2 +- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/build/build.sh b/build/build.sh index 17b232c6e8..c178df615f 100755 --- a/build/build.sh +++ b/build/build.sh @@ -36,6 +36,12 @@ fi . $ROOT/vars BUILDROOT=$(mktemp -d 2>/dev/null || mktemp -d -t 'yunion') +function cleanup { + rm -rf "$BUILDROOT" + echo "Deleted temp working directory $BUILDROOT" +} +# register the cleanup function to be called on the EXIT signal +trap cleanup EXIT echo "Build root ${BUILDROOT}" @@ -138,7 +144,17 @@ if [ -d $ROOT/root/ ]; then find $ROOT/root/ -type f | sed -e "s:$ROOT/root::g" >> $SPEC_FILE fi -rpmbuild --define "_topdir $BUILDROOT" -bb $SPEC_FILE +TARGET= +case "$GOARCH" in + "arm64" | "aarch64" | "arm") + TARGET="--target aarch64-redhat-linux" + ;; + "amd64" | "x86" | "i686" | "i386" | "x86_64") + TARGET="--target x86_64-redhat-linux" + ;; +esac + +rpmbuild --define "_topdir $BUILDROOT" -bb $SPEC_FILE $TARGET find $RPM_DIR -type f | while read f; do d="$(dirname "$f")" @@ -146,5 +162,3 @@ find $RPM_DIR -type f | while read f; do mkdir -p "$d" cp $f $d done - -rm -fr $BUILDROOT diff --git a/build/build_deb.sh b/build/build_deb.sh index c3d01f31da..09b382cd16 100755 --- a/build/build_deb.sh +++ b/build/build_deb.sh @@ -39,10 +39,18 @@ if [ -z "$VERSION" ]; then TAG=$(git describe --abbrev=0 --tags || echo 000000) VERSION=${TAG/\//-} VERSION=${VERSION/v/} + VERSION=${VERSION/master-/} fi RELEASE=`date +"%y%m%d%H"` FULL_VERSION=$VERSION-$RELEASE -BUILDROOT=$OUTPUT_DIR/yunion-$1-$FULL_VERSION +BUILDROOT=$OUTPUT_DIR/yunion-$PKG-$FULL_VERSION +function cleanup { + rm -rf "$BUILDROOT" + echo "Deleted temp working directory $BUILDROOT" +} +# register the cleanup function to be called on the EXIT signal +trap cleanup EXIT + rm -rf $BUILDROOT mkdir -p $BUILDROOT/DEBIAN mkdir -p $BUILDROOT/$BIN_PATH @@ -64,15 +72,45 @@ case $(uname -m) in ;; esac -echo "Package: yunion-$1 +if [[ -n "$GOARCH" ]]; then + case "$GOARCH" in + "arm64" | "arm" | "aarch64") + CURRENT_ARCH="arm64" + ;; + "x86" | "x86_64" | "i686" | "i386" | "amd64") + CURRENT_ARCH="amd64" + ;; + esac +fi + +echo "Package: yunion-$PKG Version: $FULL_VERSION Section: base Priority: optional Architecture: $CURRENT_ARCH Maintainer: wanyaoqi@yunionyun.com -Description: Yunion $1 -" > $BUILDROOT/DEBIAN/control +Description: $DESCRIPTION" > $BUILDROOT/DEBIAN/control +if [ ${#REQUIRES[@]} -gt 0 ]; then + DEPS=$(IFS=, ; echo "${REQUIRES[*]}") + echo "Depends: $DEPS" >> $BUILDROOT/DEBIAN/control +fi chmod 0755 $BUILDROOT/DEBIAN/control +cat $BUILDROOT/DEBIAN/control -dpkg-deb --build $BUILDROOT \ No newline at end of file +if [ -n "$SERVICE" ]; then +echo "#!/bin/bash + +/usr/bin/systemctl --no-reload disable yunion-${PKG}.service >/dev/null 2>&1 || : +/usr/bin/systemctl stop yunion-${PKG}.service >/dev/null 2>&1 ||: +" > $BUILDROOT/DEBIAN/preinst +chmod 0755 $BUILDROOT/DEBIAN/preinst +echo "#!/bin/bash + +/usr/bin/systemctl preset yunion-${PKG}.service >/dev/null 2>&1 ||: +/usr/bin/systemctl daemon-reload >/dev/null 2>&1 ||: +" > $BUILDROOT/DEBIAN/postinst +chmod 0755 $BUILDROOT/DEBIAN/postinst +fi + +dpkg-deb --build $BUILDROOT diff --git a/build/glance/vars b/build/glance/vars index 1251b25d61..ba6ef28ca0 100644 --- a/build/glance/vars +++ b/build/glance/vars @@ -1,5 +1,5 @@ DESCRIPTION="Yunion Cloud Image Service" REQUIRES=( - yunion-qemu-2.12.1 + yunion-qemu-4.2.0 )