Casual without compromise
Install tools and dependencies (via homebrew):
> /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
> brew tap homebrew/bundle
> brew bundleNext, create a local Postgres database:
- Open
postgres.app(just installed viabrew) - Open
postico.app - Create a database through
positico
Add environment variables:
# DJANGO APP KEYS
export DJ_ENV=dev
export DJ_DB_NAME=vodka-soda # database you just created
export DJ_DB_USER=tom # this is likely the user you use to login to your computer
export DJ_DB_PASSWORD=root
export DJ_DB_HOST=docker.for.mac.localhost # special docker set up
export DJ_DB_PORT=5432
export DJ_SECRET_KEY=+cg9iso$a55f3ay&)pdg3k&=lq_c*55j7oyuib=a(pi#2$oj^0
export DJ_SOCIAL_AUTH_FACEBOOK_KEY=234928371610299
export DJ_SOCIAL_AUTH_FACEBOOK_SECRET=3731939d837s7b1b0b772a64c7570edb
# FLASK APP KEYS
export FLASK_APP=app.py
# LETS ENCRYPT CERTIFICATE PATHS
export SSL_CERTIFICATE=/etc/nginx/certs/local/vodkasoda.crt
export SSL_CERTIFICATE_KEY=/etc/nginx/certs/local/vodkasoda.keyUpdate /etc/hosts by adding:
0.0.0.0 vodkasoda.local api.vodkasoda.local www.vodkasoda.localSnag the repo, start Docker, and build the containers:
> git clone https://github.com/tmm/vodka-soda-server.git
> cd vodka-soda-server
> docker-compose buildApply database migrations, create superuser, and generate static files (for admin console, etc.):
> docker-compose run api python manage.py makemigrations
> docker-compose run api python manage.py migrate
> docker-compose run api python manage.py collectstaticGenerate a local wildcard cert by running bash scripts/generate-wildcard-cert.sh and entering vodkasoda.local for root domain. Add the generated certs dir to nginx/certs. If everything worked as planned, you should be able to docker-compose up and access the admin app.
> docker-compose up -d
> docker-compose ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
13cf068eefeb vodkasodaserver_nginx "nginx -g 'daemon of…" 1 minute ago Up 1 minute 0.0.0.0:80->80/tcp nginx
18f7d8df9ef9 vodkasodaserver_web "uwsgi --ini uwsgi.i…" 1 minute ago Up 1 minute 5000/tcp web
f2bc789461bf vodkasodaserver_api "uwsgi --ini uwsgi.i…" 1 minute ago Up 1 minute 8000/tcp apiGo to the admin site to create a new Application for the API to connect to.
Whenever you make changes to a model, the database needs to be kept in sync.
> docker-compose run api python manage.py makemigrations
> docker-compose run api python manage.py migrateSee Django Migrations Worflow for more info.
-
Create RDS Postgres instance
-
Add production environment variables to
.env:
# DJANGO APP KEYS
export DJ_ENV=prod
export DJ_DB_NAME=something
export DJ_DB_USER=root
export DJ_DB_PASSWORD=zsRqfjJdDVAxhUewsqnTCxlslr
export DJ_DB_HOST=something.cxsbe1vrwmpg.us-east-1.rds.amazonaws.com
export DJ_DB_PORT=5432
export DJ_SECRET_KEY=+cg9iso$a55f3ay&)pdg3k&=lq_c*55j7oyuib=a(pi#2$oj^0
export DJ_SOCIAL_AUTH_FACEBOOK_KEY=234928371610299
export DJ_SOCIAL_AUTH_FACEBOOK_SECRET=3731939d837s7b1b0b772a64c7570edb
# FLASK APP KEYS
export FLASK_APP=app.py
# AWS IAM ACCESS KEYS
export AWS_ACCESS_KEY_ID=AKIATEMMAIEPJOZC74GP
export AWS_SECRET_ACCESS_KEY=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
# LETS ENCRYPT CERTIFICATE PATHS
export SSL_CERTIFICATE=/etc/nginx/certs/letsencrypt/name.crt
export SSL_CERTIFICATE_KEY=/etc/nginx/certs/letsencrypt/name.key-
Build, tag, and push Docker images to Amazon Elastic Container Registry
-
Update
imagepaths inaws-compose.yml(from now on you may usebash scripts/push-aws-ecr.shto build, tag, and push all images) -
Add RDS's
vpc(--vpc vpc_id) andsubnets(--subnets subnet_1,subnet_2) toscripts/setup-aws-ecs.sh -
Configure
ecs-cliwith cluster info by runningbash scripts/setup-aws-ecs.sh -
Run deploy script
bash scripts/deploy-aws-ecs.sh(update RDS's security group to accept inbound TCP connections from ECS's security group)
If all went as planned, you can navigate to the running site. (Also, need to open up ECS security group to listen for HTTPS.)
Docker & ECS:
General AWS:
- Migrating DNS Service for a Domain
- Configuring Amazon Route 53 to Route Traffic to an Amazon EC2 Instance
Django REST Framework & Social Auth:
- Django OAuth Toolkit with Django REST Framework Tutorial
- Django REST Framework Social Oauth2 Facebook Example
- dry-rest-permissions
- Facebook Developer Access Tokens
- Facebook App Dashboard
Other: