Skip to content

Commit da9a5ae

Browse files
authored
Fix compliance issues for RPM and DEB packages
As an Apache incubating project, convenience binaries must include LICENSE, NOTICE, and DISCLAIMER files. This commit adds these mandatory compliance files into the spec and rules definitions to ensure they are properly distributed with the binary RPM and DEB packages. Additionally, this commit: - Automates the cp of the .spec file into the ~/rpmbuild tree to prevent build failures for new users. - Dynamically locates debian metadata from OS-specific directories and copies to project root for dpkg-buildpackage. - Generates debian/copyright file by combining LICENSE and NOTICE to meet Debian policy requirements.
1 parent 8b91a98 commit da9a5ae

File tree

4 files changed

+99
-13
lines changed

4 files changed

+99
-13
lines changed

devops/build/packaging/deb/build-deb.sh

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export CBDB_FULL_VERSION=$VERSION
109109

110110
# Set version if not provided
111111
if [ -z "${VERSION}" ]; then
112-
export CBDB_FULL_VERSION=$(./getversion | cut -d'-' -f 1 | cut -d'+' -f 1)
112+
export CBDB_FULL_VERSION=$(./getversion 2>/dev/null | cut -d'-' -f 1 | cut -d'+' -f 1 || echo "unknown")
113113
fi
114114

115115
if [[ ! $CBDB_FULL_VERSION =~ ^[0-9] ]]; then
@@ -127,22 +127,48 @@ fi
127127
# Detect OS distribution (e.g., ubuntu22.04, debian12)
128128
if [ -z ${OS_DISTRO+x} ]; then
129129
if [ -f /etc/os-release ]; then
130+
# Temporarily disable unbound variable check for sourcing os-release
131+
set +u
130132
. /etc/os-release
131-
OS_DISTRO=$(echo "${ID}${VERSION_ID}" | tr '[:upper:]' '[:lower:]')
133+
set -u
134+
# Ensure ID and VERSION_ID are set before using them
135+
OS_DISTRO=$(echo "${ID:-unknown}${VERSION_ID:-}" | tr '[:upper:]' '[:lower:]')
132136
else
133137
OS_DISTRO="unknown"
134138
fi
135139
fi
136140

141+
# Ensure OS_DISTRO is exported and not empty
142+
export OS_DISTRO=${OS_DISTRO:-unknown}
143+
137144
export CBDB_PKG_VERSION=${CBDB_FULL_VERSION}-${BUILD_NUMBER}-${OS_DISTRO}
138145

139146
# Check if required commands are available
140147
check_commands
141148

142-
# Define the control file path
143-
CONTROL_FILE=debian/control
149+
# Find project root (assumed to be four levels up from scripts directory: devops/build/packaging/deb/)
150+
PROJECT_ROOT="$(cd "$(dirname "$0")/../../../../" && pwd)"
151+
152+
# Define where the debian metadata is located
153+
DEBIAN_SRC_DIR="$(dirname "$0")/${OS_DISTRO}"
154+
155+
# Prepare the debian directory at the project root (required by dpkg-buildpackage)
156+
if [ -d "$DEBIAN_SRC_DIR" ]; then
157+
echo "Preparing debian directory from $DEBIAN_SRC_DIR..."
158+
mkdir -p "$PROJECT_ROOT/debian"
159+
# Use /. to copy directory contents if target exists instead of nested directories
160+
cp -rf "$DEBIAN_SRC_DIR"/. "$PROJECT_ROOT/debian/"
161+
else
162+
if [ ! -d "$PROJECT_ROOT/debian" ]; then
163+
echo "Error: Debian metadata not found at $DEBIAN_SRC_DIR and no debian/ directory exists at root."
164+
exit 1
165+
fi
166+
fi
167+
168+
# Define the control file path (at the project root)
169+
CONTROL_FILE="$PROJECT_ROOT/debian/control"
144170

145-
# Check if the spec file exists
171+
# Check if the control file exists
146172
if [ ! -f "$CONTROL_FILE" ]; then
147173
echo "Error: Control file not found at $CONTROL_FILE."
148174
exit 1
@@ -160,10 +186,15 @@ if [ "${DRY_RUN:-false}" = true ]; then
160186
exit 0
161187
fi
162188

163-
# Run debbuild with the provided options
164-
echo "Building DEB with Version $CBDB_FULL_VERSION ..."
189+
# Run debbuild from the project root
190+
echo "Building DEB with Version $CBDB_FULL_VERSION in $PROJECT_ROOT ..."
191+
192+
print_changelog > "$PROJECT_ROOT/debian/changelog"
165193

166-
print_changelog > debian/changelog
194+
# Only cd if we are not already at the project root
195+
if [ "$(pwd)" != "$PROJECT_ROOT" ]; then
196+
cd "$PROJECT_ROOT"
197+
fi
167198

168199
if ! eval "$DEBBUILD_CMD"; then
169200
echo "Error: deb build failed."

devops/build/packaging/deb/ubuntu22.04/rules

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,22 @@ include /usr/share/dpkg/default.mk
1919
dh $@ --parallel
2020

2121
gpinstall:
22-
make install DESTDIR=${DEBIAN_DESTINATION} prefix=
22+
# If the build staging directory is empty, copy from the pre-installed location.
23+
# In CI, BUILD_DESTINATION already points here so it will be populated.
24+
# For local manual packaging, copy from the installed Cloudberry path.
25+
@mkdir -p ${DEBIAN_DESTINATION}
26+
@if [ -z "$$(ls -A ${DEBIAN_DESTINATION} 2>/dev/null)" ]; then \
27+
echo "Copying pre-built binaries from ${CBDB_BIN_PATH} to ${DEBIAN_DESTINATION}..."; \
28+
cp -a ${CBDB_BIN_PATH}/* ${DEBIAN_DESTINATION}/; \
29+
else \
30+
echo "Build staging directory already populated, skipping copy."; \
31+
fi
32+
# Copy Apache compliance files into the build staging directory
33+
cp -a LICENSE NOTICE DISCLAIMER ${DEBIAN_DESTINATION}/
34+
cp -a licenses ${DEBIAN_DESTINATION}/
35+
# Create debian/copyright for Debian policy compliance
36+
mkdir -p $(shell pwd)/debian
37+
cat LICENSE NOTICE > $(shell pwd)/debian/copyright
2338

2439
override_dh_auto_install: gpinstall
2540
# the staging directory for creating a debian is NOT the right GPHOME.

devops/build/packaging/rpm/apache-cloudberry-db-incubating.spec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,19 @@ mkdir -p %{buildroot}%{cloudberry_install_dir}-%{version}
155155

156156
cp -R %{cloudberry_install_dir}/* %{buildroot}%{cloudberry_install_dir}-%{version}
157157

158+
# Copy Apache mandatory compliance files from the SOURCES directory into the installation directory
159+
cp %{_sourcedir}/LICENSE %{buildroot}%{cloudberry_install_dir}-%{version}/
160+
cp %{_sourcedir}/NOTICE %{buildroot}%{cloudberry_install_dir}-%{version}/
161+
cp %{_sourcedir}/DISCLAIMER %{buildroot}%{cloudberry_install_dir}-%{version}/
162+
cp -R %{_sourcedir}/licenses %{buildroot}%{cloudberry_install_dir}-%{version}/
163+
158164
# Create the symbolic link
159165
ln -sfn %{cloudberry_install_dir}-%{version} %{buildroot}%{cloudberry_install_dir}
160166

161167
%files
162168
%{prefix}-%{version}
163169
%{prefix}
164170

165-
%license %{cloudberry_install_dir}-%{version}/LICENSE
166-
167171
%debug_package
168172

169173
%post

devops/build/packaging/rpm/build-rpm.sh

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,46 @@ fi
118118
# Check if required commands are available
119119
check_commands
120120

121-
# Define the spec file path
121+
# Define the source spec file path (assuming it is in the same directory as the script)
122+
SOURCE_SPEC_FILE="$(dirname "$0")/apache-cloudberry-db-incubating.spec"
123+
124+
# Ensure rpmbuild SPECS and SOURCES directories exist
125+
mkdir -p ~/rpmbuild/SPECS
126+
mkdir -p ~/rpmbuild/SOURCES
127+
128+
# Find project root (assumed to be four levels up from scripts directory: devops/build/packaging/rpm/)
129+
PROJECT_ROOT="$(cd "$(dirname "$0")/../../../../" && pwd)"
130+
131+
# Define the target spec file path
122132
SPEC_FILE=~/rpmbuild/SPECS/apache-cloudberry-db-incubating.spec
123133

124-
# Check if the spec file exists
134+
# Copy the spec file to rpmbuild/SPECS if the source exists and is different
135+
if [ -f "$SOURCE_SPEC_FILE" ]; then
136+
# Avoid copying if SPEC_FILE is already a symlink/file pointing to SOURCE_SPEC_FILE (common in CI)
137+
if [ ! "$SOURCE_SPEC_FILE" -ef "$SPEC_FILE" ]; then
138+
cp -f "$SOURCE_SPEC_FILE" "$SPEC_FILE"
139+
fi
140+
else
141+
echo "Warning: Source spec file not found at $SOURCE_SPEC_FILE, assuming it is already in ~/rpmbuild/SPECS/"
142+
fi
143+
144+
# Copy Apache mandatory compliance files to rpmbuild/SOURCES
145+
echo "Copying compliance files from $PROJECT_ROOT to ~/rpmbuild/SOURCES..."
146+
for f in LICENSE NOTICE DISCLAIMER; do
147+
if [ -f "$PROJECT_ROOT/$f" ]; then
148+
cp -af "$PROJECT_ROOT/$f" ~/rpmbuild/SOURCES/
149+
else
150+
echo "Warning: $f not found in $PROJECT_ROOT"
151+
fi
152+
done
153+
154+
if [ -d "$PROJECT_ROOT/licenses" ]; then
155+
cp -af "$PROJECT_ROOT/licenses" ~/rpmbuild/SOURCES/
156+
else
157+
echo "Warning: licenses directory not found in $PROJECT_ROOT"
158+
fi
159+
160+
# Check if the spec file exists at the target location before proceeding
125161
if [ ! -f "$SPEC_FILE" ]; then
126162
echo "Error: Spec file not found at $SPEC_FILE."
127163
exit 1

0 commit comments

Comments
 (0)