diff --git a/README.md b/README.md index d29be0f..5875a72 100644 --- a/README.md +++ b/README.md @@ -315,19 +315,23 @@ smoketests on them. mbx list +2. To build packages using `mbx`: + + mbx package --repo --tag --distro --output-dir --flags + 2. To deploy an environment, run: - mbx deploy + mbx deploy 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: diff --git a/files/build.sh b/files/build.sh index 53cfea5..84e6ec3 100644 --- a/files/build.sh +++ b/files/build.sh @@ -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 @@ -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 @@ -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 $(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 $(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 @@ -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" diff --git a/mbx b/mbx index bf52c88..4aa2337 100755 --- a/mbx +++ b/mbx @@ -96,43 +96,129 @@ list() { } package() { - if [[ "$1" == "-h" ]]; then - echo "Usage: mbx package