Skip to content

Commit

Permalink
Ensure postgres server is ready before running migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 28, 2023
1 parent b260095 commit 7e1e105
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Dockerfile.migrate
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
8 changes: 8 additions & 0 deletions run-migrations.sh
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 7e1e105

Please sign in to comment.