Skip to content

Commit

Permalink
Making Mapbox API Key and env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalish committed Oct 24, 2018
1 parent b4ab608 commit b2f59da
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 44 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
update_anc_database_creds.py
ancfindersite/database.sqlite
data
user_local_environment.yaml

.DS_Store
*~
Expand All @@ -17,4 +18,5 @@ __pycache__
.Python
.python-version
lib
include
include
anc_finder_sql
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ RUN pip install -r requirements.txt
COPY ./ancfinder /srv/app/ancfinder
COPY ./ancfinder_site /srv/app/ancfinder_site
COPY ./manage.py /srv/app/manage.py
COPY ./run.sh /srv/app/run.sh

RUN chmod u+x /srv/app/run.sh

VOLUME /srv/app/static

EXPOSE 8000

# Ensure that the model and database are correctly mapped
# RUN python3 manage.py makemigrations
# RUN python3 manage.py migrate

# Run these when the container launches
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
CMD ["./run.sh"]
Binary file modified ancfinder/database.sqlite
Binary file not shown.
40 changes: 38 additions & 2 deletions ancfinder/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,53 @@
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_URL = env["STATIC_ROOT"]
STATIC_URL = "/static/"
STATIC_ROOT = env["STATIC_ROOT"]

MAPBOX_API_KEY = env["MAPBOX_API_KEY"]
elif os.environ["POSTGRES_PASSWORD"]:

SECRET_KEY = os.environ['DJANGO_SECRET_KEY']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'HOST': os.environ['POSTGRES_HOST'],
'PORT': int(os.environ['POSTGRES_PORT']),
'NAME': os.environ['POSTGRES_DB'],
'USER': os.environ['POSTGRES_USER'],
'PASSWORD': os.environ['POSTGRES_PASSWORD'],
}
}

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# EMAIL_HOST = env['SMTP_HOST']
# EMAIL_HOST_USER = env['SMTP_USER']
# EMAIL_HOST_PASSWORD = env['SMTP_PASSWORD']
# EMAIL_USE_TLS = True

ALLOWED_HOSTS = ["*"] # anything unexpected will be filtered out by the http server

OPENID_TEMP_FOLDER = "/tmp/openid-ancfinder"

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_URL = "/static/"
STATIC_ROOT = os.environ["STATIC_ROOT"]

MAPBOX_API_KEY = os.environ["MAPBOX_API_KEY"]
else:
print("Running development deployment...")

SECRET_KEY = '4k90fdv_y#5na2wul&fcd&xg23va!7#3h)we)6%c2ma8mt0uc-'
DEBUG = True
MAPBOX_API_KEY = os.environ['MAPBOX_API_KEY']

ALLOWED_HOSTS = ["*"]


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
Expand Down Expand Up @@ -112,7 +149,6 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'letsencrypt',
]

MIDDLEWARE = [
Expand Down
1 change: 0 additions & 1 deletion ancfinder_site/static/showdown.js

This file was deleted.

2 changes: 1 addition & 1 deletion ancfinder_site/templates/ancfinder_site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h2>Find Your ANC</h2>
{% endblock %}
{% block base_scripts %}
<script>
mapboxgl.accessToken = 'pk.eyJ1Ijoib3BlbmRhdGFkYyIsImEiOiJjaXp5dG55MjgwM2YxMnFuaHkwcmhzazViIn0.g5M1SkNciMdpOy5IJAs-ow';
mapboxgl.accessToken = "{{ MAPBOX_API_KEY }}";
var map = new mapboxgl.Map({
container: 'map',
center: [-77.0369, 38.9072],
Expand Down
2 changes: 1 addition & 1 deletion ancfinder_site/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

{% load staticfiles %}
<link href="{% static "css/theme.css" %}" rel="stylesheet">
<link href="{% static "css/normalize.css" %}" rel="stylesheet">
<link href="{% static "css/syntax.css" %}" rel="stylesheet">
Expand Down Expand Up @@ -83,7 +84,6 @@ <h1 class="site-title">
<p>ANC Finder is a project in Washington, D.C. to strengthen our unique hyper-local level of government called Advisory Neighborhood Commissions (ANCs).</p>
<p class="by">This is a project of <a href="http://codefordc.org/">Code for DC</a>. We’re volunteers interested in using technology to solve problems in our civic lives. The site is a work in progress.</p>
<p>The source code for this website is on <a href="https://github.com/codefordc/ancfinder">github</a>.</p>
<p>The <a href="http://ryantroyford.com/central-union-mission/">Central Union Mission-inspired font</a> in the header is by <a href="http://ryantroyford.com/">Ryan Troy Ford</a>.</p>
</div>
</footer>

Expand Down
2 changes: 2 additions & 0 deletions ancfinder_site/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.shortcuts import render
from django.http import Http404, HttpResponse
from django.views.generic import TemplateView
from django.conf import settings
import logging

from ancfinder_site.models import *
Expand Down Expand Up @@ -40,4 +41,5 @@ def TemplateContextProcessor(request):
return {
"ancs_by_ward": sorted(ancs_by_ward.items()),
"anc_list": sorted(anc_list),
"MAPBOX_API_KEY": settings.MAPBOX_API_KEY,
}
27 changes: 0 additions & 27 deletions deployment/docker-compose.yml

This file was deleted.

14 changes: 7 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ version: '3'
services:
postgres:
image: postgres
# TODO: use environment variable for password
environment:
- POSTGRES_PASSWORD=ancfinder_pass
- POSTGRES_USER=ancfinder
- POSTGRES_DB=ancfinder
env_file: .env
# TODO: copy the static media into nginx from ancfinder
nginx:
image: nginx:latest
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ./uswgi_params:/home/docker/code/uwsgi_params
- ./certs/letsencrypt:/etc/letsencrypt
- static:/ancfinder_static
ports:
- "80:80"
- "443:443"
links:
- ancfinder
ancfinder:
image: codefordc2/ancfinder:2.0
command: python manage.py runserver 0.0.0.0:8000
env_file: .env
links:
- postgres
volumes:
- ./environment.yaml:/home/ancfinder/environment.yaml
- ./user_local_environment.yaml:/srv/app/environment.yaml
- static:/srv/app/static
volumes:
static:
9 changes: 7 additions & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ server {
# max upload size
client_max_body_size 75M; # adjust to taste

location ~ {
proxy_pass http://ancfinder;
location /static/ {
autoindex on;
alias /ancfinder_static/;
}

location /.well-known/acme-challenge {
allow all;
root /usr/share/nginx/html;
}

location / {
proxy_pass http://ancfinder;
}
}
File renamed without changes.
5 changes: 5 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
sleep 5
python manage.py migrate
python manage.py collectstatic --noinput
python manage.py runserver 0.0.0.0:8000
9 changes: 9 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DJANGO_SECRET_KEY=

POSTGRES_PASSWORD=
POSTGRES_USER=ancfinder
POSTGRES_DB=ancfinder
POSTGRES_PORT=5432
POSTGRES_HOST=postgres
STATIC_ROOT=/srv/app/static
MAPBOX_API_KEY=

0 comments on commit b2f59da

Please sign in to comment.