Skip to content
Draft
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
62 changes: 49 additions & 13 deletions devops/build/packaging/rpm/apache-cloudberry-db-incubating.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
# specific language governing permissions and limitations
# under the License.

%define cloudberry_install_dir /usr/local/cloudberry-db
%define cloudberry_base_dir /usr/local
%define cloudberry_name cloudberry-db
%define cloudberry_install_dir %{cloudberry_base_dir}/%{cloudberry_name}

# Add at the top of the spec file
# Default to non-debug build
Expand All @@ -41,7 +43,7 @@ License: ASL 2.0
URL: https://cloudberry.apache.org
Vendor: Apache Cloudberry (Incubating)
Group: Applications/Databases
Prefix: %{cloudberry_install_dir}
Prefix: %{cloudberry_base_dir}

# Disabled as we are shipping GO programs (e.g. gpbackup)
%define _missing_build_ids_terminate_build 0
Expand Down Expand Up @@ -142,10 +144,18 @@ completeness or stability of the code, it does indicate that the
project has yet to be fully endorsed by the ASF.

%prep
# No prep needed for binary RPM
# Validate required macros are provided
if [ %{version} = '%%{version}' ] ; then
echo "The macro 'version' must be supplied as rpmbuild ... --define='version [VERSION]'"
exit 1
fi
if [ %{release} = '%%{release}' ] ; then
echo "The macro 'release' must be supplied as rpmbuild ... --define='release [RELEASE]'"
exit 1
fi

%build
# No prep needed for binary RPM
# No build needed for binary RPM

%install
rm -rf %{buildroot}
Expand All @@ -155,31 +165,57 @@ mkdir -p %{buildroot}%{cloudberry_install_dir}-%{version}

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

# Pre-compile Python bytecode to reduce first-run latency
if command -v python3 &>/dev/null; then
python3 -m compileall -q -x test %{buildroot}%{cloudberry_install_dir}-%{version} || :
fi

# 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}

%files
%{prefix}-%{version}
%{prefix}
%{cloudberry_install_dir}-%{version}
%config(noreplace) %{cloudberry_install_dir}-%{version}/cloudberry-env.sh

%debug_package

%post
# RPM_INSTALL_PREFIX is set dynamically by RPM to the actual --prefix value
LINK_PATH="${RPM_INSTALL_PREFIX}/%{cloudberry_name}"
VERSIONED_DIR="${RPM_INSTALL_PREFIX}/%{cloudberry_name}-%{version}"

if [ ! -e "${LINK_PATH}" ]; then
# No existing link or file, create symlink
ln -fsT "${VERSIONED_DIR}" "${LINK_PATH}" || :
elif [ -L "${LINK_PATH}" ] && [ -e "${LINK_PATH}/bin/postgres" ] && [ -e "${LINK_PATH}/cloudberry-env.sh" ]; then
# Existing valid Cloudberry installation, check major version
original_version=$(source "${LINK_PATH}/cloudberry-env.sh"; "${LINK_PATH}/bin/postgres" --gp-version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
original_major_version=${original_version%%.*}
current_major_version=%{version}
current_major_version=${current_major_version%%.*}
if [ "${original_major_version}" == "${current_major_version}" ]; then
ln -fsT "${VERSIONED_DIR}" "${LINK_PATH}" || :
else
echo "Warning: symlink ${LINK_PATH} not updated because it points to a different major version (${original_major_version})"
fi
else
echo "Warning: symlink ${LINK_PATH} not created because a file or directory already exists at that location"
fi

# Change ownership to gpadmin.gpadmin if the gpadmin user exists
if id "gpadmin" &>/dev/null; then
chown -R gpadmin:gpadmin %{cloudberry_install_dir}-%{version}
chown gpadmin:gpadmin %{cloudberry_install_dir}
chown -R gpadmin:gpadmin "${VERSIONED_DIR}"
if [ -L "${LINK_PATH}" ]; then
chown -h gpadmin:gpadmin "${LINK_PATH}"
fi
fi

%postun
if [ $1 -eq 0 ] ; then
if [ "$(readlink -f "%{cloudberry_install_dir}")" == "%{cloudberry_install_dir}-%{version}" ]; then
unlink "%{cloudberry_install_dir}" || true
if [ "$(readlink -f "${RPM_INSTALL_PREFIX}/%{cloudberry_name}")" == "${RPM_INSTALL_PREFIX}/%{cloudberry_name}-%{version}" ]; then
unlink "${RPM_INSTALL_PREFIX}/%{cloudberry_name}" || :
fi
fi
Loading