feat: Package into a container

This commit is contained in:
Thomas Schwery 2022-03-06 15:12:40 +01:00
parent 362e9792e9
commit 9b63e2b0b2
6 changed files with 33 additions and 3 deletions

5
.containerignore Normal file
View file

@ -0,0 +1,5 @@
/db
/dumps
/env
__pycache__
.env*

6
.gitignore vendored
View file

@ -1,3 +1,5 @@
env
/db
/dumps
/env
__pycache__
*.sqlite3
.env*

15
Containerfile Normal file
View file

@ -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"]

0
db/.gitkeep Normal file
View file

View file

@ -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

View file

@ -1 +1,3 @@
Django==4.0.2
whitenoise==6.0.0
gunicorn==20.1.0