Skip to content

Improve packaging and defaults #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,19 +315,23 @@ smoketests on them.

mbx list

2. To build packages using `mbx`:

mbx package --repo <repo, default: shapeblue/cloudstack> --tag <tag|branch|PR, default: main> --distro <distro - el7|el8|el9|debian, default: el8> --output-dir <output directory, default: /export/testing/builds> --flags <maven build flags, default: ''>

2. To deploy an environment, run:

mbx deploy <name of env, default: mbxe> <mgmt server template, default: mbxt-kvm-el7> <hypervisor template, default: mbxt-kvm-el7> <repo, default: http://packages.shapeblue.com/cloudstack/upstream/el7/4.18>
mbx deploy <name of env, default: mbxe> <mgmt server template, default: mbxt-kvm-el8> <hypervisor template, default: mbxt-kvm-el8> <repo, default: http://packages.shapeblue.com/cloudstack/upstream/el8/4.20>

Example to deploy test matrix (kvm, vmware, xenserver) environments:

mbx deploy 418-kenv mbxt-kvm-el8 mbxt-kvm-el8 # deploys ACS 4.18 + KVM EL8 env
mbx deploy 418-venv mbxt-kvm-el8 mbxt-vmware7 # deploys ACS 4.18 + VMware7(u3) env
mbx deploy 418-xenv mbxt-kvm-el8 mbxt-xcpng82 # deploys ACS 4.18 + XCP-ng 8.2 env
mbx deploy 420-kenv mbxt-kvm-el8 mbxt-kvm-el8 # deploys ACS 4.20 + KVM EL8 env
mbx deploy 420-venv mbxt-kvm-el8 mbxt-vmware7 # deploys ACS 4.20 + VMware7(u3) env
mbx deploy 420-xenv mbxt-kvm-el8 mbxt-xcpng82 # deploys ACS 4.20 + XCP-ng 8.2 env

More examples with custom packages repositories:

mbx deploy cs417-kvm mbxt-kvm-el7 mbxt-kvm-el7 http://download.cloudstack.org/centos/7/4.17/
mbx deploy cs420-kvm mbxt-kvm-el8 mbxt-kvm-el8 http://download.cloudstack.org/el/8/4.20/

3. Once `mbx` environment is deployed, to launch a zone run:

Expand Down
139 changes: 115 additions & 24 deletions files/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,101 @@

set -e

# Cleanup function on failure
cleanup_on_failure() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "=== BUILD FAILED (exit code: $exit_code) ==="
echo "Cleaning up /jenkins and /output directories..."
# Move to root before cleanup
cd /
# Cleanup /jenkins directory
if [ -d "/jenkins" ]; then
echo "Cleaning /jenkins directory..."
rm -rf /jenkins/*
echo "/jenkins directory cleaned up."
fi
# Cleanup /output directory
if [ -d "/output" ]; then
echo "Cleaning /output directory..."
rm -rf /output/*
echo "/output directory cleaned up."
fi
echo "=== CLEANUP COMPLETED ==="
fi
exit $exit_code
}

# Set trap to cleanup on any error or exit
trap cleanup_on_failure ERR EXIT

if [[ $DISTRO == "debian" ]]; then
locale-gen en_US.UTF-8
update-locale
fi

# printenv

echo "Repo: $GIT_REPO"
echo "Tag: $GIT_TAG"
echo "PR ID: $PR_ID"
echo "ACS Branch: $ACS_BRANCH"
echo "Distro: $DISTRO"
echo "Flags: $FLAGS"

export ROOT=/jenkins
cd $ROOT
rm -fr deps/*jar deps/awsapi-lib deps/*.mar NONOSS

# Initialize git repository and fetch code
echo "Initializing git repository..."
if [ ! -d ".git" ]; then
git init .
fi

# Add remote origin if it doesn't exist
if ! git remote get-url origin >/dev/null 2>&1; then
echo "Adding remote origin: https://github.com/$GIT_REPO.git"
git remote add origin "https://github.com/$GIT_REPO.git"
else
echo "Setting remote origin URL: https://github.com/$GIT_REPO.git"
git remote set-url origin "https://github.com/$GIT_REPO.git"
fi

# Fetch the repository
echo "Fetching repository from https://github.com/$GIT_REPO.git"
git reset --hard
git clean -fd
git fetch origin --depth=1 --progress

if [[ "${PR_ID}" != "" ]]; then
# Find base branch
BASE=$(curl https://api.github.com/repos/apache/cloudstack/pulls/$PR_ID | jq -r '.base.ref')
BASE=$(curl https://api.github.com/repos/$GIT_REPO/pulls/$PR_ID | jq -r '.base.ref')
git checkout ${BASE}
else
git checkout ${ACS_BRANCH}
# For regular branches/tags
echo "Fetching and checking out: $ACS_BRANCH"
if git ls-remote --heads origin "$ACS_BRANCH" | grep -q "$ACS_BRANCH"; then
# It's a branch
if [ "$(git rev-parse --abbrev-ref HEAD)" = "$ACS_BRANCH" ]; then
echo "Already on branch $ACS_BRANCH, pulling latest changes with rebase..."
git pull --rebase origin "$ACS_BRANCH"
else
git fetch origin "$ACS_BRANCH:$ACS_BRANCH" --depth=1 --progress
git checkout "$ACS_BRANCH"
fi
elif git ls-remote --tags origin "$ACS_BRANCH" | grep -q "$ACS_BRANCH"; then
# It's a tag
git fetch origin "refs/tags/$ACS_BRANCH:refs/tags/$ACS_BRANCH" --depth=1 --progress
git checkout "refs/tags/$ACS_BRANCH"
else
# Try to fetch as commit SHA
git checkout "$ACS_BRANCH"
fi
fi

# Add github remote
git remote add gh https://github.com/apache/cloudstack.git || true
git remote add gh https://github.com/$GIT_REPO.git || true

# Apply PR
if [[ "${PR_ID}" != "" ]]; then
Expand Down Expand Up @@ -72,7 +151,13 @@ export ACS_BUILD_OPTS="-Dnoredist -Dnonoss"
export MAVEN_OPTS="-Xmx4096m -XX:MaxPermSize=800m"

LIBS=NONOSS
git clone https://github.com/shapeblue/cloudstack-nonoss.git $LIBS --depth=1
if [ ! -d "$LIBS/.git" ]; then
git clone https://github.com/shapeblue/cloudstack-nonoss.git $LIBS --depth=1 --progress
else
cd $LIBS
git pull origin main
cd $ROOT
fi
cd $LIBS
bash -x install-non-oss.sh
cd $ROOT
Expand All @@ -81,26 +166,25 @@ chmod +x scripts/vm/hypervisor/xenserver/vhd-util

# Debian stuff
if [[ $DISTRO == "debian" ]]; then
export ACS_BUILD_OPTS="-Dnoredist -Dnonoss $FLAGS"
rm -frv ../cloudstack*deb
rm -frv ../cloudstack*.tar.gz
rm -frv ../cloudstack*.dsc
rm -frv ../cloudstack*.changes

echo "cloudstack (${VERSION}) unstable; urgency=low" > $ROOT/newchangelog
echo "" >> $ROOT/newchangelog
echo " * Update the version to ${PACKAGE_VERSION}" >> $ROOT/newchangelog
echo "" >> $ROOT/newchangelog
echo " -- Apache CloudStack Dev <dev@cloudstack.apache.org> $(date +'%a, %-d %b %Y %H:%m:%S +0530')" >> $ROOT/newchangelog
echo "" >> $ROOT/newchangelog
cat $ROOT/debian/changelog >> $ROOT/newchangelog
mv $ROOT/newchangelog $ROOT/debian/changelog

cd $ROOT
echo "" >> $ROOT/newchangelog
echo " * Update the version to ${PACKAGE_VERSION}" >> $ROOT/newchangelog
echo "" >> $ROOT/newchangelog
echo " -- Apache CloudStack Dev <dev@cloudstack.apache.org> $(date +'%a, %-d %b %Y %H:%m:%S +0530')" >> $ROOT/newchangelog
echo "" >> $ROOT/newchangelog
cat $ROOT/debian/changelog >> $ROOT/newchangelog
mv $ROOT/newchangelog $ROOT/debian/changelog

dpkg-buildpackage -uc -us -b
cd $ROOT

dpkg-buildpackage -uc -us -b
mv ../cloudstack-*.deb $ROOT

for pkg in $(ls cloud*.deb);
do
cp $pkg /output
Expand All @@ -111,24 +195,31 @@ else
sed -i "s/DEFREL=.*$/DEFREL='-D_rel ${MINOR}'/g" package.sh

case $DISTRO in
centos6)
bash -x package.sh -p noredist -d centos63
;;
centos7)
el7)
bash -x package.sh -p noredist -o rhel7 -d centos7 --release $MINOR
;;
centos8)
el8|el9)
ln -sf /usr/bin/python2 /usr/bin/python
bash -x package.sh -p noredist -o rhel8 -d centos8 --release $MINOR
;;
esac

cd $ROOT
for pkg in $(ls dist/rpmbuild/RPMS/x86_64/);
do
cp dist/rpmbuild/RPMS/x86_64/$pkg /output
done
package_folder="dist/rpmbuild/RPMS/x86_64/"
if [ ! -d $package_folder ];then
package_folder="dist/rpmbuild/RPMS/noarch/"
fi
for pkg in $(ls $package_folder);
do
cp $package_folder/$pkg /output
done
fi

rm -rf $ROOT/*

# If we reach here, the build was successful
# Disable the cleanup trap for successful builds
trap - ERR EXIT

echo "=== BUILD COMPLETED SUCCESSFULLY ==="
echo "Packages available in /output directory"
Loading