diff --git a/Dockerfile b/Dockerfile index 6e72e74..b0f8fcf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,48 @@ -FROM postgres:13-alpine AS base +#https://github.com/supabase/pg_jsonschema/blob/master/dockerfiles/db/Dockerfile +FROM alpine:3.19 AS downloader +RUN apk add --no-cache git +RUN git clone https://github.com/supabase/pg_jsonschema.git --depth 1 -# 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 postgres:16 +RUN apt-get update -# 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 +ENV build_deps ca-certificates \ + git \ + build-essential \ + libpq-dev \ + postgresql-server-dev-16 \ + curl \ + libreadline6-dev \ + zlib1g-dev -FROM base AS demo -COPY ["database scripts/demo_db.sql", "/docker-entrypoint-initdb.d/"] + +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 -R +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 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