Skip to content

Commit

Permalink
refactored settings.py to pull more variables from env settings
Browse files Browse the repository at this point in the history
  • Loading branch information
James Wallace authored and James Wallace committed Apr 15, 2020
1 parent 2f1a0bd commit c9382aa
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN apt-get install -y apt-utils vim curl apache2 apache2-utils lynx \
# add apache2 configs
ADD bartensor.dev.conf /etc/apache2/sites-available/000-default.conf

# add entrypoint
# add entrypoint script
ADD entrypoint.dev.sh .

# add the project
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,4 @@ The generated coverage reports are located in the coverage_reports directory. To

This repository features a CircleCI CICD pipeline that pushes new master branch images to an AWS Elastic Container Registry and updates a service running on an AWS Elastic Container Service Cluster. The update to the service forces a new deployment of the updated task definition. This pipeline will push master code base changes to the designated AWS resources within five minutes. The details of the deployment process can be seen in the CircleCI config.yml file.

To deploy this Django project, our team decided to serve our project with Apache2. We decided to configure Apache2 to serve static requests and application requests for ease of use. The Apache2 configurations that we decided to use are listed in the bartensor.conf file.
To deploy this Django project, our team decided to serve our project with Apache2. We decided to configure Apache2 to serve static requests and application requests for ease of use. The Apache2 configurations that we decided to use are listed in the bartensor.conf file.
2 changes: 1 addition & 1 deletion bartensor.dev.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<VirtualHost *:80>

ServerName web:8000
ServerName localhost:8000
DocumentRoot /usr/src/app

Alias /static/ /usr/src/app/static/
Expand Down
1 change: 1 addition & 0 deletions entrypoint.dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python manage.py collectstatic --noinput
chmod 664 /usr/src/app/db.sqlite3
chown www-data /usr/src/app/db.sqlite3
chown www-data /usr/src/app
chmod -R 777 /usr/src/app/media
apache2ctl -D FOREGROUND

exec "$@"
12 changes: 4 additions & 8 deletions env/.env.dev
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
DEBUG=1
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] web
SQL_ENGINE=django.db.backends.postgresql_psycopg2
SQL_DATABASE=bartensordb
SQL_USER=bartensoradmin
SQL_PASSWORD=BartensorOSU!
SQL_HOST=db
SQL_PORT=5432
DATABASE=postgres
SECRET_KEY=development
ALLOWED_HOSTS=localhost 127.0.0.1
SQL_ENGINE=django.db.backends.sqlite3
DATABASE=db.sqlite3
BARTENSOR_EMAIL_USERNAME=[email protected]
BARTENSOR_EMAIL_PASSWORD=iupeqdduwlekqjrj
WATSON_DISCOVERY_API_KEY=Q48Xgoo6dGAAOSNjdUdho8uwprTEbwgXOBUspsEaTDO2
Expand Down
9 changes: 9 additions & 0 deletions env/.env.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DEBUG=0
SECRET_KEY=production
ALLOWED_HOSTS=bartensor.biz 18.217.199.76 ec2-18-217-199-76.us-east-2.compute.amazonaws.com
SQL_ENGINE=django.db.backends.sqlite3
DATABASE=db.sqlite3
BARTENSOR_EMAIL_USERNAME=[email protected]
BARTENSOR_EMAIL_PASSWORD=iupeqdduwlekqjrj
WATSON_DISCOVERY_API_KEY=Q48Xgoo6dGAAOSNjdUdho8uwprTEbwgXOBUspsEaTDO2
WATSON_SPEECH_TO_TEXT_API_KEY=GUyb9Y0-25JUO7_fZtyLvlDipUAMzROb2vxadUiWJEMX
2 changes: 2 additions & 0 deletions gnt/migrations/0034_auto_20200315_1534.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class Migration(migrations.Migration):

atomic = False

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('gnt', '0033_auto_20200304_1840'),
Expand Down
2 changes: 1 addition & 1 deletion gnt/templates/gnt/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<header class="site-header">
<nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
<div class="container">
<a class="navbar-brand mr-4" href="{% url 'home' %}">CircleCi</a>
<a class="navbar-brand mr-4" href="{% url 'home' %}">Bartensor</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
Expand Down
46 changes: 21 additions & 25 deletions website/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@
# 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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'fhsu029mf+3w+r-e-oquk3!cv(t@rd1u5ocj=sd^vn#bj)s$@y'
SECRET_KEY = os.environ.get('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', True)
DEBUG = int(os.environ.get('DEBUG', 0))

ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'django', '18.217.199.76',
'ec2-18-217-199-76.us-east-2.compute.amazonaws.com', 'bartensor.biz']
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS').split(' ')

# Application definition

Expand Down Expand Up @@ -79,8 +77,8 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': os.environ.get('SQL_ENGINE', 'django.db.backends.sqlite3'),
'NAME': os.environ.get('DATABASE', os.path.join(BASE_DIR, 'db.sqlite3'))
}
}

Expand Down Expand Up @@ -122,14 +120,20 @@
'users'
]

JENKINS_TASKS = [
'django_jenkins.tasks.run_pep8',
'django_jenkins.tasks.run_pyflakes',
'django_jenkins.tasks.run_flake8'
]

CRISPY_TEMPLATE_PACK = 'bootstrap4'

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

EMAIL_HOST = 'smtp.gmail.com'

EMAIL_HOST_PASSWORD = os.environ.get('BARTENSOR_EMAIL_PASSWORD')

EMAIL_HOST_USER = os.environ.get('BARTENSOR_EMAIL_USERNAME')

EMAIL_PORT = 587

EMAIL_USE_TLS = True

LOGIN_REDIRECT_URL = 'home'

LOGIN_URL = 'login'
Expand All @@ -138,18 +142,10 @@

MEDIA_URL = '/media/'

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('BARTENSOR_EMAIL_USERNAME')
EMAIL_HOST_PASSWORD = os.environ.get('BARTENSOR_EMAIL_PASSWORD')
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

WATSON_DISCOVERY_API_KEY = os.environ.get('WATSON_DISCOVERY_API_KEY')
WATSON_SPEECH_TO_TEXT_API_KEY = os.environ.get('WATSON_SPEECH_TO_TEXT_API_KEY')
STATIC_URL = '/static/'

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
WATSON_DISCOVERY_API_KEY = os.environ.get('WATSON_DISCOVERY_API_KEY')

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
WATSON_SPEECH_TO_TEXT_API_KEY = os.environ.get('WATSON_SPEECH_TO_TEXT_API_KEY')

0 comments on commit c9382aa

Please sign in to comment.