Skip to content

Commit 6d55ad9

Browse files
committed
Make Production Ready
1 parent 3e17d4c commit 6d55ad9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+937
-108
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
todo programdom readme

compose/local/django/Dockerfile

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
FROM python:3.7-alpine
1+
FROM node:alpine as static
2+
COPY package.json /package.json
3+
RUN npm install -g gulp
4+
RUN npm install
5+
WORKDIR /static
6+
COPY ./programdom/static /programdom/static
7+
COPY ./gulpfile.prod.js /gulpfile.js
8+
RUN gulp build
9+
210

11+
FROM python:3.7-alpine
12+
COPY --from=static /static /app/programdom/static
313
ENV PYTHONUNBUFFERED 1
414

515
RUN apk update \
616
# psycopg2 dependencies
717
&& apk add --virtual build-deps gcc python3-dev musl-dev \
818
&& apk add postgresql-dev \
9-
# Pillow dependencies
10-
&& apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
1119
# CFFI dependencies
1220
&& apk add libffi-dev py-cffi \
1321
# Translations dependencies
1422
&& apk add gettext \
1523
# https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell
16-
&& apk add postgresql-client
24+
&& apk add postgresql-client \
25+
&& apk add libxml2-dev libxslt-dev
26+
1727

1828
# Requirements are installed here to ensure they will be cached.
1929
COPY ./requirements /requirements
20-
RUN pip install -r /requirements/local.txt
30+
RUN pip install -r /requirements/production.txt
2131

2232
COPY ./compose/local/django/entrypoint /entrypoint
2333
RUN sed -i 's/\r//' /entrypoint
@@ -27,6 +37,8 @@ COPY ./compose/local/django/start /start
2737
RUN sed -i 's/\r//' /start
2838
RUN chmod +x /start
2939

40+
COPY . /app
41+
3042
WORKDIR /app
3143

3244
ENTRYPOINT ["/entrypoint"]

compose/local/django/entrypoint

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ set -o errexit
44
set -o pipefail
55
set -o nounset
66

7-
8-
# N.B. If only .env files supported variable expansion...
9-
export CELERY_BROKER_URL="${REDIS_URL}"
10-
117
if [ -z "${POSTGRES_USER}" ]; then
128
base_postgres_image_default_user='postgres'
139
export POSTGRES_USER="${base_postgres_image_default_user}"
1410
fi
1511
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
12+
export REDIS_URL="redis://${REDIS_HOST}/"
1613

1714
postgres_ready() {
1815
python << END

compose/local/django/start

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ set -o nounset
66

77

88
python manage.py migrate
9-
python manage.py runserver_plus 0.0.0.0:8000
9+
python manage.py collectstatic --no-input
10+
daphne -b 0.0.0.0 -p 8000 config.asgi:application
11+
File renamed without changes.

config/asgi.py

Whitespace-only changes.

config/settings/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
# ------------------------------------------------------------------------------
5050
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
5151

52+
DATABASES = {
53+
'default': env.db('DATABASE_URL', default='postgresql://postgres:postgrespassword@localhost:5432/postgres'),
54+
}
5255

5356
# URLS
5457
# ------------------------------------------------------------------------------
@@ -159,6 +162,9 @@
159162
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
160163
]
161164

165+
# Clear the session when the user closes the browser, so that they are not part of another workshop next time
166+
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
167+
162168
# MEDIA
163169
# ------------------------------------------------------------------------------
164170
# https://docs.djangoproject.com/en/dev/ref/settings/#media-root
@@ -237,3 +243,5 @@
237243
# ------------------------------------------------------------------------------
238244
#
239245

246+
# Time to wait before repolling Judge0 for a new status
247+
JUDGE0_POLL_WAIT = 1

config/settings/local.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
}
2828
}
2929

30-
DATABASES = {
31-
'default': env.db('DATABASE_URL', 'postgresql://postgres@localhost:5432/postgres'),
32-
}
3330

3431
# Sessions
3532
# ------------------------------------------------------------------------------

config/settings/production.py

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,57 @@
1717
}
1818
}
1919

20+
INSTALLED_APPS += ['minio_storage'] # noqa F405
21+
22+
DEFAULT_FILE_STORAGE = "minio_storage.storage.MinioMediaStorage"
23+
STATICFILES_STORAGE = "minio_storage.storage.MinioStaticStorage"
24+
MINIO_STORAGE_ENDPOINT = f"{env('MINIO_SERVER')}:9000"
25+
MINIO_STORAGE_ACCESS_KEY = env('MINIO_ACCESS_KEY')
26+
MINIO_STORAGE_SECRET_KEY = env('MINIO_SECRET_KEY')
27+
MINIO_STORAGE_USE_HTTPS = False
28+
MINIO_STORAGE_MEDIA_BUCKET_NAME = 'media'
29+
MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET = True
30+
MINIO_STORAGE_STATIC_BUCKET_NAME = 'static'
31+
MINIO_STORAGE_AUTO_CREATE_STATIC_BUCKET = True
32+
MINIO_STORAGE_MEDIA_URL = "/media"
33+
MINIO_STORAGE_STATIC_URL = "/static"
34+
35+
MINIO_STORAGE_AUTO_CREATE_STATIC_POLICY = True
36+
MINIO_STORAGE_AUTO_CREATE_MEDIA_POLICY = True
37+
2038
# SECURITY
2139
# ------------------------------------------------------------------------------
22-
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
23-
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
24-
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
25-
SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True)
40+
# # https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
41+
# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
42+
# # https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
43+
# SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True)
2644
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure
27-
SESSION_COOKIE_SECURE = True
28-
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-httponly
29-
SESSION_COOKIE_HTTPONLY = True
30-
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure
31-
CSRF_COOKIE_SECURE = True
32-
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-httponly
33-
CSRF_COOKIE_HTTPONLY = True
34-
# https://docs.djangoproject.com/en/dev/topics/security/#ssl-https
35-
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-seconds
36-
# TODO: set this to 60 seconds first and then to 518400 once you prove the former works
37-
SECURE_HSTS_SECONDS = 60
38-
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains
39-
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool('DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS', default=True)
40-
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload
41-
SECURE_HSTS_PRELOAD = env.bool('DJANGO_SECURE_HSTS_PRELOAD', default=True)
42-
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
43-
SECURE_CONTENT_TYPE_NOSNIFF = env.bool('DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True)
44-
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-browser-xss-filter
45-
SECURE_BROWSER_XSS_FILTER = True
46-
# https://docs.djangoproject.com/en/dev/ref/settings/#x-frame-options
47-
X_FRAME_OPTIONS = 'DENY'
48-
49-
45+
# SESSION_COOKIE_SECURE = True
46+
# # https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-httponly
47+
# SESSION_COOKIE_HTTPONLY = True
48+
# # https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure
49+
# CSRF_COOKIE_SECURE = True
50+
# # https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-httponly
51+
# CSRF_COOKIE_HTTPONLY = True
52+
# # https://docs.djangoproject.com/en/dev/topics/security/#ssl-https
53+
# # https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-seconds
54+
# # TODO: set this to 60 seconds first and then to 518400 once you prove the former works
55+
# SECURE_HSTS_SECONDS = 60
56+
# # https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains
57+
# SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool('DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS', default=True)
58+
# # https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload
59+
# SECURE_HSTS_PRELOAD = env.bool('DJANGO_SECURE_HSTS_PRELOAD', default=True)
60+
# # https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
61+
# SECURE_CONTENT_TYPE_NOSNIFF = env.bool('DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True)
62+
# # https://docs.djangoproject.com/en/dev/ref/settings/#secure-browser-xss-filter
63+
# SECURE_BROWSER_XSS_FILTER = True
64+
# # https://docs.djangoproject.com/en/dev/ref/settings/#x-frame-options
65+
# X_FRAME_OPTIONS = 'DENY'
66+
67+
SECRET_KEY = env('DJANGO_SECRET_KEY')
68+
69+
#TODO: change this to the hostname that you want to listen on
70+
ALLOWED_HOSTS = "*"
5071

5172
# TEMPLATES
5273
# ------------------------------------------------------------------------------
@@ -65,25 +86,7 @@
6586
# ------------------------------------------------------------------------------
6687
# https://docs.djangoproject.com/en/dev/ref/settings/#server-email
6788
# https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
68-
EMAIL_SUBJECT_PREFIX = env('DJANGO_EMAIL_SUBJECT_PREFIX', default='[AberCompSoc]')
69-
70-
MAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
71-
72-
EMAIL_HOST = env('DJANGO_SMTP_HOSTNAME', default='smtp.office365.com')
73-
EMAIL_PORT = env('DJANGO_SMTP_POST', default=587)
74-
EMAIL_HOST_USER = env('DJANGO_SMTP_USER')
75-
EMAIL_HOST_PASSWORD = env('DJANGO_SMTP_PASSWORD')
76-
77-
EMAIL_USE_TLS = True
78-
79-
80-
# https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email
81-
DEFAULT_FROM_EMAIL = env(
82-
'DJANGO_DEFAULT_FROM_EMAIL',
83-
default=EMAIL_HOST_USER
84-
)
85-
86-
SERVER_EMAIL = env('DJANGO_SERVER_EMAIL', default=DEFAULT_FROM_EMAIL)
89+
MAIL_BACKEND = 'django.core.mail.backends.console'
8790

8891
# Static Files
8992
#
@@ -143,3 +146,14 @@
143146

144147
# Your stuff...
145148
# ------------------------------------------------------------------------------
149+
150+
CHANNEL_LAYERS = {
151+
"default": {
152+
"BACKEND": "channels_redis.core.RedisChannelLayer",
153+
"CONFIG": {
154+
"hosts": [(env("REDIS_HOST"), 6379)],
155+
},
156+
},
157+
}
158+
159+
JUDGE0_ENDPOINT = "http://judgezero:3000"

config/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
WSGI config for AberCompSoc project.
2+
WSGI config for Programdom project.
33
44
This module contains the WSGI application used by Django's development server
55
and any production WSGI deployments. It should expose a module-level variable

docs/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
SOURCEDIR = source
8+
BUILDDIR = build
9+
10+
# Put it first so that "make" without argument is like "make help".
11+
help:
12+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
13+
14+
.PHONY: help Makefile
15+
16+
# Catch-all target: route all unknown targets to Sphinx using the new
17+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
18+
%: Makefile
19+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

0 commit comments

Comments
 (0)