diff --git a/Dockerfile b/Dockerfile index 0491a430..689ba3dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,14 +15,11 @@ FROM python:${PYTHON_VERSION} as python # Python build stage FROM python as python-build-stage - ARG BUILD_ENVIRONMENT=production # Install apt packages RUN apt-get update && apt-get install --no-install-recommends -y \ - # dependencies for building Python packages build-essential wget \ - # psycopg2 dependencies libpq-dev # Requirements are installed here to ensure they will be cached. @@ -32,7 +29,6 @@ COPY ./requirements . RUN pip wheel --wheel-dir /usr/src/app/wheels \ -r ${BUILD_ENVIRONMENT}.txt - # Python 'run' stage FROM python as python-run-stage ARG BUILD_ENVIRONMENT=production @@ -40,18 +36,14 @@ ARG APP_HOME=/app ENV PYTHONUNBUFFERED 1 ENV PYTHONDONTWRITEBYTECODE 1 ENV BUILD_ENV ${BUILD_ENVIRONMENT} +ENV DJANGO_SETTINGS_MODULE config.settings.production WORKDIR ${APP_HOME} - # Install required system dependencies RUN apt-get update && apt-get install --no-install-recommends -y \ - # psycopg2 dependencies libpq-dev \ - # Translations dependencies gettext \ - # wget wget \ - # cleaning up unused files && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ && rm -rf /var/lib/apt/lists/* @@ -63,12 +55,17 @@ COPY --from=python-build-stage /usr/src/app/wheels /wheels/ RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \ && rm -rf /wheels/ - -COPY ./entrypoint /entrypoint -RUN sed -i 's/\r$//g' /entrypoint -RUN chmod +x /entrypoint - # copy application code to WORKDIR COPY --from=client-builder ${APP_HOME} ${APP_HOME} -ENTRYPOINT ["/entrypoint"] +COPY ./prepare /prepare +RUN sed -i 's/\r$//g' /prepare +RUN chmod +x /prepare +RUN /prepare + +COPY ./start /start +RUN sed -i 's/\r$//g' /start +RUN chmod +x /start +RUN /start + +ENTRYPOINT ["/start"] diff --git a/cloudbuild.yaml b/cloudbuild.yaml index f4ed46c4..8e62b1e1 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -24,6 +24,7 @@ steps: '--region', 'europe-west1', '--platform', 'managed', '--allow-unauthenticated', + '--min-instances', '1', '--add-cloudsql-instances', '${_CLOUDSQL_INSTANCE_CONNECTION_NAME}', '--set-env-vars', 'GOOGLE_CLOUD_PROJECT=$PROJECT_ID,SETTINGS_NAME=mle_django_settings' ] diff --git a/config/settings/base.py b/config/settings/base.py index 49dfc52c..333b6c46 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -58,7 +58,6 @@ "ATOMIC_REQUESTS": True, } } -print(f"databases: {DATABASES}") # URLS # ------------------------------------------------------------------------------ diff --git a/config/settings/production.py b/config/settings/production.py index 2e827b00..70b8512e 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -112,7 +112,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 diff --git a/entrypoint b/entrypoint deleted file mode 100644 index 4799bf0b..00000000 --- a/entrypoint +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -set -o errexit -set -o pipefail -set -o nounset - -python /app/manage.py migrate ->&2 echo 'Ran database migrations...' - -python /app/manage.py createcachetable ->&2 echo 'Created the cache table...' - -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 - ->&2 echo 'About to run Gunicorn...' -/usr/local/bin/gunicorn config.asgi --bind 0.0.0.0:$PORT --chdir=/app -k uvicorn.workers.UvicornWorker diff --git a/pepfar_mle/common/migrations/0002_auto_20210713_0231.py b/pepfar_mle/common/migrations/0002_auto_20210713_0231.py new file mode 100644 index 00000000..5cafacb1 --- /dev/null +++ b/pepfar_mle/common/migrations/0002_auto_20210713_0231.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.12 on 2021-07-12 23:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='facilityattachment', + name='content_type', + field=models.CharField(choices=[('image/png', 'PNG'), ('image/jpeg', 'JPEG'), ('application/pdf', 'PDF'), ('application/vnd.ms-excel', 'xlsx'), ('application/msword', 'doc'), ('application/vnd.openxmlformats-officedocument.wordprocessingml.document.docx', 'docx'), ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xlsx'), ('text/plain', 'text')], max_length=100), + ), + ] diff --git a/prepare b/prepare new file mode 100755 index 00000000..87e2164e --- /dev/null +++ b/prepare @@ -0,0 +1,11 @@ +#!/bin/bash + +set -o errexit +set -o pipefail +set -o nounset + +python manage.py collectstatic --noinput +>&2 echo 'Collected static files...' + +python manage.py compress +>&2 echo 'Compressed static assets...' diff --git a/start b/start new file mode 100755 index 00000000..ec40c6c5 --- /dev/null +++ b/start @@ -0,0 +1,13 @@ +#!/bin/bash + +set -o errexit +set -o pipefail +set -o nounset + +python manage.py migrate +>&2 echo 'Ran database migrations...' + +python manage.py createcachetable +>&2 echo 'Created the cache table...' + +/usr/local/bin/gunicorn config.asgi --bind 0.0.0.0:$PORT --chdir=/app -k uvicorn.workers.UvicornWorker