Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Elastic Beanstalk Files
.elasticbeanstalk/*
.git
.gitignore
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ img.png
*.sqlite3
dump.rdb
*.dump
keys/*
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.7-buster

RUN mkdir -p /opt/app
RUN mkdir -p /opt/app/pip_cache
RUN mkdir -p /opt/app/hackx
COPY requirements.txt /opt/app/
RUN pip3 install -r /opt/app/requirements.txt --cache-dir /opt/app/pip_cache
COPY . /opt/app/hackx/
WORKDIR /opt/app/hackx/
RUN python3 manage.py collectstatic --no-input
# RUN chown -R www-data:www-data /opt/app

EXPOSE 5000
ENTRYPOINT ["/opt/app/hackx/prodrunserver.sh"]
3 changes: 1 addition & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
release: python3 manage.py migrate
web: bin/start-pgbouncer-stunnel daphne hoohacks.asgi:application --port $PORT --bind 0.0.0.0 -v2
worker: python manage.py runworker channels -v2
web: daphne -b :: -p 5000 hoohacks.asgi:application
34 changes: 34 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Steps to Deploy onto AWS

## Elastic Beanstalk

1. `eb create ENV_NAME`

2. Add Configuration Variables
[https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https-ssl.html](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https-ssl.html)

3. Create a new certificate through AWS ACM.

4. Follow instructions to add CNAME to verify domain.

5. Add port forwarding from 443 to 80 with the new certificate.

## Update version

`eb deploy --staged -v`

## Active Migration Guide of Databases

From Heroku-managed Database to AWS RDS, use the following steps to migrate.

1. `heroku maintenance:on`

2. `heroku pg:backups:capture`

3. `heroku pg:backups:download`

4. `pg_restore --verbose --clean --no-acl --no-owner -h HOST_URL -U USERNAME -d DATABASE_NAME DUMP_FILE`

5. Ensure AWS version is working.

6. Change `DATABASE_URL` in Heroku
24 changes: 20 additions & 4 deletions hoohacks/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

# SECURITY WARNING: don't run with debug turned on in production

ON_HEROKU = 'ON_HEROKU' in os.environ
ON_HEROKU = 'ON_HEROKU' in os.environ or 'ON_AWS' in os.environ

DEBUG = False if ON_HEROKU else True

Expand Down Expand Up @@ -104,6 +104,18 @@
}
}

if 'RDS_HOSTNAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}

Comment on lines +107 to +118
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed

# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

Expand Down Expand Up @@ -279,6 +291,12 @@

PROD_URL = os.environ.get('PROD_URL', 'http://localhost:8000/')

if not DEBUG:
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
import dj_database_url
DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)

try:
# Configure Django App for Heroku.
import django_heroku
Expand All @@ -295,10 +313,8 @@
dsn=os.environ['SENTRY_DSN'],
integrations=[DjangoIntegration()]
)
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
except ImportError:
found = False
pass

ALLOWED_HOSTS = [
PROD_URL,
Expand Down
3 changes: 3 additions & 0 deletions prodrunserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

daphne -b :: -p 5000 hoohacks.asgi:application
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ daphne==2.3.0
DateJS==0.5
Django==2.2.13
django-heroku
dj-database-url
dropbox==11.0.0
hyperlink==20.0.1
idna==2.10
Expand Down