From 81a6eb7b654101d7b0b133aed0e2fd661359c7e0 Mon Sep 17 00:00:00 2001 From: Michal Zander <mzander@syncad.com> Date: Fri, 19 Apr 2024 13:53:50 +0000 Subject: [PATCH] Add postgrest setup --- Dockerfile | 14 +++++++- postgrest.conf | 7 ++++ scripts/ci/start_postgrest.sh | 60 +++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 postgrest.conf create mode 100755 scripts/ci/start_postgrest.sh diff --git a/Dockerfile b/Dockerfile index 5c4f8638c..4f54261b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,10 @@ # Base docker file having defined environment for build and run of a Hivemind instance. # Use scripts/ci/build_ci_base_image.sh to build a new version of the CI base image. It must be properly tagged and pushed to the container registry. +ARG POSTGREST_VERSION=v12.0.2 + +FROM postgrest/postgrest:${POSTGREST_VERSION} AS pure_postgrest + FROM --platform=$BUILDPLATFORM python:3.8-slim as runtime ARG TARGETPLATFORM @@ -96,12 +100,19 @@ ARG HTTP_PORT=8080 ENV HTTP_PORT=${HTTP_PORT} # Lets use by default host address from default docker bridge network -ARG POSTGRES_URL="postgresql://hivemind@172.17.0.1/haf_block_log" +ARG POSTGRES_URL="postgresql://hivemind@haf-instance:5432/haf_block_log" ENV POSTGRES_URL=${POSTGRES_URL} ARG POSTGRES_ADMIN_URL="postgresql://haf_admin@172.17.0.1:5432/haf_block_log" ENV POSTGRES_ADMIN_URL=${POSTGRES_ADMIN_URL} +ARG USE_POSTGREST=1 +ENV USE_POSTGREST=${USE_POSTGREST} + +ENV PGRST_DB_SCHEMA="hivemind_endpoints" +ENV PGRST_DB_ANON_ROLE="hivemind" +ENV PGRST_DB_ROOT_SPEC="home" + ENV LANG=en_US.UTF-8 USER hivemind @@ -109,6 +120,7 @@ WORKDIR /home/hivemind SHELL ["/bin/bash", "-c"] +COPY --chmod=755 --from=pure_postgrest /bin/postgrest /usr/local/bin COPY --from=builder --chown=hivemind:hivemind /home/hivemind/app/dist /home/hivemind/dist COPY --from=builder --chown=hivemind:hivemind /home/hivemind/.hivemind-venv /home/hivemind/.hivemind-venv COPY --from=builder --chown=hivemind:hivemind /home/hivemind/app/docker/docker_entrypoint.sh . diff --git a/postgrest.conf b/postgrest.conf new file mode 100644 index 000000000..1ed102f28 --- /dev/null +++ b/postgrest.conf @@ -0,0 +1,7 @@ +db-uri = "postgres://haf_admin@/haf_block_log" +db-schema = "hivemind_endpoints" +db-anon-role = "hivemind" +db-pool = 20 +db-pool-acquisition-timeout = 10 +server-port = 3000 +admin-server-port = 3001 \ No newline at end of file diff --git a/scripts/ci/start_postgrest.sh b/scripts/ci/start_postgrest.sh new file mode 100755 index 000000000..535ce8c15 --- /dev/null +++ b/scripts/ci/start_postgrest.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +set -e +set -o pipefail + +POSTGRES_HOST="localhost" +POSTGRES_PORT=5432 +POSTGRES_USER="hivemind" +WEBSERVER_PORT=8080 +ADMIN_PORT=3001 + + + +while [ $# -gt 0 ]; do + case "$1" in + --host=*) + POSTGRES_HOST="${1#*=}" + ;; + --port=*) + POSTGRES_PORT="${1#*=}" + ;; + --user=*) + POSTGRES_USER="${1#*=}" + ;; + --webserver_port|--webserver-port=*) + WEBSERVER_PORT="${1#*=}" + ;; + --admin_port|--admin-port=*) + ADMIN_PORT="${1#*=}" + ;; + --postgres-url=*) + POSTGRES_URL="${1#*=}" + ;; + -*) + echo "ERROR: '$1' is not a valid option" + echo + exit 1 + ;; + *) + echo "ERROR: '$1' is not a valid argument" + echo + exit 2 + ;; + esac + shift +done + +POSTGRES_ACCESS=${POSTGRES_URL:-"postgresql://$POSTGRES_USER@$POSTGRES_HOST:$POSTGRES_PORT/haf_block_log"} + +start_webserver() { + export PGRST_DB_URI=$POSTGRES_ACCESS + export PGRST_SERVER_PORT=$WEBSERVER_PORT + export PGRST_ADMIN_SERVER_PORT=$ADMIN_PORT + export PGRST_DB_ROOT_SPEC="home" + + postgrest postgrest.conf +} + +start_webserver & + -- GitLab