Skip to content

Commit

Permalink
Settings Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Collins committed Oct 6, 2016
1 parent d30759b commit 2430102
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .ebextensions/10_packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packages:
yum:
git: []
postgresql94-devel: []
libjpeg-turbo-devel: []
46 changes: 46 additions & 0 deletions .ebextensions/20_elasticcache.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#This sample requires you to create a separate configuration file that defines the custom
# option settings for CacheCluster properties.

Resources:
MyCacheSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Lock cache down to webserver access only"
SecurityGroupIngress :
- IpProtocol : "tcp"
FromPort :
Fn::GetOptionSetting:
OptionName : "CachePort"
DefaultValue: "6379"
ToPort :
Fn::GetOptionSetting:
OptionName : "CachePort"
DefaultValue: "6379"
SourceSecurityGroupName:
Ref: "AWSEBSecurityGroup"
MyElastiCache:
Type: "AWS::ElastiCache::CacheCluster"
Properties:
CacheNodeType:
Fn::GetOptionSetting:
OptionName : "CacheNodeType"
DefaultValue : "cache.t1.micro"
NumCacheNodes:
Fn::GetOptionSetting:
OptionName : "NumCacheNodes"
DefaultValue : "1"
Engine:
Fn::GetOptionSetting:
OptionName : "Engine"
DefaultValue : "redis"
VpcSecurityGroupIds:
-
Fn::GetAtt:
- MyCacheSecurityGroup
- GroupId

Outputs:
ElastiCache:
Description : "ID of ElastiCache Cache Cluster with Redis Engine"
Value :
Ref : "MyElastiCache"
6 changes: 6 additions & 0 deletions .ebextensions/30_options.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
option_settings:
"aws:elasticbeanstalk:customoption":
CacheNodeType : cache.t1.micro
NumCacheNodes : 1
Engine : redis
CachePort : 6379
17 changes: 17 additions & 0 deletions .ebextensions/40_python.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python manage.py migrate"
leader_only: True
02_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "config.settings.production"
REDIS_ENDPOINT_ADDRESS: '`{ "Fn::GetAtt" : [ "MyElastiCache", "RedisEndpoint.Address"]}`'
REDIS_PORT: '`{ "Fn::GetAtt" : [ "MyElastiCache", "RedisEndpoint.Port"]}`'
"aws:elasticbeanstalk:container:python":
WSGIPath: "../config/wsgi.py"
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ sensor_portal/media/

staticfiles/


# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
8 changes: 8 additions & 0 deletions compose/nginx/dhparams.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-----BEGIN DH PARAMETERS-----
MIIBCAKCAQEAyxepj6FexDqBTjoa41Jt+1RzBMOqpsCSu0RT8k5taJ5OU2gwqRoo
v9euM+T1zWqCoFkehucnGtJ7tc+GaFHHDkBnI9xbJ8+f+OE9CNVa2UaCa4DfOadD
wXWNB1jqlQJcKr+txqyDjRvzmwL4J6nQQ//KcuLQLxFWxkTBOpxrWVU0p0OwkRin
vP7zr5pxhDW22BF95o634Ol7X9IppukKeaYwXfAwd6ysxhLWQKFIQPadf0Ga2UfZ
K1UVGac9yUPUZzZeswd3eIIVlp4wFibnUwf/dUqZXtl5heZk/6jXNjW9Y4b5XKis
tuNP0vEit/nqNOFhlIHuWL/teH71pXLJWwIBAg==
-----END DH PARAMETERS-----
19 changes: 15 additions & 4 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,26 @@

# DATABASE CONFIGURATION
# ------------------------------------------------------------------------------
# Uses Amazon RDS for database hosting, which doesn't follow the Heroku-style spec
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': env('RDS_DB_NAME'),
'USER': env('RDS_USERNAME'),
'PASSWORD': env('RDS_PASSWORD'),
'HOST': env('RDS_HOSTNAME'),
'PORT': env('RDS_PORT'),
}
}

# Use the Heroku-style specification
# Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
DATABASES['default'] = env.db('DATABASE_URL')

# CACHING
# ------------------------------------------------------------------------------
REDIS_LOCATION = "redis://{}:{}/0".format(
env('REDIS_ENDPOINT_ADDRESS'),
env('REDIS_PORT')
)

REDIS_LOCATION = '{0}/{1}'.format(env('REDIS_URL', default='redis://127.0.0.1:6379'), 0)
# Heroku URL does not pass the DB number, so we parse it in
CACHES = {
'default': {
Expand Down
37 changes: 37 additions & 0 deletions ebsetenv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Converts a .env file to Elastic Beanstalk environment variables"""

import os
from sys import exit
from subprocess import check_call

try:
import dotenv
except ImportError:
print("Please install the 'dotenv' library: 'pip install dotenv'")
exit()

def main():
if not os.path.exists('.env'):
print('ERROR!! .env file is missing!')
print("Please copy 'env.example' to '.env' and add appropriate values")
exit()
command = ['eb', 'setenv']
failures = []
for key, value in dotenv.Dotenv('.env').items():
if key.startswith('POSTGRES'):
print('Skipping POSTGRES values - Amazon RDS provides these')
continue
if value:
command.append("{}={}".format(key, value))
else:
failures.append(key)
if failures:
for failure in failures:
print("{} requires a value".format(failure))
else:
print(' '.join(command))
check_call(command)


if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file is here because many Platforms as a Service look for
# requirements.txt in the root directory of a project.
-r requirements/production.txt

0 comments on commit 2430102

Please sign in to comment.