Skip to content

Commit

Permalink
fix: combine start and entrypoint scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ngurenyaga committed Jul 12, 2021
1 parent 0cc3ca8 commit 7a78892
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ COPY --chown=django:django ./entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint

COPY --chown=django:django ./start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

# copy application code to WORKDIR
COPY --from=client-builder --chown=django:django ${APP_HOME} ${APP_HOME}

Expand Down
37 changes: 36 additions & 1 deletion entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ fi
# omit the port when running on App Engine, Cloud Run etc
if [ -z "${INSTANCE_CONNECTION_NAME}"]; then
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
echo "Set up database URL for running in Cloud SQL (Unix Socket)"
else
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}"
echo "Set up database URL for running outside Cloud SQL (host and port)"
fi

echo "Database URL: ${DATABASE_URL}"

postgres_ready() {
python << END
import sys
Expand All @@ -42,4 +46,35 @@ until postgres_ready; do
done
>&2 echo 'PostgreSQL is available'

exec "/start"
python /app/manage.py collectstatic --noinput
>&2 echo 'Collected static files...'

python /app/manage.py migrate
>&2 echo 'Ran database migrations...'

python /app/manage.py createcachetable
>&2 echo 'Created the cache table...'

compress_enabled() {
python << END
import sys
from environ import Env
env = Env(COMPRESS_ENABLED=(bool, True))
if env('COMPRESS_ENABLED'):
sys.exit(0)
else:
sys.exit(1)
END
}

if compress_enabled; then
# NOTE this command will fail if django-compressor is disabled
python /app/manage.py compress
>&2 echo 'Compressed static assets...'
fi

>&2 echo 'About to run Gunicorn...'
/usr/local/bin/gunicorn config.asgi --bind 0.0.0.0:$PORT --chdir=/app -k uvicorn.workers.UvicornWorker
32 changes: 0 additions & 32 deletions start

This file was deleted.

0 comments on commit 7a78892

Please sign in to comment.