|
2 | 2 |
|
3 | 3 | # these are the functions that perform the actual installations/builds of the extensions |
4 | 4 |
|
| 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 | + |
5 | 91 | install_timescaledb() { |
6 | 92 | local version="$1" pg pkg=timescaledb unsupported_reason oss_only="" |
7 | 93 | [ "$OSS_ONLY" = true ] && oss_only="-DAPACHE_ONLY=1" |
8 | 94 |
|
| 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 | + |
9 | 113 | for pg in $(available_pg_versions); do |
10 | 114 | unsupported_reason="$(supported_timescaledb "$pg" "$version")" |
11 | 115 | if [ -n "$unsupported_reason" ]; then |
12 | 116 | log "$pkg-$version: $unsupported_reason" |
13 | 117 | continue |
14 | 118 | fi |
15 | 119 |
|
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 |
19 | 124 |
|
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" |
26 | 126 |
|
27 | | - [ "$version" = "2.2.0" ] && sed -i 's/RelWithDebugInfo/RelWithDebInfo/g' CMakeLists.txt |
| 127 | + [[ "$DRYRUN" = true ]] && continue |
28 | 128 |
|
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)" |
35 | 141 | fi |
36 | 142 |
|
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 | | - |
57 | 143 | if [ "$OSS_ONLY" = true ]; then |
58 | 144 | log "removing timescaledb-tsl due to OSS_ONLY" |
59 | 145 | rm -f /usr/lib/postgresql/"$pg"/lib/timescaledb-tsl-* |
60 | 146 | fi |
61 | | - ) |
62 | | - err=$? |
63 | | - if [ $err -eq 0 ]; then |
64 | | - log "installed $pkg-$version for pg$pg" |
65 | 147 | 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 |
67 | 198 | fi |
68 | 199 | done |
69 | | - PATH="$ORIGINAL_PATH" |
70 | 200 | } |
71 | 201 |
|
72 | 202 | install_toolkit() { |
|
0 commit comments