Skip to content

Commit 4f1cbeb

Browse files
committed
chore: handle tsdb extension install from deb package
We are currently building the extension for each supported PG version. This change makes the script to install the deb package directly from the repository (packagecloud). As a condition, deb builds will happen only for semver formatted versions >= 2.24.0. Also, cleaning up a bit the version compatibility matrix, removing unsupported TS versions checks (as we are now only building for PG 15-18).
1 parent 6e17b36 commit 4f1cbeb

File tree

3 files changed

+177
-97
lines changed

3 files changed

+177
-97
lines changed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,19 @@ ARG OSS_ONLY
384384
# RUST_RELEASE for some packages passes this to --profile
385385
ARG RUST_RELEASE=release
386386

387+
USER root
388+
387389
# split the extension builds into two steps to allow caching of successful steps
390+
ARG ALLOW_ADDING_EXTENSIONS=true
388391
ARG GITHUB_REPO=timescale/timescaledb
389392
ARG TIMESCALEDB_VERSIONS
390393
RUN OSS_ONLY="${OSS_ONLY}" \
391394
GITHUB_REPO="${GITHUB_REPO}" \
392395
TIMESCALEDB_VERSIONS="${TIMESCALEDB_VERSIONS}" \
393396
/build/scripts/install_extensions timescaledb
394397

398+
USER postgres
399+
395400
# install all rust packages in the same step to allow it to optimize for cargo-pgx installs
396401
ARG TOOLKIT_VERSIONS
397402
RUN OSS_ONLY="${OSS_ONLY}" \

build_scripts/shared_install.sh

Lines changed: 172 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,201 @@
22

33
# these are the functions that perform the actual installations/builds of the extensions
44

5+
get_package_suffix() {
6+
local distro="${DISTRO:-}"
7+
local version="${DISTRO_VERSION:-}"
8+
9+
case "${distro}:${version}" in
10+
ubuntu:jammy) echo "~ubuntu22.04" ;;
11+
ubuntu:noble) echo "~ubuntu24.04" ;;
12+
*)
13+
echo "Unsupported distribution: ${distro} ${version}" >&2
14+
return 1
15+
;;
16+
esac
17+
}
18+
19+
construct_package_name() {
20+
local pg_version=$1
21+
local ts_version=$2
22+
local package_suffix=$3
23+
local oss_only="${OSS_ONLY:-}"
24+
local arch="${ARCH:-}"
25+
26+
if [ "${oss_only}" = true ]; then
27+
# example: timescaledb-2-oss-postgresql-18=2.23.0~ubuntu24.04
28+
echo "timescaledb-2-oss-postgresql-${pg_version}=${ts_version}${package_suffix}"
29+
else
30+
# example: timescaledb-2-2.23.0-postgresql-18=2.23.0~ubuntu24.04
31+
echo "timescaledb-2-${ts_version}-postgresql-${pg_version}=${ts_version}${package_suffix}"
32+
fi
33+
}
34+
35+
construct_loader_package_name() {
36+
local pg_version=$1
37+
local ts_version=$2
38+
local package_suffix=$3
39+
40+
# example: timescaledb-2-loader-postgresql-18=2.23.0~ubuntu24.04
41+
echo "timescaledb-2-loader-postgresql-${pg_version}=${ts_version}${package_suffix}"
42+
}
43+
44+
ensure_packagecloud_repo() {
45+
if apt-cache policy | grep -qi "packagecloud.io/timescale/timescaledb"; then
46+
log "timescale packagecloud repository already configured, skipping re-add."
47+
apt-get update -y
48+
return 0
49+
fi
50+
51+
log "configuring Timescale packagecloud repository..."
52+
curl -fsSL https://packagecloud.io/timescale/timescaledb/gpgkey | gpg --dearmor > /etc/apt/keyrings/timescale_timescaledb-archive-keyring.gpg
53+
echo "deb [signed-by=/etc/apt/keyrings/timescale_timescaledb-archive-keyring.gpg] https://packagecloud.io/timescale/timescaledb/ubuntu \
54+
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") main" \
55+
> /etc/apt/sources.list.d/timescale_timescaledb.list
56+
apt-get update -y
57+
}
58+
59+
install_timescaledb_for_pg_version() {
60+
local pg_version=$1
61+
local ts_version=$2
62+
local package_suffix
63+
local loader_package
64+
local main_package
65+
66+
package_suffix=$(get_package_suffix "${ts_version}")
67+
log "package suffix: ${package_suffix}"
68+
69+
# construct package names
70+
loader_package=$(construct_loader_package_name "${pg_version}" "${ts_version}" "${package_suffix}")
71+
main_package=$(construct_package_name "${pg_version}" "${ts_version}" "${package_suffix}")
72+
73+
log "loader package: ${loader_package}"
74+
log "main package: ${main_package}"
75+
76+
# install loader
77+
if ! apt-get install "${loader_package}" "${main_package}" -y; then
78+
apt-get update -f -y # fix dependencies
79+
error "failed to install loader package"
80+
fi
81+
82+
# Install extension
83+
if ! apt-get install "${main_package}" -y; then
84+
apt-get update -f -y
85+
error "failed to install main package"
86+
fi
87+
88+
log "successfully installed TimescaleDB ${ts_version} for PostgreSQL ${pg_version}"
89+
}
90+
591
install_timescaledb() {
692
local version="$1" pg pkg=timescaledb unsupported_reason oss_only=""
793
[ "$OSS_ONLY" = true ] && oss_only="-DAPACHE_ONLY=1"
894

95+
ensure_packagecloud_repo
96+
97+
ARCH=$(dpkg --print-architecture)
98+
log "detected architecture: ${ARCH}"
99+
100+
# map OS to packagecloud naming
101+
if [ -f /etc/os-release ]; then
102+
. /etc/os-release
103+
OS_ID="${ID}"
104+
OS_VERSION_CODENAME="${VERSION_CODENAME}"
105+
else
106+
error "cannot detect OS distribution"
107+
exit 1
108+
fi
109+
110+
DISTRO="${OS_ID}"
111+
DISTRO_VERSION="${OS_VERSION_CODENAME}"
112+
9113
for pg in $(available_pg_versions); do
10114
unsupported_reason="$(supported_timescaledb "$pg" "$version")"
11115
if [ -n "$unsupported_reason" ]; then
12116
log "$pkg-$version: $unsupported_reason"
13117
continue
14118
fi
15119

16-
log "building $pkg-$version for pg$pg"
17-
18-
[[ "$DRYRUN" = true ]] && continue
120+
if [[ "$version" = main && "$pg" -lt 14 ]]; then
121+
log "$pkg-$version: unsupported for < pg14"
122+
continue
123+
fi
19124

20-
PATH="/usr/lib/postgresql/$pg/bin:${ORIGINAL_PATH}"
21-
git_clone "https://github.com/${GITHUB_REPO}" "$pkg" || continue
22-
git_checkout $pkg "$version" || continue
23-
(
24-
set -e
25-
cd /build/$pkg
125+
log "installing $pkg-$version for pg$pg"
26126

27-
[ "$version" = "2.2.0" ] && sed -i 's/RelWithDebugInfo/RelWithDebInfo/g' CMakeLists.txt
127+
[[ "$DRYRUN" = true ]] && continue
28128

29-
# Set architecture-specific flags
30-
local cmake_c_flags=""
31-
# this part could use a more precise check, but most modern ARM CPUs already support
32-
# +crypto extensions, so in reality we can just rely on the architecture.
33-
if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then
34-
cmake_c_flags="-DCMAKE_C_FLAGS=-march=armv8.2-a+crypto"
129+
# use deb packages only with timescaledb versions >= 2.24
130+
# skip deb install for branch names (main, feature/foo, etc.) and build from source instead
131+
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]] && [ "$(printf '%s\n' "$version" "2.24.0" | sort -V | tail -n1)" = "$version" ]; then
132+
log "installing deb package for $pkg-$version for pg$pg"
133+
134+
install_timescaledb_for_pg_version "${pg}" "${version}"
135+
err=$?
136+
137+
if [ $err -eq 0 ]; then
138+
log "installed $pkg-$version for pg$pg"
139+
else
140+
error "failed install $pkg-$version for pg$pg ($err)"
35141
fi
36142

37-
./bootstrap \
38-
-DTAP_CHECKS=OFF \
39-
-DWARNINGS_AS_ERRORS=off \
40-
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
41-
-DREGRESS_CHECKS=OFF \
42-
-DGENERATE_DOWNGRADE_SCRIPT=ON \
43-
-DPROJECT_INSTALL_METHOD="${INSTALL_METHOD}" \
44-
-DUSE_UMASH=1 \
45-
${cmake_c_flags} \
46-
${oss_only}
47-
48-
cd build
49-
50-
make
51-
52-
# https://github.com/timescale/timescaledb/commit/531f7ed8b16e4d1a99021d3d2b843bbc939798e3
53-
[ "$version" = "2.5.2" ] && sed -i 's/pg_temp./_timescaledb_internal./g' sql/**/*.sql
54-
55-
make install
56-
57143
if [ "$OSS_ONLY" = true ]; then
58144
log "removing timescaledb-tsl due to OSS_ONLY"
59145
rm -f /usr/lib/postgresql/"$pg"/lib/timescaledb-tsl-*
60146
fi
61-
)
62-
err=$?
63-
if [ $err -eq 0 ]; then
64-
log "installed $pkg-$version for pg$pg"
65147
else
66-
error "failed building $pkg-$version for pg$pg ($err)"
148+
log "building $pkg-$version for pg$pg"
149+
150+
PATH="/usr/lib/postgresql/$pg/bin:${ORIGINAL_PATH}"
151+
git_clone "https://github.com/${GITHUB_REPO}" "$pkg" || continue
152+
git_checkout $pkg "$version" || continue
153+
(
154+
set -e
155+
cd /build/$pkg
156+
157+
[ "$version" = "2.2.0" ] && sed -i 's/RelWithDebugInfo/RelWithDebInfo/g' CMakeLists.txt
158+
159+
# Set architecture-specific flags
160+
local cmake_c_flags=""
161+
# this part could use a more precise check, but most modern ARM CPUs already support
162+
# +crypto extensions, so in reality we can just rely on the architecture.
163+
if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then
164+
cmake_c_flags="-DCMAKE_C_FLAGS=-march=armv8.2-a+crypto"
165+
fi
166+
167+
./bootstrap \
168+
-DTAP_CHECKS=OFF \
169+
-DWARNINGS_AS_ERRORS=off \
170+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
171+
-DREGRESS_CHECKS=OFF \
172+
-DGENERATE_DOWNGRADE_SCRIPT=ON \
173+
-DPROJECT_INSTALL_METHOD="${INSTALL_METHOD}" \
174+
-DUSE_UMASH=1 \
175+
${cmake_c_flags} \
176+
${oss_only}
177+
178+
cd build
179+
180+
make
181+
182+
# https://github.com/timescale/timescaledb/commit/531f7ed8b16e4d1a99021d3d2b843bbc939798e3
183+
[ "$version" = "2.5.2" ] && sed -i 's/pg_temp./_timescaledb_internal./g' sql/**/*.sql
184+
185+
make install
186+
187+
if [ "$OSS_ONLY" = true ]; then
188+
log "removing timescaledb-tsl due to OSS_ONLY"
189+
rm -f /usr/lib/postgresql/"$pg"/lib/timescaledb-tsl-*
190+
fi
191+
)
192+
err=$?
193+
if [ $err -eq 0 ]; then
194+
log "installed $pkg-$version for pg$pg"
195+
else
196+
error "failed building $pkg-$version for pg$pg ($err)"
197+
fi
67198
fi
68199
done
69-
PATH="$ORIGINAL_PATH"
70200
}
71201

72202
install_toolkit() {

build_scripts/versions.yaml

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -35,61 +35,6 @@ postgres_versions:
3535
13: 13.22
3636

3737
timescaledb:
38-
2.1.0:
39-
pg: [13]
40-
2.1.1:
41-
pg-max: 13
42-
2.2.0:
43-
pg-max: 13
44-
2.2.1:
45-
pg-max: 13
46-
2.3.0:
47-
pg-max: 13
48-
2.3.1:
49-
pg-max: 13
50-
2.4.0:
51-
pg-max: 13
52-
2.4.1:
53-
pg-max: 13
54-
2.4.2:
55-
pg-max: 13
56-
2.5.0:
57-
pg-max: 14
58-
2.5.1:
59-
pg-max: 14
60-
2.5.2:
61-
pg-max: 14
62-
2.6.0:
63-
pg-max: 14
64-
2.6.1:
65-
pg-max: 14
66-
2.7.0:
67-
pg-max: 14
68-
2.7.1:
69-
pg-max: 14
70-
2.7.2:
71-
pg-max: 14
72-
2.8.0:
73-
pg-max: 14
74-
2.8.1:
75-
pg-max: 14
76-
2.9.0:
77-
2.9.1:
78-
2.9.2:
79-
2.9.3:
80-
2.10.0:
81-
2.10.1:
82-
2.10.2:
83-
2.10.3:
84-
2.11.0:
85-
2.11.1:
86-
2.11.2:
87-
2.12.0:
88-
pg-min: 13
89-
2.12.1:
90-
pg-min: 13
91-
2.12.2:
92-
pg-min: 13
9338
2.13.0:
9439
pg-min: 13
9540
pg-max: 16

0 commit comments

Comments
 (0)