From 7e1e105caaa0cd7bb4a95a58f89b140495f0c19a Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Sat, 28 Oct 2023 11:49:32 +0200 Subject: [PATCH] Ensure postgres server is ready before running migrations --- Dockerfile.migrate | 5 +++-- run-migrations.sh | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100755 run-migrations.sh diff --git a/Dockerfile.migrate b/Dockerfile.migrate index 9f4ff05..d6bb150 100644 --- a/Dockerfile.migrate +++ b/Dockerfile.migrate @@ -4,11 +4,12 @@ FROM alpine:3.18 ENV PGSERVICEFILE=/tmp/pg_service.conf ENV ALEMBIC_VERSION=head -RUN apk add --no-cache --update py3-alembic py3-psycopg2 +RUN apk add --no-cache --update postgresql-client py3-alembic py3-psycopg2 COPY pg_service.conf /tmp/pg_service.conf COPY alembic.ini /tmp/alembic.ini COPY alembic /tmp/alembic +COPY run-migrations.sh /tmp/run-migrations.sh WORKDIR /tmp -ENTRYPOINT ["/bin/sh", "-c", "PGSERVICE=qwc_configdb alembic upgrade ${ALEMBIC_VERSION}"] +ENTRYPOINT ["/tmp/run-migrations.sh"] diff --git a/run-migrations.sh b/run-migrations.sh new file mode 100755 index 0000000..0a14eda --- /dev/null +++ b/run-migrations.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +until psql service=qwc_configdb -c "select 1" > /dev/null 2>&1; do + echo "Waiting for postgres server..." + sleep 1 +done + +PGSERVICE=qwc_configdb alembic upgrade ${ALEMBIC_VERSION}