Skip to content

Commit

Permalink
deploy: Use whitenoise and gunicorn for production deploys
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb authored and michaelwood committed Mar 15, 2021
1 parent 662e440 commit fdae3aa
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
uses: supercharge/redis-github-action@1.2.0
with:
redis-version: 6
- name: Collect static files
run: ./standards_lab/manage.py collectstatic
- name: Run tests
run: coverage run --source='./standards_lab' ./standards_lab/manage.py test ./standards_lab

Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ RUN pip install -r /code/requirements_dev.txt
COPY . /code/
WORKDIR /code/
ENV ROOT_PROJECTS_DIR=/projects_dir
ENV STATIC_ROOT=/staticfiles
RUN sh -c 'cd standards_lab && python manage.py collectstatic'
CMD sh -c ' \
mkdir -p "$ROOT_PROJECTS_DIR" && \
cd standards_lab && \
python manage.py runserver 0.0.0.0:80 \
gunicorn --bind 0.0.0.0:80 wsgi:application \
'
EXPOSE 80
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: env DEBUG=False sh -c 'cd /code/standards_lab && python manage.py runserver 0.0.0.0:80'
web: env DEBUG=False sh -c 'cd /code/standards_lab && gunicorn --bind 0.0.0.0:80 wsgi:application'
worker: env DEBUG=False sh -c 'cd /code/standards_lab && python manage.py rqworker default'
4 changes: 4 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ django-rq==2.4.0
pip-tools
django-environ
django-redis==4.12.*

# For production
gunicorn
whitenoise
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ et-xmlfile==1.0.1
# via openpyxl
flattentool==0.15.3
# via libcove
gunicorn==20.0.4
# via -r requirements.in
idna==2.10
# via requests
importlib-metadata==1.7.0
Expand Down Expand Up @@ -136,6 +138,8 @@ urllib3==1.26.3
# via
# requests
# sentry-sdk
whitenoise==5.2.0
# via -r requirements.in
xmltodict==0.12.0
# via
# flattentool
Expand Down
8 changes: 6 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ commonmark==0.9.1
# via libcove
contextlib2==0.6.0.post1
# via schema
dealer==2.1.0
# via libcoveweb
coverage==5.5
# via coveralls
coveralls==3.0.1
# via -r requirements_dev.in
dealer==2.1.0
# via libcoveweb
defusedxml==0.6.0
# via odfpy
django-bootstrap3==14.2.0
Expand Down Expand Up @@ -67,6 +67,8 @@ flake8==3.8.4
# via -r requirements_dev.in
flattentool==0.15.3
# via libcove
gunicorn==20.0.4
# via -r requirements.in
idna==2.10
# via requests
importlib-metadata==1.7.0
Expand Down Expand Up @@ -172,6 +174,8 @@ urllib3==1.26.3
# requests
# selenium
# sentry-sdk
whitenoise==5.2.0
# via -r requirements.in
xmltodict==0.12.0
# via
# flattentool
Expand Down
14 changes: 10 additions & 4 deletions standards_lab/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@
)


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


env = environ.Env(
REDIS_URL=(str, "redis://localhost:6379"),
ROOT_PROJECTS_DIR=(str, "/tmp/standards-lab/"),
ALLOWED_HOSTS=(list, []),
DEBUG=(bool, True),
SECRET_KEY=(str, secret_key),
STATIC_ROOT=(str, os.path.join(BASE_DIR, "staticfiles")),
)


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

Expand Down Expand Up @@ -67,6 +68,7 @@

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
Expand Down Expand Up @@ -144,6 +146,10 @@

STATIC_URL = "/static/"

STATIC_ROOT = env("STATIC_ROOT")

STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

INTERNAL_IPS = ("127.0.0.1",)

REDIS_URL = env("REDIS_URL")
Expand Down

0 comments on commit fdae3aa

Please sign in to comment.