diff --git a/Dockerfile b/Dockerfile index e055b542..54edef55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/docker/wait-for-postgres.sh b/docker/wait-for-postgres.sh new file mode 100644 index 00000000..450fffec --- /dev/null +++ b/docker/wait-for-postgres.sh @@ -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 "$@"