Skip to content

Commit

Permalink
fix: simplify entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ngurenyaga committed Jul 14, 2021
1 parent 3afefb3 commit d912f8d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 48 deletions.
2 changes: 1 addition & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ steps:
'--platform', 'managed',
'--allow-unauthenticated',
'--add-cloudsql-instances', '${_CLOUDSQL_INSTANCE_CONNECTION_NAME}',
'--set-env-vars', 'GOOGLE_CLOUD_PROJECT=$PROJECT_ID,SETTINGS_NAME=mle_django_settings',
'--set-env-vars', 'GOOGLE_CLOUD_PROJECT=$PROJECT_ID,SETTINGS_NAME=mle_django_settings,DJANGO_SETTINGS_MODULE=config.settings.production',
'--min-instances', '1'
]

Expand Down
2 changes: 1 addition & 1 deletion config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
# django-compressor
# ------------------------------------------------------------------------------
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
COMPRESS_ENABLED = env.bool("COMPRESS_ENABLED", default=True)
COMPRESS_ENABLED = True
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL
COMPRESS_URL = STATIC_URL # noqa F405
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
Expand Down
48 changes: 2 additions & 46 deletions entrypoint
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,6 @@ set -o errexit
set -o pipefail
set -o nounset

postgres_ready() {
python << END
import sys
import psycopg2
try:
psycopg2.connect(
dbname="${POSTGRES_DB}",
user="${POSTGRES_USER}",
password="${POSTGRES_PASSWORD}",
host="${POSTGRES_HOST}",
port="${POSTGRES_PORT}",
)
except psycopg2.OperationalError:
sys.exit(-1)
sys.exit(0)
END
}
until postgres_ready; do
>&2 echo 'Waiting for PostgreSQL to become available...'
sleep 1
done
>&2 echo 'PostgreSQL is available'

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

Expand All @@ -39,26 +13,8 @@ python /app/manage.py createcachetable
python /app/manage.py collectstatic --noinput
>&2 echo 'Collected static files...'

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
python /app/manage.py compress
>&2 echo 'Compressed static assets...'

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

0 comments on commit d912f8d

Please sign in to comment.