From 6857bc69b5160a925750a9800b6a7e4b35007915 Mon Sep 17 00:00:00 2001 From: Thomas Jespersen Date: Tue, 9 Feb 2021 22:48:53 +0100 Subject: [PATCH] docker: Add entrypoint.sh Apparently I forgot to add this file in previous commits - the initial shape is provided by @valberg, I added some defaults for POSTGRES_{HOST,PORT}. --- docker/Dockerfile | 2 +- entrypoint.sh | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 entrypoint.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index eae7123..6cd196e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -39,5 +39,5 @@ RUN mkdir /app/static && chown www:www /app/static ARG BUILD ENV BUILD ${BUILD} -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT ["./entrypoint.sh"] CMD ["uvicorn", "config.asgi:application", "--host", "0.0.0.0", "--port", "8080", "--workers", "3", "--lifespan", "off"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..cdce425 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +echo "Waiting for postgres..." + +POSTGRES_PORT=${POSTGRES_PORT:-5432} +POSTGRES_HOST=${POSTGRES_HOST:-localhost} + +while ! nc -z "$POSTGRES_HOST" "$POSTGRES_PORT"; do + sleep 0.1 +done + +echo "PostgreSQL started" + +# Only migrate and collectstatic if we are NOT in development +if [ -z "$DEBUG" ]; then + python manage.py migrate + python manage.py collectstatic --no-input; +fi + +exec "$@" +