From e89bbd676d5cf3ceccc53965ada1a65fa91b4256 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Sun, 5 Jan 2025 07:32:57 +0530 Subject: [PATCH 01/22] feat: add all postgres client versions --- postgres/Dockerfile | 33 ++++++++++++++++++++++++++++----- postgres/bin/dump-to-s3.sh | 24 +++++++++++++++++------- postgres/bin/load-from-s3.sh | 13 +++++++++++-- 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/postgres/Dockerfile b/postgres/Dockerfile index ff7b975..59b0ee7 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -1,9 +1,32 @@ -FROM --platform=linux/amd64 python:3.12-alpine3.19 +FROM ubuntu:20.04 ENV AWS_CONFIG_FILE=/.aws_config -RUN set -ex && \ - apk add --no-cache postgresql16-client bash && \ - pip install --no-cache-dir awscli && \ - aws configure set default.s3.multipart_chunksize 200MB +ENV PATH="/opt/postgresql/bin:$PATH" + +# Add the PostgreSQL Apt repository +RUN apt-get update && apt-get install -y wget gnupg && \ + echo "deb http://apt.postgresql.org/pub/repos/apt focal-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - + +# Install PostgreSQL client tools for versions 11–17 and other dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + curl \ + postgresql-client-11 \ + postgresql-client-12 \ + postgresql-client-13 \ + postgresql-client-14 \ + postgresql-client-15 \ + postgresql-client-16 \ + postgresql-client-17 \ + python3-pip && \ + mkdir -p /opt/postgresql && \ + for version in 11 12 13 14 15 16 17; do \ + ln -s /usr/lib/postgresql/$version/bin/pg_dump /usr/bin/pg_dump-$version && \ + ln -s /usr/lib/postgresql/$version/bin/pg_restore /usr/bin/pg_restore-$version; \ + done && \ + pip3 install awscli && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + COPY ./bin/ /bin/ ENTRYPOINT ["/bin/entrypoint.sh"] diff --git a/postgres/bin/dump-to-s3.sh b/postgres/bin/dump-to-s3.sh index ae74031..4bea19c 100755 --- a/postgres/bin/dump-to-s3.sh +++ b/postgres/bin/dump-to-s3.sh @@ -1,19 +1,29 @@ #!/bin/bash # Usage: dump-to-s3.sh [dbname] -# Expects a DATABASE_URL environment variable that is the DB to dump -# Optionally, a dbname can be supplied as the second argument -# to override the name from the DATABASE_URL +# Expects a DATABASE_URL environment variable that provides the DB connection details. +# Optionally, a dbname can be supplied as the second argument to override the name from the DATABASE_URL. + set -euf -o pipefail cleanup() { rv=$?; if [ -f /tmp/db.dump ]; then shred -u /tmp/db.dump; fi; exit $rv; } trap cleanup EXIT -NAME=${2:-$NAME} -CONNECT_DB_URL="postgres://$USER@$HOST:$PORT/$NAME" +# Extract database name from DATABASE_URL if not provided as an argument +DBNAME=${2:-$(echo "$DATABASE_URL" | sed -E 's|.*/([^/?]+).*|\1|')} +CONNECT_DB_URL="${DATABASE_URL%/*}/$DBNAME" + +# Get PostgreSQL server version +SERVER_VERSION=$(psql "$CONNECT_DB_URL" -tAc "SHOW server_version;" | cut -d '.' -f 1) +PG_DUMP="pg_dump-$SERVER_VERSION" + +if ! command -v "$PG_DUMP" &>/dev/null; then + echo "Error: pg_dump for version $SERVER_VERSION is not installed." >&2 + exit 1 +fi -echo "Dumping $CONNECT_DB_URL to $1..." +echo "Dumping $CONNECT_DB_URL to $1 using $PG_DUMP..." set -x -pg_dump --no-privileges --no-owner --format=custom "$CONNECT_DB_URL" --file=/tmp/db.dump +"$PG_DUMP" --no-privileges --no-owner --format=custom "$CONNECT_DB_URL" --file=/tmp/db.dump aws s3 cp --acl=private --no-progress /tmp/db.dump "$1" { set +x; } 2>/dev/null echo "Done!" diff --git a/postgres/bin/load-from-s3.sh b/postgres/bin/load-from-s3.sh index 9760c27..954fb18 100755 --- a/postgres/bin/load-from-s3.sh +++ b/postgres/bin/load-from-s3.sh @@ -11,12 +11,21 @@ S3_PATH=$1 echo "Downloading $S3_PATH ..." aws s3 cp --no-progress "$S3_PATH" /tmp/db.dump +# Get the PostgreSQL server version +SERVER_VERSION=$(psql -tAc "SHOW server_version;" | cut -d '.' -f 1) +PG_RESTORE="pg_restore-$SERVER_VERSION" + +if ! command -v "$PG_RESTORE" &>/dev/null; then + echo "Error: pg_restore for version $SERVER_VERSION is not installed." >&2 + exit 1 +fi + echo "Dropping $NAME..." psql --echo-all -c "DROP OWNED BY \"$USER\" CASCADE;" -echo "Loading dump from S3..." +echo "Loading dump from S3 using $PG_RESTORE..." set -x -pg_restore --jobs="${PG_RESTORE_JOBS:-2}" --no-owner --no-privileges --dbname="$NAME" /tmp/db.dump +"$PG_RESTORE" --jobs="${PG_RESTORE_JOBS:-2}" --no-owner --no-privileges --dbname="$NAME" /tmp/db.dump { set +x; } 2>/dev/null echo "Done!" From 83a37a88ab8d51408622506349bdb4037ee2f553 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Sun, 5 Jan 2025 07:35:24 +0530 Subject: [PATCH 02/22] fix: Update base image to 22.04 --- postgres/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postgres/Dockerfile b/postgres/Dockerfile index 59b0ee7..39b89cc 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -1,11 +1,11 @@ -FROM ubuntu:20.04 +FROM ubuntu:22.04 ENV AWS_CONFIG_FILE=/.aws_config ENV PATH="/opt/postgresql/bin:$PATH" # Add the PostgreSQL Apt repository RUN apt-get update && apt-get install -y wget gnupg && \ - echo "deb http://apt.postgresql.org/pub/repos/apt focal-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ + echo "deb http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - # Install PostgreSQL client tools for versions 11–17 and other dependencies From fdcc9e3f0a884783c8c60b4f397e83a932e44f01 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 7 Jan 2025 23:37:46 +0530 Subject: [PATCH 03/22] Address review comments --- postgres/Dockerfile | 2 +- postgres/bin/dump-to-s3.sh | 11 +++++------ postgres/bin/entrypoint.sh | 10 ++++++++++ postgres/bin/load-from-s3.sh | 15 +++++++++------ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/postgres/Dockerfile b/postgres/Dockerfile index 39b89cc..43480dd 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 +FROM debian:bookworm-slim ENV AWS_CONFIG_FILE=/.aws_config ENV PATH="/opt/postgresql/bin:$PATH" diff --git a/postgres/bin/dump-to-s3.sh b/postgres/bin/dump-to-s3.sh index 4bea19c..bc2b643 100755 --- a/postgres/bin/dump-to-s3.sh +++ b/postgres/bin/dump-to-s3.sh @@ -1,7 +1,7 @@ #!/bin/bash # Usage: dump-to-s3.sh [dbname] -# Expects a DATABASE_URL environment variable that provides the DB connection details. -# Optionally, a dbname can be supplied as the second argument to override the name from the DATABASE_URL. +# Expects a DATABASE_URL environment variable and SERVER_VERSION exported by the entrypoint. +# Optionally, a dbname can be supplied as the second argument to override the name from DATABASE_URL. set -euf -o pipefail @@ -12,13 +12,12 @@ trap cleanup EXIT DBNAME=${2:-$(echo "$DATABASE_URL" | sed -E 's|.*/([^/?]+).*|\1|')} CONNECT_DB_URL="${DATABASE_URL%/*}/$DBNAME" -# Get PostgreSQL server version -SERVER_VERSION=$(psql "$CONNECT_DB_URL" -tAc "SHOW server_version;" | cut -d '.' -f 1) +# Use SERVER_VERSION set by the entrypoint PG_DUMP="pg_dump-$SERVER_VERSION" if ! command -v "$PG_DUMP" &>/dev/null; then - echo "Error: pg_dump for version $SERVER_VERSION is not installed." >&2 - exit 1 + echo "WARNING: pg_dump for version $SERVER_VERSION is not installed. Defaulting to pg_dump-17." + PG_DUMP="pg_dump-17" fi echo "Dumping $CONNECT_DB_URL to $1 using $PG_DUMP..." diff --git a/postgres/bin/entrypoint.sh b/postgres/bin/entrypoint.sh index f785fd6..0e29a12 100755 --- a/postgres/bin/entrypoint.sh +++ b/postgres/bin/entrypoint.sh @@ -13,6 +13,16 @@ else # Setup PGSERVICE so `psql` just does the right thing /bin/echo -e "[$NAME]\nhost=$HOST\nport=$PORT\ndbname=$NAME\nuser=$USER" > ~/.pg_service.conf export PGSERVICE="$NAME" + + # Detect PostgreSQL server version + SERVER_VERSION=$(psql "$DATABASE_URL" -tAc "SHOW server_version;" | cut -d '.' -f 1 || true) + if [ -z "$SERVER_VERSION" ]; then + echo "WARNING: Unable to detect PostgreSQL server version. Defaulting to latest (17)." + SERVER_VERSION="17" + else + echo "Detected PostgreSQL server version: $SERVER_VERSION" + fi + export SERVER_VERSION fi exec "$@" diff --git a/postgres/bin/load-from-s3.sh b/postgres/bin/load-from-s3.sh index 954fb18..90a001d 100755 --- a/postgres/bin/load-from-s3.sh +++ b/postgres/bin/load-from-s3.sh @@ -11,17 +11,20 @@ S3_PATH=$1 echo "Downloading $S3_PATH ..." aws s3 cp --no-progress "$S3_PATH" /tmp/db.dump -# Get the PostgreSQL server version -SERVER_VERSION=$(psql -tAc "SHOW server_version;" | cut -d '.' -f 1) +# Ensure SERVER_VERSION is set by the entrypoint +if [ -z "${SERVER_VERSION:-}" ]; then + echo "Warning: SERVER_VERSION not detected. Defaulting to latest (17)." + SERVER_VERSION="17" +fi + PG_RESTORE="pg_restore-$SERVER_VERSION" if ! command -v "$PG_RESTORE" &>/dev/null; then - echo "Error: pg_restore for version $SERVER_VERSION is not installed." >&2 - exit 1 + echo "Warning: pg_restore for version $SERVER_VERSION is not installed. Defaulting to pg_restore-17." + PG_RESTORE="pg_restore-17" fi -echo "Dropping $NAME..." - +echo "Dropping all objects owned by \"$USER\" in the database..." psql --echo-all -c "DROP OWNED BY \"$USER\" CASCADE;" echo "Loading dump from S3 using $PG_RESTORE..." From 4d2232078e4ce4363cbbc7e1f870972187230f14 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Wed, 8 Jan 2025 00:17:33 +0530 Subject: [PATCH 04/22] chore: fix Dockerfile + use venv --- postgres/Dockerfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/postgres/Dockerfile b/postgres/Dockerfile index 43480dd..e89a67d 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -5,7 +5,7 @@ ENV PATH="/opt/postgresql/bin:$PATH" # Add the PostgreSQL Apt repository RUN apt-get update && apt-get install -y wget gnupg && \ - echo "deb http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ + echo "deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - # Install PostgreSQL client tools for versions 11–17 and other dependencies @@ -19,13 +19,16 @@ RUN apt-get update && \ postgresql-client-15 \ postgresql-client-16 \ postgresql-client-17 \ - python3-pip && \ + python3-venv python3-pip && \ mkdir -p /opt/postgresql && \ for version in 11 12 13 14 15 16 17; do \ ln -s /usr/lib/postgresql/$version/bin/pg_dump /usr/bin/pg_dump-$version && \ ln -s /usr/lib/postgresql/$version/bin/pg_restore /usr/bin/pg_restore-$version; \ done && \ - pip3 install awscli && \ + # Use a virtual environment to install Python packages + python3 -m venv /opt/awscli && \ + /opt/awscli/bin/pip install --no-cache-dir awscli && \ + ln -s /opt/awscli/bin/aws /usr/bin/aws && \ apt-get clean && rm -rf /var/lib/apt/lists/* COPY ./bin/ /bin/ From e3e6678182a596e316452b56efc665c5a3f15c1d Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Wed, 8 Jan 2025 00:22:05 +0530 Subject: [PATCH 05/22] fix path for aws --- postgres/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postgres/Dockerfile b/postgres/Dockerfile index e89a67d..18d51f6 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -1,7 +1,7 @@ FROM debian:bookworm-slim ENV AWS_CONFIG_FILE=/.aws_config -ENV PATH="/opt/postgresql/bin:$PATH" +ENV PATH="/opt/postgresql/bin:/opt/awscli/bin:$PATH" # Add the PostgreSQL Apt repository RUN apt-get update && apt-get install -y wget gnupg && \ @@ -28,7 +28,7 @@ RUN apt-get update && \ # Use a virtual environment to install Python packages python3 -m venv /opt/awscli && \ /opt/awscli/bin/pip install --no-cache-dir awscli && \ - ln -s /opt/awscli/bin/aws /usr/bin/aws && \ + ln -s /opt/awscli/bin/aws /usr/local/bin/aws && \ apt-get clean && rm -rf /var/lib/apt/lists/* COPY ./bin/ /bin/ From e550024213a200159db6784bbb32189c4692082c Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Wed, 8 Jan 2025 00:37:53 +0530 Subject: [PATCH 06/22] add debugging on db creds setup --- postgres/bin/entrypoint.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/postgres/bin/entrypoint.sh b/postgres/bin/entrypoint.sh index 0e29a12..31bb4d2 100755 --- a/postgres/bin/entrypoint.sh +++ b/postgres/bin/entrypoint.sh @@ -7,9 +7,19 @@ export PGSSLMODE=require if [ -z "${DATABASE_URL:-""}" ]; then echo "WARNING: DATABASE_URL not found in environment." else + echo "DEBUG: DATABASE_URL=$DATABASE_URL" + # Extract connection details from DATABASE_URL # shellcheck disable=SC2046 export $(parse_database_url.py | xargs) + + # Log the parsed variables for debugging + echo "DEBUG: Parsed variables:" + echo " HOST=$HOST" + echo " PORT=$PORT" + echo " NAME=$NAME" + echo " USER=$USER" + # Setup PGSERVICE so `psql` just does the right thing /bin/echo -e "[$NAME]\nhost=$HOST\nport=$PORT\ndbname=$NAME\nuser=$USER" > ~/.pg_service.conf export PGSERVICE="$NAME" From 03e8f8fd9ab1726a7ab6e2676b57946b8cda62ff Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Thu, 9 Jan 2025 01:55:14 +0530 Subject: [PATCH 07/22] Fix mysql tests --- mysql/docker-compose.test.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mysql/docker-compose.test.yml b/mysql/docker-compose.test.yml index 4724fb1..1e49d3a 100644 --- a/mysql/docker-compose.test.yml +++ b/mysql/docker-compose.test.yml @@ -1,10 +1,11 @@ services: db: - image: mysql:8 + image: mariadb:10.5 platform: linux/amd64 - command: --default-authentication-plugin=mysql_native_password environment: MYSQL_ROOT_PASSWORD: password + volumes: + - db_data:/var/lib/mysql s3: image: localstack/localstack platform: linux/amd64 @@ -25,3 +26,6 @@ services: AWS_ENDPOINT_URL: http://s3:4566 AWS_ACCESS_KEY_ID: foo AWS_SECRET_ACCESS_KEY: bar + +volumes: + db_data: From f7813c59e2b67eda405b32271d160ba286bc8e16 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Thu, 9 Jan 2025 02:22:55 +0530 Subject: [PATCH 08/22] Modify github actions for postgres --- .github/workflows/postgres.yml | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/postgres.yml b/.github/workflows/postgres.yml index 67431aa..7bf171a 100644 --- a/.github/workflows/postgres.yml +++ b/.github/workflows/postgres.yml @@ -8,7 +8,25 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Test Postgres + + - name: Set up Docker + uses: docker/setup-buildx-action@v2 + + - name: Generate SSL Certificates + run: | + mkdir -p /etc/ssl/certs /etc/ssl/private + openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ + -keyout /etc/ssl/private/ssl-cert-snakeoil.key \ + -out /etc/ssl/certs/ssl-cert-snakeoil.pem \ + -subj "/CN=localhost" + + - name: Pull Postgres Image + run: docker pull postgres:14 + + - name: Start Test Environment + run: | + docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit + + - name: Debug Postgres Version run: | - cd postgres - docker compose -f docker-compose.test.yml run --rm utils + docker exec $(docker ps -q -f "name=db") psql --version From ea4ff7f7e89264feff305780c30340e4ff218341 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Thu, 9 Jan 2025 03:32:39 +0530 Subject: [PATCH 09/22] Revert "Modify github actions for postgres" This reverts commit f7813c59e2b67eda405b32271d160ba286bc8e16. --- .github/workflows/postgres.yml | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/.github/workflows/postgres.yml b/.github/workflows/postgres.yml index 7bf171a..67431aa 100644 --- a/.github/workflows/postgres.yml +++ b/.github/workflows/postgres.yml @@ -8,25 +8,7 @@ jobs: steps: - uses: actions/checkout@v3 - - - name: Set up Docker - uses: docker/setup-buildx-action@v2 - - - name: Generate SSL Certificates - run: | - mkdir -p /etc/ssl/certs /etc/ssl/private - openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ - -keyout /etc/ssl/private/ssl-cert-snakeoil.key \ - -out /etc/ssl/certs/ssl-cert-snakeoil.pem \ - -subj "/CN=localhost" - - - name: Pull Postgres Image - run: docker pull postgres:14 - - - name: Start Test Environment - run: | - docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit - - - name: Debug Postgres Version + - name: Test Postgres run: | - docker exec $(docker ps -q -f "name=db") psql --version + cd postgres + docker compose -f docker-compose.test.yml run --rm utils From b9c6bd34f52da8acb169049ca31e7b3bbed22952 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 28 Jan 2025 04:00:20 +0530 Subject: [PATCH 10/22] fix: Wait for DB to detect psql version --- postgres/bin/entrypoint.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/postgres/bin/entrypoint.sh b/postgres/bin/entrypoint.sh index 31bb4d2..ee0e483 100755 --- a/postgres/bin/entrypoint.sh +++ b/postgres/bin/entrypoint.sh @@ -4,26 +4,39 @@ set -euf -o pipefail export PGSSLMODE=require +wait_for_db() { + local retries=30 + local sleep_time=2 + + echo "Waiting for PostgreSQL server to be ready..." + until psql "$DATABASE_URL" -c '\q' 2>/dev/null || [ "$retries" -eq 0 ]; do + echo "PostgreSQL is unavailable - sleeping ($((retries--)) retries left)..." + sleep "$sleep_time" + done + + if [ "$retries" -eq 0 ]; then + echo "ERROR: PostgreSQL server did not become ready in time." + exit 1 + fi + + echo "PostgreSQL server is ready!" +} + if [ -z "${DATABASE_URL:-""}" ]; then echo "WARNING: DATABASE_URL not found in environment." else - echo "DEBUG: DATABASE_URL=$DATABASE_URL" # Extract connection details from DATABASE_URL # shellcheck disable=SC2046 export $(parse_database_url.py | xargs) - # Log the parsed variables for debugging - echo "DEBUG: Parsed variables:" - echo " HOST=$HOST" - echo " PORT=$PORT" - echo " NAME=$NAME" - echo " USER=$USER" - # Setup PGSERVICE so `psql` just does the right thing /bin/echo -e "[$NAME]\nhost=$HOST\nport=$PORT\ndbname=$NAME\nuser=$USER" > ~/.pg_service.conf export PGSERVICE="$NAME" + # Wait for PostgreSQL to be ready + wait_for_db + # Detect PostgreSQL server version SERVER_VERSION=$(psql "$DATABASE_URL" -tAc "SHOW server_version;" | cut -d '.' -f 1 || true) if [ -z "$SERVER_VERSION" ]; then From 7f2192d4fb1cd7ed9487397c6460940aedb7f495 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 28 Jan 2025 04:10:35 +0530 Subject: [PATCH 11/22] Add postgres init script for db auth --- postgres/docker-compose.test.yml | 2 ++ postgres/init.sql | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 postgres/init.sql diff --git a/postgres/docker-compose.test.yml b/postgres/docker-compose.test.yml index 82a8edd..82dd2db 100644 --- a/postgres/docker-compose.test.yml +++ b/postgres/docker-compose.test.yml @@ -2,6 +2,8 @@ services: db: image: postgres:14 command: -c ssl=on -c ssl_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem -c ssl_key_file=/etc/ssl/private/ssl-cert-snakeoil.key + volumes: + - ./init.sql:/docker-entrypoint-initdb.d/init.sql environment: POSTGRES_PASSWORD: password s3: diff --git a/postgres/init.sql b/postgres/init.sql new file mode 100644 index 0000000..ee6f0cf --- /dev/null +++ b/postgres/init.sql @@ -0,0 +1,2 @@ +CREATE ROLE test WITH LOGIN PASSWORD 'password'; +CREATE DATABASE test OWNER test; From ef8448222a63bc9470ee7fb0efcadfb0bc23e42f Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 28 Jan 2025 04:57:25 +0530 Subject: [PATCH 12/22] Address review comments --- postgres/Dockerfile | 9 ++++----- postgres/bin/dump-to-s3.sh | 6 ++++-- postgres/docs/support-newer-postgres-versions.md | 11 +++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 postgres/docs/support-newer-postgres-versions.md diff --git a/postgres/Dockerfile b/postgres/Dockerfile index 18d51f6..f1af492 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -19,16 +19,15 @@ RUN apt-get update && \ postgresql-client-15 \ postgresql-client-16 \ postgresql-client-17 \ - python3-venv python3-pip && \ + python3-pip && \ mkdir -p /opt/postgresql && \ for version in 11 12 13 14 15 16 17; do \ ln -s /usr/lib/postgresql/$version/bin/pg_dump /usr/bin/pg_dump-$version && \ ln -s /usr/lib/postgresql/$version/bin/pg_restore /usr/bin/pg_restore-$version; \ done && \ - # Use a virtual environment to install Python packages - python3 -m venv /opt/awscli && \ - /opt/awscli/bin/pip install --no-cache-dir awscli && \ - ln -s /opt/awscli/bin/aws /usr/local/bin/aws && \ + # Install AWS CLI globally + pip3 install --no-cache-dir awscli && \ + ln -s /usr/local/bin/aws /usr/bin/aws && \ apt-get clean && rm -rf /var/lib/apt/lists/* COPY ./bin/ /bin/ diff --git a/postgres/bin/dump-to-s3.sh b/postgres/bin/dump-to-s3.sh index bc2b643..e7e697f 100755 --- a/postgres/bin/dump-to-s3.sh +++ b/postgres/bin/dump-to-s3.sh @@ -1,6 +1,6 @@ #!/bin/bash # Usage: dump-to-s3.sh [dbname] -# Expects a DATABASE_URL environment variable and SERVER_VERSION exported by the entrypoint. +# Expects a DATABASE_URL environment variable and optionally SERVER_VERSION exported by the entrypoint. # Optionally, a dbname can be supplied as the second argument to override the name from DATABASE_URL. set -euf -o pipefail @@ -12,9 +12,11 @@ trap cleanup EXIT DBNAME=${2:-$(echo "$DATABASE_URL" | sed -E 's|.*/([^/?]+).*|\1|')} CONNECT_DB_URL="${DATABASE_URL%/*}/$DBNAME" -# Use SERVER_VERSION set by the entrypoint +# Default SERVER_VERSION to 17 if not supplied +SERVER_VERSION=${SERVER_VERSION:-17} PG_DUMP="pg_dump-$SERVER_VERSION" +# Fallback to pg_dump-17 if the specified version is not available if ! command -v "$PG_DUMP" &>/dev/null; then echo "WARNING: pg_dump for version $SERVER_VERSION is not installed. Defaulting to pg_dump-17." PG_DUMP="pg_dump-17" diff --git a/postgres/docs/support-newer-postgres-versions.md b/postgres/docs/support-newer-postgres-versions.md new file mode 100644 index 0000000..76469d7 --- /dev/null +++ b/postgres/docs/support-newer-postgres-versions.md @@ -0,0 +1,11 @@ +# HOW TO UPDATE FOR NEW POSTGRESQL VERSIONS: + +1. Install the new PostgreSQL client tools: + Add the new version of `postgresql-client` to the Dockerfile, e.g., `postgresql-client-18`. +2. Test the script: + Verify that the new version works by setting `SERVER_VERSION` to the new version (e.g., `18`) + and running the script against a PostgreSQL 18 server. +3. Ensure fallback compatibility: + Test the script with no `SERVER_VERSION` set to confirm it falls back to the latest version. +4. Update `dump-to-s3.sh` script's `SERVER_VERSION` default value if the new version becomes the default: + Change `SERVER_VERSION=${SERVER_VERSION:-17}` to `SERVER_VERSION=${SERVER_VERSION:-18}`. From e688af461ffd4b1226df28557219529d7c338e64 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 28 Jan 2025 04:59:11 +0530 Subject: [PATCH 13/22] minor fix --- postgres/docs/support-newer-postgres-versions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres/docs/support-newer-postgres-versions.md b/postgres/docs/support-newer-postgres-versions.md index 76469d7..eb927b9 100644 --- a/postgres/docs/support-newer-postgres-versions.md +++ b/postgres/docs/support-newer-postgres-versions.md @@ -1,4 +1,4 @@ -# HOW TO UPDATE FOR NEW POSTGRESQL VERSIONS: +# How To Update For New Postgresql Versions: 1. Install the new PostgreSQL client tools: Add the new version of `postgresql-client` to the Dockerfile, e.g., `postgresql-client-18`. From 1f4f4e5129d3aa0dd9d5f630206a1828c3cc30bb Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 28 Jan 2025 05:02:55 +0530 Subject: [PATCH 14/22] remove externally-managed --- postgres/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/postgres/Dockerfile b/postgres/Dockerfile index f1af492..8f38502 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -26,6 +26,7 @@ RUN apt-get update && \ ln -s /usr/lib/postgresql/$version/bin/pg_restore /usr/bin/pg_restore-$version; \ done && \ # Install AWS CLI globally + rm -f /usr/lib/python3.11/EXTERNALLY-MANAGED && \ pip3 install --no-cache-dir awscli && \ ln -s /usr/local/bin/aws /usr/bin/aws && \ apt-get clean && rm -rf /var/lib/apt/lists/* From 89cddda2c027847a3c27edf7153bdd36e452ee79 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 28 Jan 2025 05:09:37 +0530 Subject: [PATCH 15/22] Update docs --- postgres/docs/support-newer-postgres-versions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/postgres/docs/support-newer-postgres-versions.md b/postgres/docs/support-newer-postgres-versions.md index eb927b9..6550ee4 100644 --- a/postgres/docs/support-newer-postgres-versions.md +++ b/postgres/docs/support-newer-postgres-versions.md @@ -2,6 +2,8 @@ 1. Install the new PostgreSQL client tools: Add the new version of `postgresql-client` to the Dockerfile, e.g., `postgresql-client-18`. + Update the newer version in the for loop: + `for version in 11 12 13 14 15 16 17; do \` to `for version in 11 12 13 14 15 16 17 18; do \` 2. Test the script: Verify that the new version works by setting `SERVER_VERSION` to the new version (e.g., `18`) and running the script against a PostgreSQL 18 server. From edcae011f883fc8a9398aa0b15e73e6c4576c008 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 1 Apr 2025 00:53:56 +0530 Subject: [PATCH 16/22] Address first set of review --- postgres/bin/entrypoint.sh | 6 ++---- postgres/bin/load-from-s3.sh | 4 ++-- postgres/bin/parse_database_url.py | 1 - postgres/docs/support-newer-postgres-versions.md | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/postgres/bin/entrypoint.sh b/postgres/bin/entrypoint.sh index ee0e483..2e7cb29 100755 --- a/postgres/bin/entrypoint.sh +++ b/postgres/bin/entrypoint.sh @@ -10,16 +10,14 @@ wait_for_db() { echo "Waiting for PostgreSQL server to be ready..." until psql "$DATABASE_URL" -c '\q' 2>/dev/null || [ "$retries" -eq 0 ]; do - echo "PostgreSQL is unavailable - sleeping ($((retries--)) retries left)..." + echo "PostgreSQL is unavailable - ($((retries--)) retries left)..." sleep "$sleep_time" done if [ "$retries" -eq 0 ]; then - echo "ERROR: PostgreSQL server did not become ready in time." + echo "ERROR: PostgreSQL server did not respond." exit 1 fi - - echo "PostgreSQL server is ready!" } if [ -z "${DATABASE_URL:-""}" ]; then diff --git a/postgres/bin/load-from-s3.sh b/postgres/bin/load-from-s3.sh index 90a001d..fbd73cf 100755 --- a/postgres/bin/load-from-s3.sh +++ b/postgres/bin/load-from-s3.sh @@ -20,8 +20,8 @@ fi PG_RESTORE="pg_restore-$SERVER_VERSION" if ! command -v "$PG_RESTORE" &>/dev/null; then - echo "Warning: pg_restore for version $SERVER_VERSION is not installed. Defaulting to pg_restore-17." - PG_RESTORE="pg_restore-17" + echo "Error: $PG_RESTORE not found in PATH." >&2 + exit 1 fi echo "Dropping all objects owned by \"$USER\" in the database..." diff --git a/postgres/bin/parse_database_url.py b/postgres/bin/parse_database_url.py index 14dabe5..221425b 100755 --- a/postgres/bin/parse_database_url.py +++ b/postgres/bin/parse_database_url.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 """Dump out a DATABASE_URL provided in the environment as individual variables""" import os -import sys from urllib.parse import urlparse parsed = urlparse(os.environ["DATABASE_URL"]) diff --git a/postgres/docs/support-newer-postgres-versions.md b/postgres/docs/support-newer-postgres-versions.md index 6550ee4..e62a55a 100644 --- a/postgres/docs/support-newer-postgres-versions.md +++ b/postgres/docs/support-newer-postgres-versions.md @@ -9,5 +9,5 @@ and running the script against a PostgreSQL 18 server. 3. Ensure fallback compatibility: Test the script with no `SERVER_VERSION` set to confirm it falls back to the latest version. -4. Update `dump-to-s3.sh` script's `SERVER_VERSION` default value if the new version becomes the default: +4. Update `load-from-s3.sh` & `dump-to-s3.sh` script's `SERVER_VERSION` default value if the new version becomes the default: Change `SERVER_VERSION=${SERVER_VERSION:-17}` to `SERVER_VERSION=${SERVER_VERSION:-18}`. From 87ba63df8276bf29bc76e032f6bffa341328de6d Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 1 Apr 2025 02:07:58 +0530 Subject: [PATCH 17/22] fix: Handle the fallback --- postgres/bin/dump-to-s3.sh | 18 +++++++++++++----- postgres/bin/entrypoint.sh | 12 +++++++++--- postgres/bin/load-from-s3.sh | 10 +++++++--- postgres/tests/tests.sh | 15 ++++++++++++--- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/postgres/bin/dump-to-s3.sh b/postgres/bin/dump-to-s3.sh index e7e697f..884032d 100755 --- a/postgres/bin/dump-to-s3.sh +++ b/postgres/bin/dump-to-s3.sh @@ -12,14 +12,22 @@ trap cleanup EXIT DBNAME=${2:-$(echo "$DATABASE_URL" | sed -E 's|.*/([^/?]+).*|\1|')} CONNECT_DB_URL="${DATABASE_URL%/*}/$DBNAME" -# Default SERVER_VERSION to 17 if not supplied -SERVER_VERSION=${SERVER_VERSION:-17} +# Try to detect server version if not provided +if [ -z "${SERVER_VERSION:-}" ]; then + echo "SERVER_VERSION not set. Trying to detect using psql..." + SERVER_VERSION=$(psql "$CONNECT_DB_URL" -tAc "SHOW server_version;" | cut -d '.' -f 1 || true) +fi + +if [ -z "$SERVER_VERSION" ]; then + echo "Warning: SERVER_VERSION not detected. Defaulting to version 17 (latest)." + SERVER_VERSION="17" +fi + PG_DUMP="pg_dump-$SERVER_VERSION" -# Fallback to pg_dump-17 if the specified version is not available if ! command -v "$PG_DUMP" &>/dev/null; then - echo "WARNING: pg_dump for version $SERVER_VERSION is not installed. Defaulting to pg_dump-17." - PG_DUMP="pg_dump-17" + echo "ERROR: $PG_DUMP not found in PATH. You must install it or override SERVER_VERSION." >&2 + exit 1 fi echo "Dumping $CONNECT_DB_URL to $1 using $PG_DUMP..." diff --git a/postgres/bin/entrypoint.sh b/postgres/bin/entrypoint.sh index 2e7cb29..e94afcc 100755 --- a/postgres/bin/entrypoint.sh +++ b/postgres/bin/entrypoint.sh @@ -36,14 +36,20 @@ else wait_for_db # Detect PostgreSQL server version - SERVER_VERSION=$(psql "$DATABASE_URL" -tAc "SHOW server_version;" | cut -d '.' -f 1 || true) + if [ -z "${SERVER_VERSION:-}" ]; then + echo "Attempting to detect PostgreSQL server version..." + SERVER_VERSION=$(psql "$DATABASE_URL" -tAc "SHOW server_version;" | cut -d '.' -f 1 || true) + fi + if [ -z "$SERVER_VERSION" ]; then - echo "WARNING: Unable to detect PostgreSQL server version. Defaulting to latest (17)." + echo "WARNING: Unable to detect PostgreSQL version. Defaulting to latest (17)." SERVER_VERSION="17" else - echo "Detected PostgreSQL server version: $SERVER_VERSION" + echo "Detected PostgreSQL version: $SERVER_VERSION" fi + export SERVER_VERSION + fi exec "$@" diff --git a/postgres/bin/load-from-s3.sh b/postgres/bin/load-from-s3.sh index fbd73cf..c78c180 100755 --- a/postgres/bin/load-from-s3.sh +++ b/postgres/bin/load-from-s3.sh @@ -1,6 +1,5 @@ #!/bin/bash # Usage: load-from-s3.sh -# The DATABASE_URL will be dropped and recreated from S3 set -euf -o pipefail cleanup() { rv=$?; if [ -f /tmp/db.dump ]; then shred -u /tmp/db.dump; fi; exit $rv; } @@ -11,9 +10,14 @@ S3_PATH=$1 echo "Downloading $S3_PATH ..." aws s3 cp --no-progress "$S3_PATH" /tmp/db.dump -# Ensure SERVER_VERSION is set by the entrypoint +# Detect server version if not already available if [ -z "${SERVER_VERSION:-}" ]; then - echo "Warning: SERVER_VERSION not detected. Defaulting to latest (17)." + echo "SERVER_VERSION not set. Trying to detect using psql..." + SERVER_VERSION=$(psql "$DATABASE_URL" -tAc "SHOW server_version;" | cut -d '.' -f 1 || true) +fi + +if [ -z "$SERVER_VERSION" ]; then + echo "Warning: SERVER_VERSION not detected. Defaulting to version 17 (latest)." SERVER_VERSION="17" fi diff --git a/postgres/tests/tests.sh b/postgres/tests/tests.sh index 2b362f7..ad03a90 100755 --- a/postgres/tests/tests.sh +++ b/postgres/tests/tests.sh @@ -16,7 +16,7 @@ echo "###### Setup test state" aws s3api create-bucket --bucket "$BUCKET" aws s3 rm --recursive "s3://$BUCKET/" psql postgres -U postgres -c "DROP DATABASE IF EXISTS test" -psql postgres -U postgres -c "DROP DATABASE IF EXISTS \"test-clone\"" +psql postgres -U postgres -c "DROP DATABASE IF EXISTS \"test-clone\"" psql postgres -U postgres -c "DROP ROLE IF EXISTS test" psql postgres -U postgres -c "CREATE ROLE test WITH LOGIN PASSWORD 'password'" @@ -25,18 +25,27 @@ psql test -c "CREATE TABLE tbl (id SERIAL PRIMARY KEY, name CHAR(255) NOT NULL)" psql test -c "INSERT INTO tbl (name) VALUES ('name1')" psql test -c "INSERT INTO tbl (name) VALUES ('name2')" +printf "\n###### Testing SERVER_VERSION override...\n" +export SERVER_VERSION=17 +dump-to-s3.sh "s3://$BUCKET/explicit.dump" test +aws s3 ls "s3://$BUCKET/" | grep explicit.dump + +printf "\n###### Testing fallback with unset SERVER_VERSION...\n" +unset SERVER_VERSION +dump-to-s3.sh "s3://$BUCKET/default.dump" test +aws s3 ls "s3://$BUCKET/" | grep default.dump + printf "\n###### Starting tests...\n" dump-to-s3.sh "s3://$BUCKET/dump.dump" test printf "\n###### Verify dump file exists...\n" aws s3 ls "s3://$BUCKET/" | grep dump.dump - psql test -c "INSERT INTO tbl (name) VALUES ('name3')" printf "\n###### Verify 3 records exist before load...\n" psql test -c "SELECT COUNT(*) FROM tbl" | grep "3" load-from-s3.sh "s3://$BUCKET/dump.dump" -printf "\n###### Verify 2 record exists after load...\n" +printf "\n###### Verify 2 records exist after load...\n" psql test -c "SELECT COUNT(*) FROM tbl" | grep "2" printf "\n###### Verify dump file does not exist after load...\n" From a914377af19e033d51766d850bd292b4a1edc199 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 1 Apr 2025 02:27:01 +0530 Subject: [PATCH 18/22] Update docs + tests to correctly detect dump/restore using correct version --- .../docs/support-newer-postgres-versions.md | 49 ++++++++++++++----- postgres/tests/tests.sh | 12 +++-- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/postgres/docs/support-newer-postgres-versions.md b/postgres/docs/support-newer-postgres-versions.md index e62a55a..30ca9c0 100644 --- a/postgres/docs/support-newer-postgres-versions.md +++ b/postgres/docs/support-newer-postgres-versions.md @@ -1,13 +1,36 @@ -# How To Update For New Postgresql Versions: - -1. Install the new PostgreSQL client tools: - Add the new version of `postgresql-client` to the Dockerfile, e.g., `postgresql-client-18`. - Update the newer version in the for loop: - `for version in 11 12 13 14 15 16 17; do \` to `for version in 11 12 13 14 15 16 17 18; do \` -2. Test the script: - Verify that the new version works by setting `SERVER_VERSION` to the new version (e.g., `18`) - and running the script against a PostgreSQL 18 server. -3. Ensure fallback compatibility: - Test the script with no `SERVER_VERSION` set to confirm it falls back to the latest version. -4. Update `load-from-s3.sh` & `dump-to-s3.sh` script's `SERVER_VERSION` default value if the new version becomes the default: - Change `SERVER_VERSION=${SERVER_VERSION:-17}` to `SERVER_VERSION=${SERVER_VERSION:-18}`. +# How to Update for New PostgreSQL Versions + +Follow these steps to add support for a new PostgreSQL version (e.g., version 18): + +## 1. Install the New Client Tools + +In the `Dockerfile`: + +- Add the new version of `postgresql-client`, e.g., `postgresql-client-18` +- Update the `for` loop that creates version-specific symlinks: + +```dockerfile +for version in 11 12 13 14 15 16 17 18; do \ + ln -s /usr/lib/postgresql/$version/bin/pg_dump /usr/bin/pg_dump-$version && \ + ln -s /usr/lib/postgresql/$version/bin/pg_restore /usr/bin/pg_restore-$version; \ +done +``` + +These changes ensure the tooling for the new version is available. + +## 2. Update the Default Version (If Applicable) + +If the new version should become the default: + +- Update both `dump-to-s3.sh` and `load-from-s3.sh` + +This ensures the scripts default to the latest version when `SERVER_VERSION` is not set or detection fails. + +--- + +✅ Fallback behavior and override logic are already tested automatically in `tests.sh`, including: + +- Ensuring correct `pg_dump-*` is used when `SERVER_VERSION` is set +- Falling back to the detected or default version when unset + +Re-run `tests.sh` after changes to confirm compatibility across versions. diff --git a/postgres/tests/tests.sh b/postgres/tests/tests.sh index ad03a90..516e4b0 100755 --- a/postgres/tests/tests.sh +++ b/postgres/tests/tests.sh @@ -27,13 +27,17 @@ psql test -c "INSERT INTO tbl (name) VALUES ('name2')" printf "\n###### Testing SERVER_VERSION override...\n" export SERVER_VERSION=17 -dump-to-s3.sh "s3://$BUCKET/explicit.dump" test -aws s3 ls "s3://$BUCKET/" | grep explicit.dump +DUMP_LOG=$(dump-to-s3.sh "s3://$BUCKET/explicit.dump" test 2>&1) +echo "$DUMP_LOG" | grep "using pg_dump-17" > /dev/null +aws s3 ls "s3://$BUCKET/" | grep explicit.dump > /dev/null +echo "✅ pg_dump-17 used as expected with SERVER_VERSION=17" printf "\n###### Testing fallback with unset SERVER_VERSION...\n" unset SERVER_VERSION -dump-to-s3.sh "s3://$BUCKET/default.dump" test -aws s3 ls "s3://$BUCKET/" | grep default.dump +DUMP_LOG=$(dump-to-s3.sh "s3://$BUCKET/default.dump" test 2>&1) +echo "$DUMP_LOG" | grep "using pg_dump-14" > /dev/null +aws s3 ls "s3://$BUCKET/" | grep default.dump > /dev/null +echo "✅ pg_dump-14 used as expected when SERVER_VERSION was unset" printf "\n###### Starting tests...\n" dump-to-s3.sh "s3://$BUCKET/dump.dump" test From d054ac8be1b1359faf5a10a3cf67572facfd4d1c Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 1 Apr 2025 02:31:48 +0530 Subject: [PATCH 19/22] revert back to older way of parsing db-url --- postgres/bin/dump-to-s3.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/postgres/bin/dump-to-s3.sh b/postgres/bin/dump-to-s3.sh index 884032d..0b7167f 100755 --- a/postgres/bin/dump-to-s3.sh +++ b/postgres/bin/dump-to-s3.sh @@ -1,6 +1,6 @@ #!/bin/bash # Usage: dump-to-s3.sh [dbname] -# Expects a DATABASE_URL environment variable and optionally SERVER_VERSION exported by the entrypoint. +# Expects a DATABASE_URL environment variable that is the DB to dump and optionally SERVER_VERSION exported by the entrypoint. # Optionally, a dbname can be supplied as the second argument to override the name from DATABASE_URL. set -euf -o pipefail @@ -9,8 +9,8 @@ cleanup() { rv=$?; if [ -f /tmp/db.dump ]; then shred -u /tmp/db.dump; fi; exit trap cleanup EXIT # Extract database name from DATABASE_URL if not provided as an argument -DBNAME=${2:-$(echo "$DATABASE_URL" | sed -E 's|.*/([^/?]+).*|\1|')} -CONNECT_DB_URL="${DATABASE_URL%/*}/$DBNAME" +NAME=${2:-$NAME} +CONNECT_DB_URL="postgres://$USER@$HOST:$PORT/$NAME" # Try to detect server version if not provided if [ -z "${SERVER_VERSION:-}" ]; then From 23032f83e628081cad05c176c646202c2955f2a8 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 1 Apr 2025 02:32:20 +0530 Subject: [PATCH 20/22] Minor formatting --- postgres/bin/dump-to-s3.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/postgres/bin/dump-to-s3.sh b/postgres/bin/dump-to-s3.sh index 0b7167f..e25618e 100755 --- a/postgres/bin/dump-to-s3.sh +++ b/postgres/bin/dump-to-s3.sh @@ -1,7 +1,9 @@ #!/bin/bash # Usage: dump-to-s3.sh [dbname] -# Expects a DATABASE_URL environment variable that is the DB to dump and optionally SERVER_VERSION exported by the entrypoint. -# Optionally, a dbname can be supplied as the second argument to override the name from DATABASE_URL. +# Expects a DATABASE_URL environment variable that is the DB +# to dump and optionally SERVER_VERSION exported by the entrypoint. +# Optionally, a dbname can be supplied as the second argument +# to override the name from DATABASE_URL. set -euf -o pipefail From a511c6c2ba5bcc26c78f1b51a4cf54502dc46e09 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 1 Apr 2025 02:35:57 +0530 Subject: [PATCH 21/22] Minor fix --- postgres/bin/load-from-s3.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/postgres/bin/load-from-s3.sh b/postgres/bin/load-from-s3.sh index c78c180..b336408 100755 --- a/postgres/bin/load-from-s3.sh +++ b/postgres/bin/load-from-s3.sh @@ -1,5 +1,6 @@ #!/bin/bash # Usage: load-from-s3.sh +# The DATABASE_URL will be dropped and recreated from S3 set -euf -o pipefail cleanup() { rv=$?; if [ -f /tmp/db.dump ]; then shred -u /tmp/db.dump; fi; exit $rv; } From de697774f10e606af16a8b7494f7a9cf39782534 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Tue, 1 Apr 2025 02:38:09 +0530 Subject: [PATCH 22/22] Set back the s3 multipart chunksize to 200MB --- postgres/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/postgres/Dockerfile b/postgres/Dockerfile index 8f38502..7385bdd 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -29,6 +29,8 @@ RUN apt-get update && \ rm -f /usr/lib/python3.11/EXTERNALLY-MANAGED && \ pip3 install --no-cache-dir awscli && \ ln -s /usr/local/bin/aws /usr/bin/aws && \ + aws configure set default.s3.multipart_chunksize 200MB && \ + # Cleanup cache apt-get clean && rm -rf /var/lib/apt/lists/* COPY ./bin/ /bin/