Upgrade to Pro — share decks privately, control downloads, hide ads and more …

deploying_django.pdf

Avatar for Bob Wei Bob Wei
April 22, 2014
23

 deploying_django.pdf

Avatar for Bob Wei

Bob Wei

April 22, 2014

Transcript

  1. 今⽇日主題 • 系統架構 • 執⾏行 Django Web 應⽤用程式 • 部署⼯工具

    ( Fabric ) • 靜態檔案部署 ( Collectstatic ) • A Real World Example
  2. Django Django Django Celery Celery Static Media 背景⼯工作伺服器 SQL db

    關聯式資料庫伺服器 Redis 資料庫伺服器 靜態檔案伺服器 應⽤用程式伺服器 Cache 快取伺服器
  3. 執⾏行 Django Web 應⽤用程式 • Development • ./manage.py runserver •

    可處理的 request 次數較少 • Production • gunicorn project.wsgi -b 0.0.0.0:$PORT -w 3
  4. Gunicorn • Gunicorn (‘Green Unicorn’) is a pure-Python WSGI server

    for UNIX. It has no dependencies and is easy to install and use • 安裝 : pip install gunicorn
  5. Deploy to Heroku • 前置作業 • 定義 Procfile => 設定如何執⾏行你的

    Web App • 定義 requirements.txt => 設定所需要的 Dependency • 定義 Database 的位置,並以環境變數 DATABASE_URL 的形式告知 Web App • 定義 STATICFILES_STORAGE
  6. Deploy to Heroku • 部署應⽤用程式⾄至 Heroku • git push heroku

    master • 部署靜態檔案⾄至靜態檔案伺服器 • ./manage.py collectstatic —noinput