two scoops of django - deployment

19
Best Practices for Django 1.6 TWO SCOOPS OF DJANGO Ch.27 Deployment: Platforms as a Service Ch.28 Deploying Django Project Michelle Leu @flywindy 2015/07/14

Upload: flywindy

Post on 16-Aug-2015

140 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Two scoops of Django - Deployment

Best Practices for Django 1.6

TWO SCOOPS OF DJANGO

Ch.27 Deployment: Platforms as a Service Ch.28 Deploying Django Project

Michelle Leu @flywindy 2015/07/14

Page 2: Two scoops of Django - Deployment

ABOUT THIS BOOK

• Not really for new comer

• Author:

• Daniel Greenfeld & Audrey Roy

• Django Packages Website

• New version for Django 1.8

2

Page 3: Two scoops of Django - Deployment

DEPLOYMENT

3

Platform as a Service (PaaS)

Page 4: Two scoops of Django - Deployment

CLOUD SERVICE

4

Build Deploy Buy

Page 5: Two scoops of Django - Deployment

EVALUATION

5

Compliance SSL/HTTPS, PCI Level 1 SSL/HTTPS

Pricing (Free Limit)

Sleeps after 30 mins of inactivity Must sleep 6 hours in a 24 hour period

one app, no custom domain, one app, MySQL.

Uptime 99.99x% ?

Staffing 24×7×365 (free in business hour) forums, stackoverflow

Scaling From command line / dashboard By switch diff pricing plan

Documentation Step by step tutorial (1.7) Wiki, Django 1.3

Performance 512 RAM, sleep 6hrs / day (free) low bandwidth, CPU allowance (free)

Geography United States or Europe Amazon's us-east-1c

Company stability Founded in 2007, acquired by Salesforce.com in 2010 PythonAnywhere LLP (2012)

Page 6: Two scoops of Django - Deployment

LIVE DEMO ♥

6

Page 7: Two scoops of Django - Deployment

7

• Project Layout

• Create Heroku app

• Setup environment variables

• Git push

• Django migrate

Page 8: Two scoops of Django - Deployment

8

• Project Layout

• Open Bash console

• git clone, creating a virtualenv and pip install

• Setup environment variable

• Setup static files

• WSGI Settings

Page 9: Two scoops of Django - Deployment

SUMMARY

9

Limit of app 5 1

Database PostgresSQL sqlite3, MySQL

Custom domain ✓ ✗ (only username)

Sleeping Sleeping at least 6hrs / day No sleeping

Scheduled tasks Heroku Scheduler (Unlimited) 1 daily task

Logging heroku logs Online log files (access, error, server)

Deployment Command line, more configs Online IDE / Console

Page 10: Two scoops of Django - Deployment

DEPLOYMENT

10

Single-Server for Small Projects

Page 11: Two scoops of Django - Deployment

SINGLE-SERVER FOR SMALL PROJECTS

11

HTTP + WSGI App

server

ProcessManager

DB Server

1. Nginx + uWSGI 2. Nginx + Gunicorn 3. Apache + mod_wsgi

1. Supervisord 2. init scripts

1. PostgresSQL 2. MySQL

Page 12: Two scoops of Django - Deployment

DEPLOYMENT

12

Multi-Server for Medium to Large Projects

Page 13: Two scoops of Django - Deployment

MULTI-SERVER FOR MEDIUM TO LARGE PROJECTS

13

HTTP + WSGI App

server

ProcessManager

DB Server

CDN for static

files

CachingServer

1. Redis for caching & async message queue 2. Memcached 3. Varnish

Page 14: Two scoops of Django - Deployment

AUTOMATED, REPEATABLE DEPLOYMENTS

14

Page 15: Two scoops of Django - Deployment

Remote execution

CURRENT INFRASTRUCTURE AUTOMATION TOOLS

• Installing packages

• Running commands on remote servers.

• Starting services, and restarting them under certain conditions.

• logging and returning the response from the server.

15

Page 16: Two scoops of Django - Deployment

CURRENT INFRASTRUCTURE AUTOMATION TOOLS

16

Python

Ruby

Page 17: Two scoops of Django - Deployment

SUMMARY

17

• Single-Server for Small Projects -> PaaS

• Multi-Server for Medium to Large Projects.

• Horizontal vs. Vertical Scaling

• Scaling Horizontally and Sessions

Page 18: Two scoops of Django - Deployment

REFERENCE• http://twoscoopspress.org/products/two-scoops-of-django-1-6

• https://devcenter.heroku.com/

• https://www.pythonanywhere.com/wiki/

• http://djangogirlstaipei.gitbooks.io/django-girls-taipei-tutorial/content/django/deploy.html

• http://tutorial.djangogirls.org/en/deploy/index.html

18

Page 19: Two scoops of Django - Deployment

THANKS FOR YOUR LISTENING