From 88193a930ec558216a86a1af3af2ad5ff4069cba Mon Sep 17 00:00:00 2001 From: Tobias Florek Date: Wed, 8 Apr 2026 09:21:33 +0200 Subject: [PATCH] add first_last_agg extension Signed-off-by: Tobias Florek --- .github/workflows/bake.yml | 4 +++ first-last-agg/Dockerfile | 25 ++++++++++++++ first-last-agg/README.md | 67 +++++++++++++++++++++++++++++++++++++ first-last-agg/metadata.hcl | 35 +++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 first-last-agg/Dockerfile create mode 100644 first-last-agg/README.md create mode 100644 first-last-agg/metadata.hcl diff --git a/.github/workflows/bake.yml b/.github/workflows/bake.yml index efbbfb0..04fc6de 100644 --- a/.github/workflows/bake.yml +++ b/.github/workflows/bake.yml @@ -13,6 +13,7 @@ on: - postgis - pgaudit - pg-crash + - first-last-agg defaults: run: @@ -55,6 +56,9 @@ jobs: pg-crash: - 'pg-crash/**' - *shared + first-last-agg: + - 'first-last-agg/**' + - *shared # Compute a matrix containing the list of all extensions that have been modified - name: Compute matrix diff --git a/first-last-agg/Dockerfile b/first-last-agg/Dockerfile new file mode 100644 index 0000000..abd4172 --- /dev/null +++ b/first-last-agg/Dockerfile @@ -0,0 +1,25 @@ +ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie +FROM $BASE AS builder + +ARG PG_MAJOR +ARG EXT_VERSION + +USER 0 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends "postgresql-${PG_MAJOR}-first-last-agg=${EXT_VERSION}" + +FROM scratch +ARG PG_MAJOR + +# Licenses +COPY --from=builder /usr/share/doc/postgresql-${PG_MAJOR}-first-last-agg/copyright /licenses/postgresql-${PG_MAJOR}-first-last-agg/ + +# Libraries +COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/first_last_agg* /lib/ +COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/ /lib/bitcode/ + +# Share +COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/first_last_agg* /share/extension/ + +USER 65532:65532 diff --git a/first-last-agg/README.md b/first-last-agg/README.md new file mode 100644 index 0000000..10abf91 --- /dev/null +++ b/first-last-agg/README.md @@ -0,0 +1,67 @@ +# First-Last-Agg + +[First-Last-Agg](https://github.com/wulczer/first_last_agg) is a simple +extension providing two aggregate functions, last and first aggregate +functions, operating on any element type and returning the last or the first +value of the group. + +This image provides a convenient way to deploy and manage `first_last_agg` with +[CloudNativePG](https://cloudnative-pg.io/). + +## Usage + +### 1. Add the first_last_agg extension image to your Cluster + +Define the `first_last_agg` extension under the `postgresql.extensions` section of +your `Cluster` resource. For example: + +```yaml +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: cluster-first-last-agg +spec: + imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie + instances: 1 + + storage: + size: 1Gi + + postgresql: + extensions: + - name: first_last_agg + image: + # renovate: suite=trixie-pgdg depName=postgresql-18-first-last-agg + reference: ghcr.io/cloudnative-pg/first-last-agg:0.8.2-18-trixie +``` + +### 2. Enable the extension in a database + +You can install `first_last_agg` 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-first-last-agg-app +spec: + name: app + owner: app + cluster: + name: cluster-first-last-agg + extensions: + - name: first_last_agg + # renovate: suite=trixie-pgdg depName=postgresql-18-first-last-agg extractVersion=^(?\d+\.\d+\.\d+) + version: '0.8.2' +``` + +### 3. Verify installation + +Once the database is ready, connect to it with `psql` and run: + +```sql +\dx +``` + +You should see `first_last_agg` listed among the installed extensions. diff --git a/first-last-agg/metadata.hcl b/first-last-agg/metadata.hcl new file mode 100644 index 0000000..38c5726 --- /dev/null +++ b/first-last-agg/metadata.hcl @@ -0,0 +1,35 @@ +metadata = { + name = "first-last-agg" + sql_name = "first_last_agg" + image_name = "first-last-agg" + licenses = ["PostgreSQL"] + shared_preload_libraries = [] + postgresql_parameters = {} + extension_control_path = [] + dynamic_library_path = [] + ld_library_path = [] + bin_path = [] + env = {} + auto_update_os_libs = false + required_extensions = [] + create_extension = true + + versions = { + bookworm = { + "18" = { + // renovate: suite=bookworm-pgdg depName=postgresql-18-first-last-agg + package = "0.1.4-4-gd63ea3b-9.pgdg12+1" + // renovate: suite=bookworm-pgdg depName=postgresql-18-first-last-agg extractVersion=^(?\d+\.\d+\.\d+) + sql = "0.1.4" + } + } + trixie = { + "18" = { + // renovate: suite=trixie-pgdg depName=postgresql-18-first-last-agg + package = "0.1.4-4-gd63ea3b-9.pgdg13+1" + // renovate: suite=trixie-pgdg depName=postgresql-18-first-last-agg extractVersion=^(?\d+\.\d+\.\d+) + sql = "0.1.4" + } + } + } +}