Skip to content

Commit 23e1f6c

Browse files
committed
first pass at prod setup
1 parent 64b2f83 commit 23e1f6c

File tree

11 files changed

+115
-38
lines changed

11 files changed

+115
-38
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ node_modules
2121
*/static/libs/modernizr.js
2222
inspections.log*
2323
ssl
24+
pgdata/

compose/django/Dockerfile

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ RUN set -x \
3535
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
3636

3737
# Build Python virtualenv
38-
ADD ./requirements /code/requirements
38+
COPY ./requirements /code/requirements
3939
RUN set -ex \
4040
&& pip install -U virtualenv \
4141
&& virtualenv /venv \
42-
&& LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "/venv/bin/pip install -r /code/requirements/dev.txt"
42+
&& LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "/venv/bin/pip install -r /code/requirements/production.txt"
4343

44-
ADD . /code/
44+
COPY . /code/
45+
46+
RUN /venv/bin/python manage.py collectstatic --noinput
4547

4648
CMD ["/code/compose/django/runserver.sh"]

compose/django/Dockerfile.override

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM python:3.5-slim
2+
3+
# Ensure that Python outputs everything that's printed inside
4+
# the application rather than buffering it.
5+
ENV PYTHONUNBUFFERED 1
6+
7+
RUN mkdir /code
8+
WORKDIR /code
9+
10+
# Setup the locales in the Dockerfile
11+
RUN set -x \
12+
&& apt-get update \
13+
&& apt-get install locales -y \
14+
&& locale-gen en_US.UTF-8
15+
16+
# Install dependencies
17+
RUN set -x \
18+
&& apt-get install \
19+
wget \
20+
bzip2 \
21+
gcc \
22+
libpq-dev \
23+
libjpeg-dev \
24+
libffi-dev \
25+
libxml2-dev \
26+
libxslt1-dev \
27+
binutils \
28+
libproj-dev \
29+
gdal-bin \
30+
nodejs \
31+
git-core \
32+
--no-install-recommends -y \
33+
&& apt-get autoremove -y \
34+
&& apt-get clean \
35+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
36+
37+
# Build Python virtualenv
38+
ADD ./requirements /code/requirements
39+
RUN set -ex \
40+
&& pip install -U virtualenv \
41+
&& virtualenv /venv \
42+
&& LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "/venv/bin/pip install -r /code/requirements/dev.txt"
43+
44+
ADD . /code/
45+
46+
CMD ["/code/compose/django/runserver.sh"]

docker-compose.override.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: '3'
2+
3+
services:
4+
db:
5+
restart: always
6+
image: mdillon/postgis:9.3
7+
volumes:
8+
- ./pgdata:/var/lib/postgresql/data
9+
expose:
10+
- "5432"
11+
app:
12+
env_file: .env
13+
build:
14+
context: .
15+
dockerfile: ./compose/django/Dockerfile
16+
volumes:
17+
- .:/code
18+
links:
19+
- db:db
20+
ports:
21+
- "8000:8000"
22+
depends_on:
23+
- db

docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ services:
44
db:
55
restart: always
66
image: mdillon/postgis:9.3
7+
volumes:
8+
- ./pgdata:/var/lib/postgresql/data
79
expose:
810
- "5432"
911
app:
1012
env_file: .env
1113
build:
1214
context: .
1315
dockerfile: ./compose/django/Dockerfile
14-
volumes:
15-
- .:/code
1616
links:
1717
- db:db
1818
ports:

eatsmart/settings/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@
3434
'django.contrib.contenttypes',
3535
'django.contrib.sessions',
3636
'django.contrib.messages',
37+
'whitenoise.runserver_nostatic',
3738
'django.contrib.staticfiles',
3839
'django.contrib.admin',
3940
'django.contrib.humanize',
4041
'django.contrib.sitemaps',
4142
'django.contrib.gis',
4243
# External apps
43-
'compressor',
44+
# 'compressor',
4445
'tastypie',
4546
'leaflet',
4647
# Internal apps
@@ -53,6 +54,7 @@
5354
MIDDLEWARE_CLASSES = [
5455
'django.middleware.security.SecurityMiddleware',
5556
'django.contrib.sessions.middleware.SessionMiddleware',
57+
'whitenoise.middleware.WhiteNoiseMiddleware',
5658
'django.middleware.locale.LocaleMiddleware',
5759
'django.middleware.common.CommonMiddleware',
5860
'django.middleware.csrf.CsrfViewMiddleware',

eatsmart/settings/deploy.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Settings for live deployed environments: vagrant, staging, production, etc
22
from .base import * # noqa
3+
import dj_database_url
34

45
os.environ.setdefault('CACHE_HOST', '127.0.0.1:11211')
56
os.environ.setdefault('BROKER_HOST', '127.0.0.1:5672')
@@ -11,11 +12,11 @@
1112

1213
DEBUG = False
1314

14-
DATABASES['default']['NAME'] = 'eatsmart_%s' % ENVIRONMENT.lower()
15-
DATABASES['default']['USER'] = 'eatsmart_%s' % ENVIRONMENT.lower()
16-
DATABASES['default']['HOST'] = os.environ.get('DB_HOST', '')
17-
DATABASES['default']['PORT'] = os.environ.get('DB_PORT', '')
18-
DATABASES['default']['PASSWORD'] = os.environ.get('DB_PASSWORD', '')
15+
# Update database configuration with $DATABASE_URL.
16+
db_from_env = dj_database_url.config(conn_max_age=500)
17+
DATABASES['default'].update(db_from_env) # noqa: F405
18+
19+
# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
1920

2021
WEBSERVER_ROOT = '/var/www/eatsmart/'
2122

@@ -25,12 +26,12 @@
2526

2627
MEDIA_ROOT = os.path.join(PUBLIC_ROOT, 'media')
2728

28-
CACHES = {
29-
'default': {
30-
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
31-
'LOCATION': '%(CACHE_HOST)s' % os.environ,
32-
}
33-
}
29+
# CACHES = {
30+
# 'default': {
31+
# 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
32+
# 'LOCATION': '%(CACHE_HOST)s' % os.environ,
33+
# }
34+
# }
3435

3536
EMAIL_HOST = os.environ.get('EMAIL_HOST', 'localhost')
3637
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER', '')
@@ -50,13 +51,13 @@
5051
DEFAULT_FROM_EMAIL = 'noreply@%(DOMAIN)s' % os.environ
5152
SERVER_EMAIL = DEFAULT_FROM_EMAIL
5253

53-
CSRF_COOKIE_SECURE = True
54+
# CSRF_COOKIE_SECURE = True
5455

55-
SESSION_COOKIE_SECURE = True
56+
# SESSION_COOKIE_SECURE = True
5657

5758
SESSION_COOKIE_HTTPONLY = True
5859

59-
ALLOWED_HOSTS = [os.environ['DOMAIN']]
60+
ALLOWED_HOSTS = ['*']
6061

6162
# Use template caching on deployed servers
6263
for backend in TEMPLATES:

eatsmart/static/css/site.css

+17-17
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ p.value {
119119
font-size:40px;
120120
float:left;
121121
display:block;
122-
padding:0 15px 0 0;
122+
padding:0 15px 0 0;
123123
margin:-7px 0 0 0;
124124
}
125125

@@ -135,12 +135,12 @@ p.value {
135135
.foodlisting .risk-factor { margin-top:10px;margin-bottom:0px;}
136136

137137
.risk-factor li {
138-
background-size:25px 25px;
138+
background-size:25px 25px;
139139
width:25px;
140140
height:25px;
141141
opacity:0.2;}
142142

143-
143+
144144
.detail-risk-factor li {
145145
list-style:none;
146146
line-height:60px;
@@ -150,7 +150,7 @@ p.value {
150150
clear:left;
151151
}
152152

153-
.detail-risk-factor li::before {
153+
.detail-risk-factor li::before {
154154
width:50px;
155155
height:50px;
156156
opacity:0.2;
@@ -185,37 +185,37 @@ p.value {
185185

186186

187187
/* Individual Icons */
188-
188+
189189
.detail-risk-factor li.source::before {
190190
content: url(https://ncfoodinspector.com/static/css/source-icon.svg);
191191
}
192-
192+
193193
.detail-risk-factor li.temperature::before {
194194
content: url(https://ncfoodinspector.com/static/css/temperature-icon.svg);
195195
}
196-
196+
197197
.detail-risk-factor li.contamination::before {
198198
content: url(https://ncfoodinspector.com/static/css/contamination-icon.svg);
199199
}
200-
200+
201201
.detail-risk-factor li.holding::before {
202202
content: url(https://ncfoodinspector.com/static/css/holding-icon.svg);
203203
}
204-
204+
205205
.detail-risk-factor li.hygiene::before {
206206
content: url(https://ncfoodinspector.com/static/css/hygiene-icon.svg);
207207
}
208-
209-
.risk-factor li[class*="source"] {background:url('https://ncfoodinspector.com/static/css/source-icon.svg') no-repeat; background-size:25px 25px;}
210-
211-
212-
.foodlisting .risk-factor li[class*="temperature"] {background:url('https://ncfoodinspector.com/static/css/temperature-icon.svg') no-repeat; background-size:25px 25px;}
213208

214-
.foodlisting .risk-factor li[class*="contamination"] {background:url('https://ncfoodinspector.com/static/css/contamination-icon.svg') no-repeat; background-size:25px 25px;}
209+
.risk-factor li[class*="source"] {background:url('source-icon.svg') no-repeat; background-size:25px 25px;}
210+
211+
212+
.foodlisting .risk-factor li[class*="temperature"] {background:url('temperature-icon.svg') no-repeat; background-size:25px 25px;}
213+
214+
.foodlisting .risk-factor li[class*="contamination"] {background:url('contamination-icon.svg') no-repeat; background-size:25px 25px;}
215215

216-
.foodlisting .risk-factor li[class*="holding"] {background:url('https://ncfoodinspector.com/static/css/holding-icon.svg') no-repeat; background-size:25px 25px;}
216+
.foodlisting .risk-factor li[class*="holding"] {background:url('holding-icon.svg') no-repeat; background-size:25px 25px;}
217217

218-
.foodlisting .risk-factor li[class*="hygiene"] {background:url('https://ncfoodinspector.com/static/css/hygiene-icon.svg') no-repeat; background-size:25px 25px;}
218+
.foodlisting .risk-factor li[class*="hygiene"] {background:url('hygiene-icon.svg') no-repeat; background-size:25px 25px;}
219219

220220

221221

eatsmart/templates/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load compress i18n %}
1+
{% load i18n %}
22
{% load static from staticfiles %}
33
{% load leaflet_tags %}
44

requirements/base.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ BeautifulSoup4==4.4.0
1313

1414
django-leaflet==0.18.1
1515
requests==2.2.1
16+
whitenoise==3.3.0

requirements/production.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
-r base.txt
22
python3-memcached==1.51
3+
dj-database-url==0.4.2

0 commit comments

Comments
 (0)