chore: wait for postgres in docker compose

This commit is contained in:
Ali BARIN
2022-08-31 21:28:35 +02:00
parent 827fef8a05
commit 6e9a9992c0
2 changed files with 15 additions and 1 deletions

View File

@@ -2,6 +2,9 @@
FROM node:16
WORKDIR /automatisch
RUN apt-get update && apt-get install -y postgresql-client
COPY ./docker/wait-for-postgres.sh /automatisch/wait-for-postgres.sh
# npm registry for dev purposes
RUN npm config set fetch-retry-maxtimeout 5000
RUN npm config set fetch-retry-mintimeout 3000
@@ -15,4 +18,4 @@ RUN echo "APP_SECRET_KEY=$(openssl rand -base64 36)" >> /automatisch/storage/.en
RUN yarn global add @automatisch/cli
EXPOSE 3000
CMD ["automatisch", "start", "--env-file=/automatisch/storage/.env"]
CMD sh /automatisch/wait-for-postgres.sh automatisch start --env-file=/automatisch/storage/.env

View File

@@ -0,0 +1,11 @@
#!/bin/sh
set -e
until psql -h "$POSTGRES_HOST" -U "$POSTGRES_USERNAME" -d "$POSTGRES_HOST" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
exec "$@"