From 04d4a2fa0a621d23e13b9e99ab36beed6ab15c00 Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Thu, 7 Nov 2024 16:36:36 +0100 Subject: [PATCH 1/9] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6e72e74..8e679da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM postgres:13-alpine AS base +FROM https://github.com/supabase/pg_jsonschema/blob/master/dockerfiles/db/Dockerfile AS base # Script to detect whether the database has finished initializing COPY ["true_isready.sh", "/usr/local/bin/"] From bdf35822be032bb1463c779e71cc7cbe95af7bad Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Thu, 7 Nov 2024 16:38:52 +0100 Subject: [PATCH 2/9] remove proto --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8e679da..e30bd1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM https://github.com/supabase/pg_jsonschema/blob/master/dockerfiles/db/Dockerfile AS base +FROM github.com/supabase/pg_jsonschema/blob/master/dockerfiles/db/Dockerfile AS base # Script to detect whether the database has finished initializing COPY ["true_isready.sh", "/usr/local/bin/"] From a372c8374d91540448f2638aa5f12cd99083339c Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Thu, 7 Nov 2024 16:40:01 +0100 Subject: [PATCH 3/9] Update Dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index e30bd1d..1340c87 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.4 FROM github.com/supabase/pg_jsonschema/blob/master/dockerfiles/db/Dockerfile AS base # Script to detect whether the database has finished initializing From 93238fab3e6fd8c637d279949f34db285cfd44f6 Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Thu, 7 Nov 2024 16:42:37 +0100 Subject: [PATCH 4/9] Update Dockerfile --- Dockerfile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Dockerfile b/Dockerfile index 1340c87..28d5f18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,13 @@ # syntax=docker/dockerfile:1.4 + +FROM alpine:3.19 AS downloader +RUN apk add --no-cache curl +RUN curl -o Dockerfile.pg_jsonschema https://raw.githubusercontent.com/supabase/pg_jsonschema/master/dockerfiles/db/Dockerfile + +FROM scratch AS pg_jsonschema +COPY --from=downloader Dockerfile.pg_jsonschema . + +FROM pg_jsonschema AS base FROM github.com/supabase/pg_jsonschema/blob/master/dockerfiles/db/Dockerfile AS base # Script to detect whether the database has finished initializing From 05cdf980c180359d143db0aa7a9f98ba9a5e14bb Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Thu, 7 Nov 2024 16:43:29 +0100 Subject: [PATCH 5/9] Update Dockerfile --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 28d5f18..9334043 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,8 +8,6 @@ FROM scratch AS pg_jsonschema COPY --from=downloader Dockerfile.pg_jsonschema . FROM pg_jsonschema AS base -FROM github.com/supabase/pg_jsonschema/blob/master/dockerfiles/db/Dockerfile AS base - # Script to detect whether the database has finished initializing COPY ["true_isready.sh", "/usr/local/bin/"] COPY ["database scripts/00_dump.sql", "database scripts/0[2345]_*.sql", "database scripts/json_schema_extension.sql", "/docker-entrypoint-initdb.d/"] From 4d0260f542566adc727dd7b0f443bd9db74e5e78 Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Thu, 7 Nov 2024 16:53:03 +0100 Subject: [PATCH 6/9] Update Dockerfile --- Dockerfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9334043..7ab83c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,16 @@ # syntax=docker/dockerfile:1.4 FROM alpine:3.19 AS downloader -RUN apk add --no-cache curl -RUN curl -o Dockerfile.pg_jsonschema https://raw.githubusercontent.com/supabase/pg_jsonschema/master/dockerfiles/db/Dockerfile +RUN apk add --no-cache git +RUN git clone https://github.com/supabase/pg_jsonschema.git +WORKDIR /pg_jsonschema +RUN ln -s dockerfiles/db/Dockerfile Dockerfile.pg_jsonschema FROM scratch AS pg_jsonschema -COPY --from=downloader Dockerfile.pg_jsonschema . +COPY --from=downloader /pg_jsonschema / FROM pg_jsonschema AS base + # Script to detect whether the database has finished initializing COPY ["true_isready.sh", "/usr/local/bin/"] COPY ["database scripts/00_dump.sql", "database scripts/0[2345]_*.sql", "database scripts/json_schema_extension.sql", "/docker-entrypoint-initdb.d/"] From e1d9d80538fd8416f5bc1883bbd381104a43f87c Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Thu, 7 Nov 2024 16:57:43 +0100 Subject: [PATCH 7/9] Update Dockerfile --- Dockerfile | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7ab83c0..6d2f8c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,47 @@ -# syntax=docker/dockerfile:1.4 +#https://github.com/supabase/pg_jsonschema/blob/master/dockerfiles/db/Dockerfile +FROM postgres:16 as base +RUN apt-get update -FROM alpine:3.19 AS downloader -RUN apk add --no-cache git -RUN git clone https://github.com/supabase/pg_jsonschema.git -WORKDIR /pg_jsonschema -RUN ln -s dockerfiles/db/Dockerfile Dockerfile.pg_jsonschema +ENV build_deps ca-certificates \ + git \ + build-essential \ + libpq-dev \ + postgresql-server-dev-16 \ + curl \ + libreadline6-dev \ + zlib1g-dev -FROM scratch AS pg_jsonschema -COPY --from=downloader /pg_jsonschema / -FROM pg_jsonschema AS base +RUN apt-get install -y --no-install-recommends $build_deps pkg-config cmake + +WORKDIR /home/supa + +ENV HOME=/home/supa \ + PATH=/home/supa/.cargo/bin:$PATH +RUN chown postgres:postgres /home/supa +USER postgres + +RUN \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain stable && \ + rustup --version && \ + rustc --version && \ + cargo --version + +# PGX +RUN cargo install cargo-pgrx --version 0.12.6 --locked + +RUN cargo pgrx init --pg16 $(which pg_config) + +USER root + +COPY . . +RUN cargo pgrx install + +RUN chown -R postgres:postgres /home/supa +RUN chown -R postgres:postgres /usr/share/postgresql/16/extension +RUN chown -R postgres:postgres /usr/lib/postgresql/16/lib + +USER postgres # Script to detect whether the database has finished initializing COPY ["true_isready.sh", "/usr/local/bin/"] From 59b7e441be913d29f73751b0b6d4aaf353bc335b Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Fri, 8 Nov 2024 09:35:33 +0100 Subject: [PATCH 8/9] Update Dockerfile --- Dockerfile | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6d2f8c7..b0f8fcf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,9 @@ #https://github.com/supabase/pg_jsonschema/blob/master/dockerfiles/db/Dockerfile -FROM postgres:16 as base +FROM alpine:3.19 AS downloader +RUN apk add --no-cache git +RUN git clone https://github.com/supabase/pg_jsonschema.git --depth 1 + +FROM postgres:16 RUN apt-get update ENV build_deps ca-certificates \ @@ -15,10 +19,10 @@ ENV build_deps ca-certificates \ RUN apt-get install -y --no-install-recommends $build_deps pkg-config cmake WORKDIR /home/supa - +COPY --from=downloader /pg_jsonschema ./ ENV HOME=/home/supa \ PATH=/home/supa/.cargo/bin:$PATH -RUN chown postgres:postgres /home/supa +RUN chown postgres:postgres /home/supa -R USER postgres RUN \ @@ -42,16 +46,3 @@ RUN chown -R postgres:postgres /usr/share/postgresql/16/extension RUN chown -R postgres:postgres /usr/lib/postgresql/16/lib USER postgres - -# Script to detect whether the database has finished initializing -COPY ["true_isready.sh", "/usr/local/bin/"] -COPY ["database scripts/00_dump.sql", "database scripts/0[2345]_*.sql", "database scripts/json_schema_extension.sql", "/docker-entrypoint-initdb.d/"] - -# Install https://github.com/gavinwahl/postgres-json-schema/ -# extension that allows validation of jsonb fields against jsonschema -COPY ["install_postgres_json_schema_extension.sh", "install_postgres_json_schema_extension.sh"] -RUN chmod u+x install_postgres_json_schema_extension.sh -RUN ./install_postgres_json_schema_extension.sh - -FROM base AS demo -COPY ["database scripts/demo_db.sql", "/docker-entrypoint-initdb.d/"] From d3db2c0e2e58812ee7fc79fe1a65a6668270e067 Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Thu, 14 Nov 2024 11:41:41 +0100 Subject: [PATCH 9/9] Update install_postgres_json_schema_extension.sh --- install_postgres_json_schema_extension.sh | 45 ++++++++++++++++++----- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/install_postgres_json_schema_extension.sh b/install_postgres_json_schema_extension.sh index 38889d0..e491409 100644 --- a/install_postgres_json_schema_extension.sh +++ b/install_postgres_json_schema_extension.sh @@ -1,20 +1,47 @@ #!/bin/bash -apk add --update make -apk add --update git + +# Detect the operating system +if [ -f /etc/os-release ]; then + . /etc/os-release + OS=$NAME +else + OS=$(uname -s) +fi + +# Function to install packages on Alpine +install_alpine() { + apk add --update $@ +} + +# Function to install packages on Ubuntu +install_ubuntu() { + apt-get update + apt-get install -y $@ +} + +# Install packages based on the detected OS +if [[ "$OS" == *"Alpine"* ]]; then + echo "Detected Alpine Linux" + install_alpine make git libpq-dev postgresql-client +elif [[ "$OS" == *"Ubuntu"* ]]; then + echo "Detected Ubuntu" + install_ubuntu make git libpq-dev postgresql-client +else + echo "Unsupported operating system: $OS" + exit 1 +fi # Clone the repository git clone https://github.com/gavinwahl/postgres-json-schema/ -apk add libpq-dev # Move into the directory cd postgres-json-schema # Build the extension -make & make install - - -apk add postgresql-client +make && make install -/bin/mkdir -p '/usr/local/share/postgresql/extension' +# Create the extension directory if it doesn't exist +mkdir -p '/usr/local/share/postgresql/extension' -chmod 666 /usr/local/share/postgresql/extension/postgres-json-schema.control +# Set appropriate permissions for the control file +chmod 644 /usr/local/share/postgresql/extension/postgres-json-schema.control