diff --git a/devops/build/packaging/deb/build-deb.sh b/devops/build/packaging/deb/build-deb.sh index 1f5aef2258a..3bcd967fa5a 100755 --- a/devops/build/packaging/deb/build-deb.sh +++ b/devops/build/packaging/deb/build-deb.sh @@ -139,10 +139,29 @@ export CBDB_PKG_VERSION=${CBDB_FULL_VERSION}-${BUILD_NUMBER}-${OS_DISTRO} # Check if required commands are available check_commands -# Define the control file path -CONTROL_FILE=debian/control +# Find project root (assumed to be four levels up from scripts directory: devops/build/packaging/deb/) +PROJECT_ROOT="$(cd "$(dirname "$0")/../../../../" && pwd)" + +# Define where the debian metadata is located +DEBIAN_SRC_DIR="$(dirname "$0")/${OS_DISTRO}" + +# Prepare the debian directory at the project root (required by dpkg-buildpackage) +if [ -d "$DEBIAN_SRC_DIR" ]; then + echo "Preparing debian directory from $DEBIAN_SRC_DIR..." + mkdir -p "$PROJECT_ROOT/debian" + # Use /. to copy directory contents if target exists instead of nested directories + cp -rf "$DEBIAN_SRC_DIR"/. "$PROJECT_ROOT/debian/" +else + if [ ! -d "$PROJECT_ROOT/debian" ]; then + echo "Error: Debian metadata not found at $DEBIAN_SRC_DIR and no debian/ directory exists at root." + exit 1 + fi +fi + +# Define the control file path (at the project root) +CONTROL_FILE="$PROJECT_ROOT/debian/control" -# Check if the spec file exists +# Check if the control file exists if [ ! -f "$CONTROL_FILE" ]; then echo "Error: Control file not found at $CONTROL_FILE." exit 1 @@ -160,10 +179,15 @@ if [ "${DRY_RUN:-false}" = true ]; then exit 0 fi -# Run debbuild with the provided options -echo "Building DEB with Version $CBDB_FULL_VERSION ..." +# Run debbuild from the project root +echo "Building DEB with Version $CBDB_FULL_VERSION in $PROJECT_ROOT ..." -print_changelog > debian/changelog +print_changelog > "$PROJECT_ROOT/debian/changelog" + +# Only cd if we are not already at the project root +if [ "$(pwd)" != "$PROJECT_ROOT" ]; then + cd "$PROJECT_ROOT" +fi if ! eval "$DEBBUILD_CMD"; then echo "Error: deb build failed." diff --git a/devops/build/packaging/deb/ubuntu22.04/rules b/devops/build/packaging/deb/ubuntu22.04/rules index cb387d209e6..463486cf03f 100755 --- a/devops/build/packaging/deb/ubuntu22.04/rules +++ b/devops/build/packaging/deb/ubuntu22.04/rules @@ -19,7 +19,22 @@ include /usr/share/dpkg/default.mk dh $@ --parallel gpinstall: - make install DESTDIR=${DEBIAN_DESTINATION} prefix= + # If the build staging directory is empty, copy from the pre-installed location. + # In CI, BUILD_DESTINATION already points here so it will be populated. + # For local manual packaging, copy from the installed Cloudberry path. + @mkdir -p ${DEBIAN_DESTINATION} + @if [ -z "$$(ls -A ${DEBIAN_DESTINATION} 2>/dev/null)" ]; then \ + echo "Copying pre-built binaries from ${CBDB_BIN_PATH} to ${DEBIAN_DESTINATION}..."; \ + cp -a ${CBDB_BIN_PATH}/* ${DEBIAN_DESTINATION}/; \ + else \ + echo "Build staging directory already populated, skipping copy."; \ + fi + # Copy Apache compliance files into the build staging directory + cp -a LICENSE NOTICE DISCLAIMER ${DEBIAN_DESTINATION}/ + cp -a licenses ${DEBIAN_DESTINATION}/ + # Create debian/copyright for Debian policy compliance + mkdir -p $(shell pwd)/debian + cat LICENSE NOTICE > $(shell pwd)/debian/copyright override_dh_auto_install: gpinstall # the staging directory for creating a debian is NOT the right GPHOME. diff --git a/devops/build/packaging/rpm/apache-cloudberry-db-incubating.spec b/devops/build/packaging/rpm/apache-cloudberry-db-incubating.spec index 03fa0a34570..cafb057c351 100644 --- a/devops/build/packaging/rpm/apache-cloudberry-db-incubating.spec +++ b/devops/build/packaging/rpm/apache-cloudberry-db-incubating.spec @@ -152,6 +152,12 @@ mkdir -p %{buildroot}%{cloudberry_install_dir}-%{version} cp -R %{cloudberry_install_dir}/* %{buildroot}%{cloudberry_install_dir}-%{version} +# Copy Apache mandatory compliance files from the SOURCES directory into the installation directory +cp %{_sourcedir}/LICENSE %{buildroot}%{cloudberry_install_dir}-%{version}/ +cp %{_sourcedir}/NOTICE %{buildroot}%{cloudberry_install_dir}-%{version}/ +cp %{_sourcedir}/DISCLAIMER %{buildroot}%{cloudberry_install_dir}-%{version}/ +cp -R %{_sourcedir}/licenses %{buildroot}%{cloudberry_install_dir}-%{version}/ + # Create the symbolic link ln -sfn %{cloudberry_install_dir}-%{version} %{buildroot}%{cloudberry_install_dir} @@ -159,8 +165,6 @@ ln -sfn %{cloudberry_install_dir}-%{version} %{buildroot}%{cloudberry_install_di %{prefix}-%{version} %{prefix} -%license %{cloudberry_install_dir}-%{version}/LICENSE - %debug_package %post diff --git a/devops/build/packaging/rpm/build-rpm.sh b/devops/build/packaging/rpm/build-rpm.sh index ceb7d18d392..2c490166f45 100755 --- a/devops/build/packaging/rpm/build-rpm.sh +++ b/devops/build/packaging/rpm/build-rpm.sh @@ -118,10 +118,46 @@ fi # Check if required commands are available check_commands -# Define the spec file path +# Define the source spec file path (assuming it is in the same directory as the script) +SOURCE_SPEC_FILE="$(dirname "$0")/apache-cloudberry-db-incubating.spec" + +# Ensure rpmbuild SPECS and SOURCES directories exist +mkdir -p ~/rpmbuild/SPECS +mkdir -p ~/rpmbuild/SOURCES + +# Find project root (assumed to be four levels up from scripts directory: devops/build/packaging/rpm/) +PROJECT_ROOT="$(cd "$(dirname "$0")/../../../../" && pwd)" + +# Define the target spec file path SPEC_FILE=~/rpmbuild/SPECS/apache-cloudberry-db-incubating.spec -# Check if the spec file exists +# Copy the spec file to rpmbuild/SPECS if the source exists and is different +if [ -f "$SOURCE_SPEC_FILE" ]; then + # Avoid copying if SPEC_FILE is already a symlink/file pointing to SOURCE_SPEC_FILE (common in CI) + if [ ! "$SOURCE_SPEC_FILE" -ef "$SPEC_FILE" ]; then + cp -f "$SOURCE_SPEC_FILE" "$SPEC_FILE" + fi +else + echo "Warning: Source spec file not found at $SOURCE_SPEC_FILE, assuming it is already in ~/rpmbuild/SPECS/" +fi + +# Copy Apache mandatory compliance files to rpmbuild/SOURCES +echo "Copying compliance files from $PROJECT_ROOT to ~/rpmbuild/SOURCES..." +for f in LICENSE NOTICE DISCLAIMER; do + if [ -f "$PROJECT_ROOT/$f" ]; then + cp -af "$PROJECT_ROOT/$f" ~/rpmbuild/SOURCES/ + else + echo "Warning: $f not found in $PROJECT_ROOT" + fi +done + +if [ -d "$PROJECT_ROOT/licenses" ]; then + cp -af "$PROJECT_ROOT/licenses" ~/rpmbuild/SOURCES/ +else + echo "Warning: licenses directory not found in $PROJECT_ROOT" +fi + +# Check if the spec file exists at the target location before proceeding if [ ! -f "$SPEC_FILE" ]; then echo "Error: Spec file not found at $SPEC_FILE." exit 1