diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..757af8a --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +release: python manage.py migrate +web: gunicorn webpersonal.wsgi diff --git a/docker-compose.yml b/docker-compose.yml index dbcc21a..51b63ee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3.9" services: db: - image: postgres + image: postgres:14.3-bullseye volumes: - ./data/db:/var/lib/postgresql/data environment: @@ -14,15 +14,18 @@ services: web: build: . command: > - sh -c "python manage.py migrate && + sh -c "python manage.py collectstatic --noinput && + python manage.py migrate && python manage.py runserver 0.0.0.0:8000" volumes: - .:/src ports: - "8000:8000" environment: - - POSTGRES_NAME=postgres - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres + - DATABASE_URL=postgres://postgres:postgres@db:5432/postgres + - DEBUG=False + - PGSSL=False + - SECRET_KEY=${DJANGO_SECRET_KEY} depends_on: - db + diff --git a/requirements.txt b/requirements.txt index 4276ed5..58efeb2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,6 @@ Django==4.0.4 Pillow==9.1.1 psycopg2-binary==2.9.3 +dj-database-url==0.5.0 +gunicorn==20.1.0 +whitenoise==6.2.0 diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..c6f7782 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.9.13 diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000..e244582 Binary files /dev/null and b/static/favicon.ico differ diff --git a/webpersonal/settings.py b/webpersonal/settings.py index 97ae870..3a52ff5 100644 --- a/webpersonal/settings.py +++ b/webpersonal/settings.py @@ -11,21 +11,25 @@ """ import os +import dj_database_url -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +from pathlib import Path +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = Path(__file__).resolve().parent.parent +STATIC_ROOT = os.path.join(BASE_DIR, 'static') +STATIC_URL = 'static/' # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'ae08^9v)^u)h-y6urnicudz$d4+$fr0*14bf%6%-#pp8dinzk3' +SECRET_KEY = os.environ.get('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = True if os.environ.get('DEBUG', 'True') == 'True' else False -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = [] if os.environ.get('DEBUG', 'True') == 'True' else ['*'] # Application definition @@ -50,6 +54,7 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', ] ROOT_URLCONF = 'webpersonal.urls' @@ -79,14 +84,13 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': os.environ.get('POSTGRES_NAME'), - 'USER': os.environ.get('POSTGRES_USER'), - 'PASSWORD': os.environ.get('POSTGRES_PASSWORD'), - 'HOST': 'db', - 'PORT': 5432, } } +PGSSL = False if os.environ.get('PGSSL', 'False') == 'False' else True + +DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=PGSSL) + # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -123,8 +127,6 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.1/howto/static-files/ -STATIC_URL = '/static/' - # Media files MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, "media")