Skip to content

Commit

Permalink
Added heroku support for deploying online
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben69695 committed Jun 17, 2022
1 parent 23c3239 commit 996aa85
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release: python manage.py migrate
web: gunicorn webpersonal.wsgi
13 changes: 8 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"

services:
db:
image: postgres
image: postgres:14.3-bullseye
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
Expand All @@ -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

3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.9.13
Binary file added static/favicon.ico
Binary file not shown.
26 changes: 14 additions & 12 deletions webpersonal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 996aa85

Please sign in to comment.