From d54134048b644c662b80e2619392ad3bb12413dc Mon Sep 17 00:00:00 2001 From: Enno Richter Date: Tue, 10 Feb 2026 21:38:15 +0100 Subject: [PATCH] Add pg-jsonschema extension target Signed-off-by: Enno Richter --- README.md | 1 + pg-jsonschema/Dockerfile | 55 ++++++++++++++++++++++++++++++++ pg-jsonschema/README.md | 65 ++++++++++++++++++++++++++++++++++++++ pg-jsonschema/metadata.hcl | 22 +++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 pg-jsonschema/Dockerfile create mode 100644 pg-jsonschema/README.md create mode 100644 pg-jsonschema/metadata.hcl diff --git a/README.md b/README.md index d45e7bd..785fdc2 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ they are maintained by their respective authors, and PostgreSQL Debian Group | Extension | Description | Project URL | | :--- | :--- | :--- | | **[pgAudit](pgaudit)** | PostgreSQL audit extension | [https://github.com/pgaudit/pgaudit](https://github.com/pgaudit/pgaudit) | +| **[pg-jsonschema](pg-jsonschema)** | JSON Schema validation for PostgreSQL `json` and `jsonb` data | [https://github.com/supabase/pg_jsonschema](https://github.com/supabase/pg_jsonschema) | | **[pgvector](pgvector)** | Vector similarity search for PostgreSQL | [https://github.com/pgvector/pgvector](https://github.com/pgvector/pgvector) | | **[PostGIS](postgis)** | Geospatial database extension for PostgreSQL | [https://postgis.net/](https://postgis.net/) | diff --git a/pg-jsonschema/Dockerfile b/pg-jsonschema/Dockerfile new file mode 100644 index 0000000..76dc7c8 --- /dev/null +++ b/pg-jsonschema/Dockerfile @@ -0,0 +1,55 @@ +ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie +FROM $BASE AS builder + +ARG PG_MAJOR +ARG EXT_VERSION +ARG PGRX_VERSION=0.16.1 + +USER 0 + +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + git \ + build-essential \ + libpq-dev \ + "postgresql-server-dev-${PG_MAJOR}" \ + pkg-config \ + cmake \ + clang \ + libclang-dev; \ + rm -rf /var/lib/apt/lists/* + +ENV PATH=/root/.cargo/bin:${PATH} + +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain stable +RUN cargo install cargo-pgrx --version "${PGRX_VERSION}" --locked +RUN cargo pgrx init --pg"${PG_MAJOR}"=/usr/lib/postgresql/"${PG_MAJOR}"/bin/pg_config + +WORKDIR /tmp +RUN set -eux; \ + curl -fsSL -o pg_jsonschema.tar.gz "https://github.com/supabase/pg_jsonschema/archive/refs/tags/v${EXT_VERSION}.tar.gz"; \ + tar -xzf pg_jsonschema.tar.gz; \ + mv "pg_jsonschema-${EXT_VERSION}" pg_jsonschema + +WORKDIR /tmp/pg_jsonschema +RUN set -eux; \ + cargo pgrx install --release --no-default-features --features "pg${PG_MAJOR}" --pg-config /usr/lib/postgresql/"${PG_MAJOR}"/bin/pg_config + +RUN install -D -m 0644 /tmp/pg_jsonschema/LICENSE /licenses/pg_jsonschema/LICENSE + +FROM scratch +ARG PG_MAJOR + +# Licenses +COPY --from=builder /licenses /licenses/ + +# Libraries +COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_jsonschema.so /lib/ + +# Share +COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/pg_jsonschema* /share/extension/ + +USER 65532:65532 diff --git a/pg-jsonschema/README.md b/pg-jsonschema/README.md new file mode 100644 index 0000000..0e88f26 --- /dev/null +++ b/pg-jsonschema/README.md @@ -0,0 +1,65 @@ +# pg_jsonschema + +[pg_jsonschema](https://github.com/supabase/pg_jsonschema) is a PostgreSQL +extension that adds JSON Schema validation for `json` and `jsonb` data. + +This image provides a convenient way to deploy and manage `pg_jsonschema` with +[CloudNativePG](https://cloudnative-pg.io/). + +## Usage + +### 1. Add the extension image to your Cluster + +Define the `pg-jsonschema` extension under the `postgresql.extensions` section +of your `Cluster` resource. For example: + +```yaml +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: cluster-pg-jsonschema +spec: + imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie + instances: 1 + + storage: + size: 1Gi + + postgresql: + extensions: + - name: pg-jsonschema + image: + # renovate: datasource=github-tags depName=supabase/pg_jsonschema versioning=semver extractVersion=^v(?.*)$ + reference: ghcr.io/cloudnative-pg/pg-jsonschema:0.3.4-18-trixie +``` + +### 2. Enable the extension in a database + +Create or update a `Database` resource to install the extension in a specific +database: + +```yaml +apiVersion: postgresql.cnpg.io/v1 +kind: Database +metadata: + name: cluster-pg-jsonschema-app +spec: + name: app + owner: app + cluster: + name: cluster-pg-jsonschema + extensions: + - name: pg_jsonschema + # renovate: datasource=github-tags depName=supabase/pg_jsonschema versioning=semver extractVersion=^v(?.*)$ + version: "0.3.4" +``` + +### 3. Verify installation + +Once the database is ready, connect to it with `psql` and run: + +```sql +\dx +``` + +You should see `pg_jsonschema` listed among the installed extensions. diff --git a/pg-jsonschema/metadata.hcl b/pg-jsonschema/metadata.hcl new file mode 100644 index 0000000..e1170e1 --- /dev/null +++ b/pg-jsonschema/metadata.hcl @@ -0,0 +1,22 @@ +metadata = { + name = "pg-jsonschema" + sql_name = "pg_jsonschema" + image_name = "pg-jsonschema" + shared_preload_libraries = [] + extension_control_path = [] + dynamic_library_path = [] + ld_library_path = [] + auto_update_os_libs = false + required_extensions = [] + + versions = { + bookworm = { + // renovate: datasource=github-tags depName=supabase/pg_jsonschema versioning=semver extractVersion=^v(?.*)$ + "18" = "0.3.4" + } + trixie = { + // renovate: datasource=github-tags depName=supabase/pg_jsonschema versioning=semver extractVersion=^v(?.*)$ + "18" = "0.3.4" + } + } +}