From 9b63e2b0b28b7480a3392743e6c25d300b16cc3d Mon Sep 17 00:00:00 2001 From: Thomas Schwery Date: Sun, 6 Mar 2022 15:12:40 +0100 Subject: [PATCH] feat: Package into a container --- .containerignore | 5 +++++ .gitignore | 6 ++++-- Containerfile | 15 +++++++++++++++ db/.gitkeep | 0 djangotea/settings.py | 8 +++++++- requirements.txt | 2 ++ 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 .containerignore create mode 100644 Containerfile create mode 100644 db/.gitkeep diff --git a/.containerignore b/.containerignore new file mode 100644 index 0000000..7f4f1fc --- /dev/null +++ b/.containerignore @@ -0,0 +1,5 @@ +/db +/dumps +/env +__pycache__ +.env* diff --git a/.gitignore b/.gitignore index acfdee3..7f4f1fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ -env +/db +/dumps +/env __pycache__ -*.sqlite3 +.env* diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..f3ecef2 --- /dev/null +++ b/Containerfile @@ -0,0 +1,15 @@ +FROM docker.io/python:3.9-alpine + +# Allows docker to cache installed dependencies between builds +COPY requirements.txt requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +COPY . code +WORKDIR /code + +EXPOSE 8000 + +RUN python3 /code/manage.py collectstatic --no-input + +ENTRYPOINT ["gunicorn"] +CMD ["djangotea.wsgi:application", "--bind=0.0.0.0:8000"] diff --git a/db/.gitkeep b/db/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/djangotea/settings.py b/djangotea/settings.py index 7fa0d36..ec7ab65 100644 --- a/djangotea/settings.py +++ b/djangotea/settings.py @@ -29,6 +29,10 @@ ALLOWED_HOSTS = [ '*', ] +CSRF_TRUSTED_ORIGINS = [ + os.environ.get('CSRF_TRUSTED_ORIGINS') +] + # Application definition INSTALLED_APPS = [ @@ -45,6 +49,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + "whitenoise.middleware.WhiteNoiseMiddleware", 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -80,7 +85,7 @@ WSGI_APPLICATION = 'djangotea.wsgi.application' DATABASES = { 'default': { "ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"), - "NAME": os.environ.get("SQL_DATABASE", os.path.join(BASE_DIR, "db.sqlite3")), + "NAME": os.environ.get("SQL_DATABASE", os.path.join(BASE_DIR, "db", "db.sqlite3")), "USER": os.environ.get("SQL_USER", "user"), "PASSWORD": os.environ.get("SQL_PASSWORD", "password"), "HOST": os.environ.get("SQL_HOST", "localhost"), @@ -124,6 +129,7 @@ USE_TZ = True # https://docs.djangoproject.com/en/4.0/howto/static-files/ STATIC_URL = 'static/' +STATIC_ROOT = os.path.join(BASE_DIR, "static") # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field diff --git a/requirements.txt b/requirements.txt index ab09bb7..2f0bb8f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ Django==4.0.2 +whitenoise==6.0.0 +gunicorn==20.1.0