Skip to content

Commit

Permalink
ci: support packaging RPM and DEB
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdrivingduck authored and polardb-bot[bot] committed Sep 5, 2024
1 parent 25ed000 commit f3737b0
Show file tree
Hide file tree
Showing 5 changed files with 532 additions and 0 deletions.
124 changes: 124 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: build packages

on:
push:
tags:
- "v*"
branches: [ POLARDB_15_STABLE ]
pull_request:
branches: [ POLARDB_15_STABLE ]
paths:
- '.github/workflows/package.yml'
- 'config/**'
- 'contrib/**'
- 'external/**'
- 'package/**'
- 'src/**'
- 'configure*'
- 'build.sh'
# trigger testing manually
workflow_dispatch:

jobs:

build-and-publish-rpm:
runs-on: ubuntu-latest
strategy:
matrix:
base_image: [ anolis8, rocky8, rocky9 ]
steps:
- name: fetch source code
uses: actions/checkout@v4
- name: create and start the container
run: |
docker create \
-t \
--name polardb_${{ matrix.base_image }} \
-v `pwd`:/home/postgres/PolarDB-for-PostgreSQL \
polardb/polardb_pg_devel:${{ matrix.base_image }} \
bash && \
docker start polardb_${{ matrix.base_image }}
- name: build RPM package
run: |
docker exec \
polardb_${{ matrix.base_image }} \
bash -c "cd /home/postgres/PolarDB-for-PostgreSQL && \
sudo chown -R postgres:postgres ./ && \
cd ./package/rpm && \
if [ -f /etc/bashrc ]; then source /etc/bashrc; fi && \
./build-rpm.sh"
- name: get package name
run: |
cd ./package/rpm/x86_64 && RPMNAME=`ls` && echo "rpmname=$RPMNAME" >> $GITHUB_ENV
- name: upload artifact
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v4
with:
name: ${{ env.rpmname }}
path: ./package/rpm/x86_64/${{ env.rpmname }}
compression-level: 0
- name: change ownership of the source code
run: |
sudo chown -R runner:runner `pwd`
build-and-publish-deb:
runs-on: ubuntu-latest
strategy:
matrix:
base_image: [ ubuntu20.04, ubuntu22.04, ubuntu24.04 ]
steps:
- name: fetch source code
uses: actions/checkout@v4
- name: create and start the container
run: |
docker create \
-t \
--name polardb_${{ matrix.base_image }} \
-v `pwd`:/home/postgres/PolarDB-for-PostgreSQL \
polardb/polardb_pg_devel:${{ matrix.base_image }} \
bash && \
docker start polardb_${{ matrix.base_image }}
- name: build deb package
run: |
docker exec \
polardb_${{ matrix.base_image }} \
bash -c "cd /home/postgres/PolarDB-for-PostgreSQL && \
sudo chown -R postgres:postgres ./ && \
cd ./package/debian && \
if [ -f /etc/bashrc ]; then source /etc/bashrc; fi && \
./build-deb.sh"
- name: get package name
run: |
cd ./package/debian && DEBNAME=`ls *.deb` && echo "debname=$DEBNAME" >> $GITHUB_ENV
- name: upload artifact
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v4
with:
name: ${{ env.debname }}
path: ./package/debian/${{ env.debname }}
compression-level: 0
- name: change ownership of the source code
run: |
sudo chown -R runner:runner `pwd`
release-packages:
if: startsWith(github.ref, 'refs/tags/')
needs: [ build-and-publish-rpm, build-and-publish-deb ]
runs-on: ubuntu-latest
steps:
- name: download all artifacts
uses: actions/download-artifact@v4
with:
pattern: |
*.{rpm,deb}
merge-multiple: true
- name: upload artifacts to release
uses: softprops/action-gh-release@v2
with:
files: |
*.rpm
*.deb
153 changes: 153 additions & 0 deletions package/debian/build-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/bin/bash

# build-deb.sh
# Use shell script to build .deb packages.
#
# Copyright (c) 2024, Alibaba Group Holding Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# IDENTIFICATION
# package/debian/build-deb.sh

build_date=${1:-$(date +"%Y%m%d%H%M%S")}
code_commit=$(git rev-parse HEAD || echo unknown)
code_branch=$(git rev-parse --abbrev-ref HEAD || echo unknown)
polar_commit=$(git rev-parse --short=8 HEAD || echo unknown)
pg_version=$(grep AC_INIT ../../configure.ac | awk -F'[][]' '{print $4}')
polar_majorversion=$(echo ${pg_version})
polar_minorversion=$(grep '^POLAR_MINORVERSION' ../../configure.ac | cut -d '"' -f2)
polar_release_date=$(grep '^POLAR_RELEASE_DATE' ../../configure.ac | cut -d '"' -f2)
polar_version=${polar_majorversion}.${polar_minorversion}
polar_pg_version=${pg_version}.${polar_minorversion}

package=PolarDB
debpkgname=$(grep 'Package:' ./control | awk '{print $2}')
distname=$(grep '^ID=' /etc/os-release | awk -F'=' '{print $2}')
distversion=$(grep 'VERSION_ID=' /etc/os-release | awk -F\" '{print $2}')
arch=$(dpkg --print-architecture)

pkgname=${package}_${polar_version}-${polar_commit}-${distname}${distversion}_${arch}
rm -rf ./${pkgname}
mkdir -p ${pkgname}/DEBIAN

cat ./control >> ${pkgname}/DEBIAN/control
echo 'Version: '${polar_version}'-'${polar_commit}'' >> ${pkgname}/DEBIAN/control
echo 'Architecture: '${arch}'' >> ${pkgname}/DEBIAN/control

prefix=/u01/polardb_pg
buildroot=$(pwd)
cd ../../
export COPT="-Wno-error ${COPT-}"
./build.sh --ec="--prefix=${buildroot}/${pkgname}${prefix} --with-pfsd" --debug=off --ni
cd ${buildroot}

polar_install_dependency()
{
target_dir=${1}

# create link for lib inside lib
cd ${target_dir}/lib/
ln -sf ../lib ./lib

cd ${target_dir}

# generate list of .so files
# collect all the executable binaries, scripts and shared libraries
binfiles=`find ${target_dir}/bin`
libfiles=`find ${target_dir}/lib`
filelist=${binfiles}$'\n'${libfiles}
exelist=`echo $filelist | xargs -r file | egrep -v ":.* (commands|script)" | \
grep ":.*executable" | cut -d: -f1`
scriptlist=`echo $filelist | xargs -r file | \
egrep ":.* (commands|script)" | cut -d: -f1`
liblist=`echo $filelist | xargs -r file | \
grep ":.*shared object" | cut -d : -f1`

# dependency list of the executable binaries and shared libraries
cp /dev/null mytmpfilelist
cp /dev/null mytmpfilelist2

# put PolarDB-PG libs before any other libs to let ldd take it first
export LD_LIBRARY_PATH=${target_dir}/lib:$LD_LIBRARY_PATH:/usr/lib

# dependency list of all binaries and shared objects
for f in $liblist $exelist; do
ldd $f | awk '/=>/ {
if (X$3 != "X" && $3 !~ /libNoVersion.so/ && $3 !~ /4[um]lib.so/ && $3 !~ /libredhat-kernel.so/ && $3 !~ /libselinux.so/ && $3 !~ /\/u01\/polardb_pg/ && $3 !~ /libjvm.so/ && $3 ~ /\.so/) {
# printf "$s => $s\n", $1, $3
print $3
}
}' >> mytmpfilelist
done

# deduplicate
cat mytmpfilelist | sort -u > mytmpfilelist2

for f in `cat mytmpfilelist2`; do
ldd $f | awk '/=>/ {
if (X$3 != "X" && $3 !~ /libNoVersion.so/ && $3 !~ /4[um]lib.so/ && $3 !~ /libredhat-kernel.so/ && $3 !~ /libselinux.so/ && $3 !~ /\/u01\/polardb_pg/ && $3 !~ /libjvm.so/ && $3 ~ /\.so/) {
# printf "$s => $s\n", $1, $3
print $3
}
}' >> mytmpfilelist
done

# deduplicate
cat mytmpfilelist | sort -u > mytmpfilelist2

# copy libraries if necessary
for line in `cat mytmpfilelist2`; do
base=`basename $line`
dirpath=${target_dir}/lib
filepath=$dirpath/$base

objdump -p $line | awk 'BEGIN { START=0; LIBNAME=""; }
/^$/ { START=0; }
/^Dynamic Section:$/ { START=1; }
(START==1) && /NEEDED/ {
print $2 ;
}
(START==2) && /^[A-Za-z]/ { START=3; }
/^Version References:$/ { START=2; }
(START==2) && /required from/ {
sub(/:/, "", $3);
LIBNAME=$3;
}
(START==2) && (LIBNAME!="") && ($4!="") && (($4~/^GLIBC_*/) || ($4~/^GCC_*/)) {
print LIBNAME "(" $4 ")";
}
END { exit 0 }
' > objdumpfile

has_private=
if grep -q PRIVATE objdumpfile; then
has_private=true
fi

if [[ ! -f $filepath ]]; then
if [[ $has_private != "true" ]]; then
cp $line $dirpath
echo $line $dirpath
fi
fi
done

rm mytmpfilelist mytmpfilelist2 objdumpfile
}

# install package dependencies
polar_install_dependency $(pwd)/${pkgname}${prefix}
cd ${buildroot}

dpkg --build ./${pkgname}
17 changes: 17 additions & 0 deletions package/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Package: polardb-for-postgresql
Maintainer: mrdrivingduck <mrdrivingduck@gmail.com>
Depends: libicu66 | libicu70 | libicu74, libkrb5-3, libldap-2.4-2 | libldap-2.5-0 | libldap2
Section: database
Priority: optional
Homepage: https://github.com/ApsaraDB/PolarDB-for-PostgreSQL
Description: PolarDB is an advanced Object-Relational database management system
(DBMS) that supports almost all SQL constructs (including
transactions, subselects and user-defined types and functions). The
PolarDB package includes the client programs and libraries that
you'll need to access a PolarDB DBMS server. These PolarDB
client programs are programs that directly manipulate the internal
structure of PolarDB databases on a PolarDB server. These client
programs can be located on the same machine with the PolarDB
server, or may be on a remote machine which accesses a PolarDB
server over a network connection. This package contains the command-line
utilities for managing PolarDB databases on a PolarDB server.
Loading

0 comments on commit f3737b0

Please sign in to comment.