Two scoops of Django - Deployment
-
Upload
flywindy -
Category
Engineering
-
view
142 -
download
1
Transcript of Two scoops of Django - Deployment
![Page 1: Two scoops of Django - Deployment](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/1.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/2.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/3.jpg)
DEPLOYMENT
3
Platform as a Service (PaaS)
![Page 4: Two scoops of Django - Deployment](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/4.jpg)
CLOUD SERVICE
4
Build Deploy Buy
![Page 5: Two scoops of Django - Deployment](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/5.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/6.jpg)
LIVE DEMO ♥
6
![Page 7: Two scoops of Django - Deployment](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/7.jpg)
7
• Project Layout
• Create Heroku app
• Setup environment variables
• Git push
• Django migrate
![Page 8: Two scoops of Django - Deployment](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/8.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/9.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/10.jpg)
DEPLOYMENT
10
Single-Server for Small Projects
![Page 11: Two scoops of Django - Deployment](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/11.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/12.jpg)
DEPLOYMENT
12
Multi-Server for Medium to Large Projects
![Page 13: Two scoops of Django - Deployment](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/13.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/14.jpg)
AUTOMATED, REPEATABLE DEPLOYMENTS
14
![Page 15: Two scoops of Django - Deployment](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/15.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/16.jpg)
CURRENT INFRASTRUCTURE AUTOMATION TOOLS
16
Python
Ruby
![Page 17: Two scoops of Django - Deployment](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/17.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/18.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022042514/55d05509bb61ebb97b8b45fd/html5/thumbnails/19.jpg)
THANKS FOR YOUR LISTENING