Skip to content

Commit f3737b0

Browse files
mrdrivingduckpolardb-bot[bot]
authored andcommitted
ci: support packaging RPM and DEB
1 parent 25ed000 commit f3737b0

File tree

5 files changed

+532
-0
lines changed

5 files changed

+532
-0
lines changed

.github/workflows/package.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: build packages
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
branches: [ POLARDB_15_STABLE ]
8+
pull_request:
9+
branches: [ POLARDB_15_STABLE ]
10+
paths:
11+
- '.github/workflows/package.yml'
12+
- 'config/**'
13+
- 'contrib/**'
14+
- 'external/**'
15+
- 'package/**'
16+
- 'src/**'
17+
- 'configure*'
18+
- 'build.sh'
19+
# trigger testing manually
20+
workflow_dispatch:
21+
22+
jobs:
23+
24+
build-and-publish-rpm:
25+
runs-on: ubuntu-latest
26+
strategy:
27+
matrix:
28+
base_image: [ anolis8, rocky8, rocky9 ]
29+
steps:
30+
- name: fetch source code
31+
uses: actions/checkout@v4
32+
- name: create and start the container
33+
run: |
34+
docker create \
35+
-t \
36+
--name polardb_${{ matrix.base_image }} \
37+
-v `pwd`:/home/postgres/PolarDB-for-PostgreSQL \
38+
polardb/polardb_pg_devel:${{ matrix.base_image }} \
39+
bash && \
40+
docker start polardb_${{ matrix.base_image }}
41+
42+
- name: build RPM package
43+
run: |
44+
docker exec \
45+
polardb_${{ matrix.base_image }} \
46+
bash -c "cd /home/postgres/PolarDB-for-PostgreSQL && \
47+
sudo chown -R postgres:postgres ./ && \
48+
cd ./package/rpm && \
49+
if [ -f /etc/bashrc ]; then source /etc/bashrc; fi && \
50+
./build-rpm.sh"
51+
52+
- name: get package name
53+
run: |
54+
cd ./package/rpm/x86_64 && RPMNAME=`ls` && echo "rpmname=$RPMNAME" >> $GITHUB_ENV
55+
- name: upload artifact
56+
if: startsWith(github.ref, 'refs/tags/')
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: ${{ env.rpmname }}
60+
path: ./package/rpm/x86_64/${{ env.rpmname }}
61+
compression-level: 0
62+
- name: change ownership of the source code
63+
run: |
64+
sudo chown -R runner:runner `pwd`
65+
66+
build-and-publish-deb:
67+
runs-on: ubuntu-latest
68+
strategy:
69+
matrix:
70+
base_image: [ ubuntu20.04, ubuntu22.04, ubuntu24.04 ]
71+
steps:
72+
- name: fetch source code
73+
uses: actions/checkout@v4
74+
- name: create and start the container
75+
run: |
76+
docker create \
77+
-t \
78+
--name polardb_${{ matrix.base_image }} \
79+
-v `pwd`:/home/postgres/PolarDB-for-PostgreSQL \
80+
polardb/polardb_pg_devel:${{ matrix.base_image }} \
81+
bash && \
82+
docker start polardb_${{ matrix.base_image }}
83+
84+
- name: build deb package
85+
run: |
86+
docker exec \
87+
polardb_${{ matrix.base_image }} \
88+
bash -c "cd /home/postgres/PolarDB-for-PostgreSQL && \
89+
sudo chown -R postgres:postgres ./ && \
90+
cd ./package/debian && \
91+
if [ -f /etc/bashrc ]; then source /etc/bashrc; fi && \
92+
./build-deb.sh"
93+
94+
- name: get package name
95+
run: |
96+
cd ./package/debian && DEBNAME=`ls *.deb` && echo "debname=$DEBNAME" >> $GITHUB_ENV
97+
- name: upload artifact
98+
if: startsWith(github.ref, 'refs/tags/')
99+
uses: actions/upload-artifact@v4
100+
with:
101+
name: ${{ env.debname }}
102+
path: ./package/debian/${{ env.debname }}
103+
compression-level: 0
104+
- name: change ownership of the source code
105+
run: |
106+
sudo chown -R runner:runner `pwd`
107+
108+
release-packages:
109+
if: startsWith(github.ref, 'refs/tags/')
110+
needs: [ build-and-publish-rpm, build-and-publish-deb ]
111+
runs-on: ubuntu-latest
112+
steps:
113+
- name: download all artifacts
114+
uses: actions/download-artifact@v4
115+
with:
116+
pattern: |
117+
*.{rpm,deb}
118+
merge-multiple: true
119+
- name: upload artifacts to release
120+
uses: softprops/action-gh-release@v2
121+
with:
122+
files: |
123+
*.rpm
124+
*.deb

package/debian/build-deb.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/bash
2+
3+
# build-deb.sh
4+
# Use shell script to build .deb packages.
5+
#
6+
# Copyright (c) 2024, Alibaba Group Holding Limited
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
# IDENTIFICATION
21+
# package/debian/build-deb.sh
22+
23+
build_date=${1:-$(date +"%Y%m%d%H%M%S")}
24+
code_commit=$(git rev-parse HEAD || echo unknown)
25+
code_branch=$(git rev-parse --abbrev-ref HEAD || echo unknown)
26+
polar_commit=$(git rev-parse --short=8 HEAD || echo unknown)
27+
pg_version=$(grep AC_INIT ../../configure.ac | awk -F'[][]' '{print $4}')
28+
polar_majorversion=$(echo ${pg_version})
29+
polar_minorversion=$(grep '^POLAR_MINORVERSION' ../../configure.ac | cut -d '"' -f2)
30+
polar_release_date=$(grep '^POLAR_RELEASE_DATE' ../../configure.ac | cut -d '"' -f2)
31+
polar_version=${polar_majorversion}.${polar_minorversion}
32+
polar_pg_version=${pg_version}.${polar_minorversion}
33+
34+
package=PolarDB
35+
debpkgname=$(grep 'Package:' ./control | awk '{print $2}')
36+
distname=$(grep '^ID=' /etc/os-release | awk -F'=' '{print $2}')
37+
distversion=$(grep 'VERSION_ID=' /etc/os-release | awk -F\" '{print $2}')
38+
arch=$(dpkg --print-architecture)
39+
40+
pkgname=${package}_${polar_version}-${polar_commit}-${distname}${distversion}_${arch}
41+
rm -rf ./${pkgname}
42+
mkdir -p ${pkgname}/DEBIAN
43+
44+
cat ./control >> ${pkgname}/DEBIAN/control
45+
echo 'Version: '${polar_version}'-'${polar_commit}'' >> ${pkgname}/DEBIAN/control
46+
echo 'Architecture: '${arch}'' >> ${pkgname}/DEBIAN/control
47+
48+
prefix=/u01/polardb_pg
49+
buildroot=$(pwd)
50+
cd ../../
51+
export COPT="-Wno-error ${COPT-}"
52+
./build.sh --ec="--prefix=${buildroot}/${pkgname}${prefix} --with-pfsd" --debug=off --ni
53+
cd ${buildroot}
54+
55+
polar_install_dependency()
56+
{
57+
target_dir=${1}
58+
59+
# create link for lib inside lib
60+
cd ${target_dir}/lib/
61+
ln -sf ../lib ./lib
62+
63+
cd ${target_dir}
64+
65+
# generate list of .so files
66+
# collect all the executable binaries, scripts and shared libraries
67+
binfiles=`find ${target_dir}/bin`
68+
libfiles=`find ${target_dir}/lib`
69+
filelist=${binfiles}$'\n'${libfiles}
70+
exelist=`echo $filelist | xargs -r file | egrep -v ":.* (commands|script)" | \
71+
grep ":.*executable" | cut -d: -f1`
72+
scriptlist=`echo $filelist | xargs -r file | \
73+
egrep ":.* (commands|script)" | cut -d: -f1`
74+
liblist=`echo $filelist | xargs -r file | \
75+
grep ":.*shared object" | cut -d : -f1`
76+
77+
# dependency list of the executable binaries and shared libraries
78+
cp /dev/null mytmpfilelist
79+
cp /dev/null mytmpfilelist2
80+
81+
# put PolarDB-PG libs before any other libs to let ldd take it first
82+
export LD_LIBRARY_PATH=${target_dir}/lib:$LD_LIBRARY_PATH:/usr/lib
83+
84+
# dependency list of all binaries and shared objects
85+
for f in $liblist $exelist; do
86+
ldd $f | awk '/=>/ {
87+
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/) {
88+
# printf "$s => $s\n", $1, $3
89+
print $3
90+
}
91+
}' >> mytmpfilelist
92+
done
93+
94+
# deduplicate
95+
cat mytmpfilelist | sort -u > mytmpfilelist2
96+
97+
for f in `cat mytmpfilelist2`; do
98+
ldd $f | awk '/=>/ {
99+
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/) {
100+
# printf "$s => $s\n", $1, $3
101+
print $3
102+
}
103+
}' >> mytmpfilelist
104+
done
105+
106+
# deduplicate
107+
cat mytmpfilelist | sort -u > mytmpfilelist2
108+
109+
# copy libraries if necessary
110+
for line in `cat mytmpfilelist2`; do
111+
base=`basename $line`
112+
dirpath=${target_dir}/lib
113+
filepath=$dirpath/$base
114+
115+
objdump -p $line | awk 'BEGIN { START=0; LIBNAME=""; }
116+
/^$/ { START=0; }
117+
/^Dynamic Section:$/ { START=1; }
118+
(START==1) && /NEEDED/ {
119+
print $2 ;
120+
}
121+
(START==2) && /^[A-Za-z]/ { START=3; }
122+
/^Version References:$/ { START=2; }
123+
(START==2) && /required from/ {
124+
sub(/:/, "", $3);
125+
LIBNAME=$3;
126+
}
127+
(START==2) && (LIBNAME!="") && ($4!="") && (($4~/^GLIBC_*/) || ($4~/^GCC_*/)) {
128+
print LIBNAME "(" $4 ")";
129+
}
130+
END { exit 0 }
131+
' > objdumpfile
132+
133+
has_private=
134+
if grep -q PRIVATE objdumpfile; then
135+
has_private=true
136+
fi
137+
138+
if [[ ! -f $filepath ]]; then
139+
if [[ $has_private != "true" ]]; then
140+
cp $line $dirpath
141+
echo $line $dirpath
142+
fi
143+
fi
144+
done
145+
146+
rm mytmpfilelist mytmpfilelist2 objdumpfile
147+
}
148+
149+
# install package dependencies
150+
polar_install_dependency $(pwd)/${pkgname}${prefix}
151+
cd ${buildroot}
152+
153+
dpkg --build ./${pkgname}

package/debian/control

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

0 commit comments

Comments
 (0)