Skip to content

Commit b7fe8c7

Browse files
authored
Merge pull request #6 from HackSoftware/add-heroku-setup
Add Heroku Setup / Production settings
2 parents a8067ba + a45f8f5 commit b7fe8c7

File tree

9 files changed

+70
-1
lines changed

9 files changed

+70
-1
lines changed

.github/workflows/django.yml

+11
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ jobs:
3030
run: python manage.py migrate
3131
- name: Run tests
3232
run: py.test
33+
deploy_to_heroku:
34+
runs-on: ubuntu-latest
35+
needs: build
36+
if: github.ref == 'refs/heads/master'
37+
steps:
38+
- uses: actions/checkout@v1
39+
- name: Deploy to Heroku
40+
env:
41+
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
42+
HEROKU_APP_NAME: 'hacksoft-styleguide-example'
43+
run: git push --force https://heroku:[email protected]/$HEROKU_APP_NAME.git origin/master:master

Procfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
release: python manage.py migrate
2+
web: gunicorn config.wsgi:application
3+
worker: REMAP_SIGTERM=SIGQUIT celery --without-gossip --without-mingle --without-heartbeat worker -A styleguide_example.tasks -l info
4+
beat: REMAP_SIGTERM=SIGQUIT celery -A styleguide_example.tasks beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Few important things:
99
* Linux / Ubuntu is our primary OS and things are tested for that. It will mostly not work on Mac & certainly not work on Windows.
1010
* It uses Postgres as primary database.
1111
* It comes with GitHub Actions support, [based on that article](https://hacksoft.io/github-actions-in-action-setting-up-django-and-postgres/)
12+
* It comes with [`whitenoise`](http://whitenoise.evans.io/en/stable/) setup.
13+
* It can be easily deployed to Heroku.
1214

1315
## Helpful commands
1416

@@ -35,3 +37,7 @@ To start Celery Beat:
3537
```
3638
celery -A styleguide_example.tasks beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
3739
```
40+
41+
## Heroku
42+
43+
The project is ready to be deployed on Heroku. There's a current deployment that can be found - <https://hacksoft-styleguide-example.herokuapp.com/>

config/settings/base.py

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
MIDDLEWARE = [
6161
'django.middleware.security.SecurityMiddleware',
62+
'whitenoise.middleware.WhiteNoiseMiddleware',
6263
'django.contrib.sessions.middleware.SessionMiddleware',
6364
'django.middleware.common.CommonMiddleware',
6465
'django.middleware.csrf.CsrfViewMiddleware',
@@ -147,7 +148,10 @@
147148
# Static files (CSS, JavaScript, Images)
148149
# https://docs.djangoproject.com/en/3.0/howto/static-files/
149150

151+
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
150152
STATIC_URL = '/static/'
153+
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
154+
151155

152156
# https://django-rest-framework-simplejwt.readthedocs.io/en/latest/settings.html
153157
SIMPLE_JWT = {

config/settings/production.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from .base import * # noqa
2+
from .env_reader import env
3+
4+
DEBUG = env.bool('DJANGO_DEBUG', default=False)
5+
6+
SECRET_KEY = env('DJANGO_SECRET_KEY')
7+
8+
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=[])
9+
10+
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
11+
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
12+
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
13+
SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True)
14+
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure
15+
SESSION_COOKIE_SECURE = True
16+
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure
17+
CSRF_COOKIE_SECURE = True
18+
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
19+
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
20+
"DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True
21+
)
22+
23+
SENTRY_DSN = env('DJANGO_SENTRY_DSN', default='')
24+
25+
if SENTRY_DSN:
26+
import sentry_sdk
27+
from sentry_sdk.integrations.django import DjangoIntegration
28+
from sentry_sdk.integrations.celery import CeleryIntegration
29+
30+
sentry_sdk.init(
31+
dsn=SENTRY_DSN,
32+
integrations=[
33+
DjangoIntegration(),
34+
CeleryIntegration(),
35+
]
36+
)

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-r requirements/base.txt
1+
-r requirements/production.txt

requirements/base.txt

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ djangorestframework-simplejwt==4.4.0
77
celery==4.4.6
88
django-celery-results==1.2.1
99
django-celery-beat==2.0.0
10+
11+
whitenoise==5.1.0

requirements/production.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-r base.txt
2+
3+
whitenoise==5.1.0
4+
gunicorn==20.0.4
5+
sentry-sdk==0.16.0

runtime.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-3.7.7

0 commit comments

Comments
 (0)