diff --git a/.github/workflows/bake.yml b/.github/workflows/bake.yml index bf45b5d..28293ec 100644 --- a/.github/workflows/bake.yml +++ b/.github/workflows/bake.yml @@ -11,6 +11,7 @@ on: options: - pgvector - postgis + - timescaledb - pgaudit defaults: @@ -48,6 +49,8 @@ jobs: - *shared postgis: - 'postgis/**' + timescaledb: + - 'timescaledb/**' - *shared pgaudit: - 'pgaudit/**' diff --git a/timescaledb/Dockerfile b/timescaledb/Dockerfile new file mode 100644 index 0000000..9206a69 --- /dev/null +++ b/timescaledb/Dockerfile @@ -0,0 +1,36 @@ + +ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie +FROM $BASE AS builder + +ARG PG_MAJOR +ARG EXT_VERSION + +USER 0 +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends gnupg postgresql-common apt-transport-https lsb-release wget ca-certificates; \ + # Add TimescaleDB package repository + echo "deb https://packagecloud.io/timescale/timescaledb/debian/ $(lsb_release -c -s) main" > /etc/apt/sources.list.d/timescaledb.list; \ + wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | gpg --dearmor -o /etc/apt/trusted.gpg.d/timescaledb.gpg; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + timescaledb-2-postgresql-${PG_MAJOR}=${EXT_VERSION}* \ + timescaledb-2-loader-postgresql-${PG_MAJOR}=${EXT_VERSION}* + +###################################################################### +# Final SCRATCH image +###################################################################### +FROM scratch +ARG PG_MAJOR + +# Licenses +COPY --from=builder /usr/share/doc/timescaledb-2-postgresql-${PG_MAJOR}/copyright /licenses/timescaledb/ + +# Libraries — .so and bitcode for TimescaleDB +COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb* /lib/ +COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb-2* /lib/ + +# Extension SQL + control files +COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/timescaledb* /share/extension/ + +USER 65532:65532 \ No newline at end of file diff --git a/timescaledb/README.md b/timescaledb/README.md new file mode 100644 index 0000000..7a9c215 --- /dev/null +++ b/timescaledb/README.md @@ -0,0 +1,67 @@ +# TimescaleDB with CloudNativePG + +[TimescaleDB](https://github.com/timescale/timescaledb) is the leading open-source time-series database, built on PostgreSQL. It enables fast analytics, efficient storage, and powerful querying for time-series workloads. + +This image provides a convenient way to deploy and manage `TimescaleDB` with +[CloudNativePG](https://cloudnative-pg.io/). + +## Usage + +### 1. Add the timescaledb extension image to your Cluster + +Define the `timescaledb` extension under the `postgresql.extensions` section of +your `Cluster` resource. For example: + +```yaml +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: cluster-timescaledb +spec: + imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie + instances: 1 + + storage: + size: 1Gi + + postgresql: + shared_preload_libraries: + - "timescaledb" + parameters: + timescaledb.telemetry_level: 'off' + max_locks_per_transaction: '128' + + extensions: + - name: timescaledb + image: + reference: ghcr.io/cloudnative-pg/timescaledb:2.23.1-18-trixie +``` + +### 2. Enable the extension in a database + +You can install `timescaledb` in a specific database by creating or updating a +`Database` resource. For example, to enable it in the `app` database: + +```yaml +apiVersion: postgresql.cnpg.io/v1 +kind: Database +metadata: + name: cluster-timescaledb-app +spec: + name: app + owner: app + cluster: + name: cluster-timescaledb + extensions: + - name: timescaledb +``` + +### 3. Verify installation + +Once the database is ready, connect to it with `psql` and run: + +```sql +\dx +``` + +You should see `timescaledb` listed among the installed extensions. diff --git a/timescaledb/metadata.hcl b/timescaledb/metadata.hcl new file mode 100644 index 0000000..1ea21d4 --- /dev/null +++ b/timescaledb/metadata.hcl @@ -0,0 +1,19 @@ +metadata = { + name = "timescaledb" + sql_name = "timescaledb" + image_name = "timescaledb" + shared_preload_libraries = ["timescaledb"] + extension_control_path = [] + dynamic_library_path = [] + ld_library_path = [] + versions = { + bookworm = { + // renovate: datasource=postgresql depName=timescaledb-2-postgresql-18 versioning=deb + "18" = "2.23.1~debian12-1800" + } + trixie = { + // renovate: datasource=postgresql depName=timescaledb-2-postgresql-18 versioning=deb + "18" = "2.23.1~debian13-1800" + } + } +} \ No newline at end of file