Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Django deployment with PaaS

This presentation was given at the Boston Django meetup on November 16, and surveyed several leading PaaS providers including Stackato, Dotcloud, OpenShift and Heroku.

For each PaaS provider, I documented the steps necessary to deploy Mezzanine, a popular Django-based CMS and blogging platform.

At the end of the presentation, I do a wrap-up of the different providers and provide a comparison matrix showing which providers have which features. This matrix is likely to go out-of-date quickly because these providers are adding new features all the time.

  • Be the first to comment

Django deployment with PaaS

  1. 1. Djangodeployment revisited Nate Aune, @natea Appsembler & Jazkarta November 15, 2012 Django Boston Users Group
  2. 2. A brief history of /me• Jazkarta (2004-Current) AWS) first taste of cloud platforms (GAE,• DjangoZoom -(2010-2011) it be!?” built my own PaaS “how hard can• Appsembler (2012-Current) SaaS apps leveraging PaaS, make it easy to launch
  3. 3. What’s on the menu• Where are you deploying Django apps today?• What is a PaaS?• Why you might want to use a PaaS?• What are the different PaaS players?• How do they compare?
  4. 4. Where are youdeploying Django today?• Shared hosting (i.e. Webfaction)• Running your own servers (co-located)?• Using an IaaS provider (i.e. AWS or Rackspace)• Already using a platform-as-a-service (PaaS)
  5. 5. What is a PaaS? Platform-as-a-service enables developers to createinnovative applications without operational overhead around configuration, deployment and management.
  6. 6. Layers of infrastructureSource: EngineYard “PaaS - State of the Market Survey” May 2012 - http://venturebeat.com/2012/07/05/engine-yard-paas-infographic/
  7. 7. Source: EngineYard “PaaS - State of the Market Survey” May 2012 - http://venturebeat.com/2012/07/05/engine-yard-paas-infographic/
  8. 8. Source: EngineYard “PaaS - State of the Market Survey” May 2012 - http://venturebeat.com/2012/07/05/engine-yard-paas-infographic/
  9. 9. Source: EngineYard “PaaS - State of the Market Survey” May 2012 - http://venturebeat.com/2012/07/05/engine-yard-paas-infographic/
  10. 10. Source: AppFog “Evolution of the Cloud: Toward a NoOps World” Jan 2012http://gigaom.com/cloud/why-2013-is-the-year-of-noops-for-programmers-infographic/
  11. 11. Efficient, Elastic, Secure• Lots of applications co-located on a few servers • Drastically reduces resources • Add/remove servers depending on load • All secured using SELinux or LXC
  12. 12. Let them do the boring stuff• Let the PaaS provider do the boring stuff • Patches and updates • Migrating applications • Backups / snapshots • Configuring everything (web servers, load balancers, modules, databases)
  13. 13. Who are the players?• CloudFoundry • Heroku (open source by VMWare) (now Salesforce) • OpenShift (Redhat’s open source PaaS)• AppFog • Dotcloud • App Engine (Google)• Stackato (ActiveState) • Gondor (Python only) • Elastic Beanstalk (Amazon) • Azure (Microsoft)
  14. 14. Who are the players? We’ll look at these ones tonight.• CloudFoundry • Heroku • OpenShift (open source by VMWare) (now Salesforce) (Redhat’s open source PaaS)• AppFog • Dotcloud • App Engine (Google)• Stackato • Gondor (ActiveState) • Elastic Beanstalk (Python only) (Amazon) • Azure (Microsoft)
  15. 15. Stackato by ActiveState Python 3, Run anywhere, New Relic integrationhttp://appsembler.com/blog/django-deployment-using-stackato/
  16. 16. Stackato
  17. 17. Secure using Linux Containers (LXC)
  18. 18. New Relic integration
  19. 19. Consistent deployment at all stages of the lifecycle
  20. 20. Stackato for Django1. Download the Stackato client http://www.activestate.com/stackato/download_client2. Create a wsgi.py file3. Create a requirements.txt file (if you don’t already have one)4. Edit the DATABASES and MEDIA_ROOT settings in settings.py file5. Create a stackato.yml file to persist the configuration (optional)
  21. 21. wsgi.py file
  22. 22. requirements.txtDjango==1.4.2psycopg2==2.4.5-e git+git@github.com:yourname/django-awesome.git#egg=django-awesome Or you can just reference another requirements file in your repo-r requirements/project.txt
  23. 23. Database overrides
  24. 24. MEDIA_ROOT
  25. 25. Target and login$ stackato target api.appsembler.net$ stackato login --email user@domain.comAttempting to login to [https://api.appsembler.net]Password: ********Successfully logged into [https://api.appsembler.net]
  26. 26. Initial push$ stackato pushWould you like to deploy from the current directory ? [Yn]:Would you like to use paasbakeoff as application name ? [Yn]:Detected a Python Application, is this correct ? [Yn]:Framework: pythonRuntime: <framework-specific default>Application Deployed URL [paasbakeoff.appsembler.net]:Application Url: paasbakeoff.appsembler.netEnter Memory Reservation [128M]:Creating Application [paasbakeoff]: OKCreate services to bind to paasbakeoff ? [yN]: y
  27. 27. Bind servicesWhat kind of service ?1. filesystem2. memcached3. mongodb4. mysql5. postgresql6. rabbitmq7. redisChoose: 5Specify the name of the service [postgresql-cf691]:Creating Service: OKBinding Service: OKCreate another ? [yN]:Would you like to save this configuration? [yN]: yUploading Application [paasbakeoff]: Checking for bad links: 29 OK Copying to temp space: 28 OK Checking for available resources: 44022 OK Packing application: OK Uploading (20K): 100% OKPush Status: OKStaging Application [paasbakeoff]:
  28. 28. Auto-generated stackato.yml filename: paasbakeoffinstances: 1framework: type: pythonmem: 128services: postgresql-cf691: postgresql Let’s add some other requirements to be installedrequirements: requirements: pypm: pypm: - pillow -OR- - pillow - psycopg2 pip: - psycopg2
  29. 29. Running syncdb manually$ stackato update -n$ stackato start$ stackato logs$ stackato run python mywebsite/manage.py syncdb --noinputCreating tables ......Creating table django_commentsCreating table django_comment_flagsCreating default account (username: admin / password: default) ...Creating default Site 127.0.0.1:8000 ...Creating initial content (About page, Blog, Contact form, Gallery) ...Installed 18 object(s) from 3 fixture(s)Installing custom SQL ...Installing indexes ...Installed 0 object(s) from 0 fixture(s)
  30. 30. Handling static assets$ stackato run python mywebsite/manage.py collectstatic --noinput...Copying /app/python/lib/python2.7/site-packages/django/contrib/admin/static/admin/css/rtl.cssCopying /app/python/lib/python2.7/site-packages/django/contrib/admin/static/admin/css/ie.cssCopying /app/python/lib/python2.7/site-packages/django/contrib/admin/static/admin/css/forms.css554 static files copied. Make sure they were copied to the right placeframework: type: python home-dir: appprocesses: web: $STACKATO_UWSGI --static-map /static=$HOME/mywebsite/static
  31. 31. Run management commands automaticallyhooks: post-staging: - python mywebsite/manage.py syncdb --noinput - python mywebsite/manage.py collectstatic --noinput - python mywebsite/manage.py migrate --noinput Make sure you add South to the requirementsrequirements: pypm: - pillow - psycopg2 - south
  32. 32. Persisted filesystem for file uploadsservices: postgresql-cf691: postgresql filesystem-paasbakeoff: filesystemRemember to set the MEDIA_ROOT in settings.py:MEDIA_ROOT = os.environ[STACKATO_FILESYSTEM]
  33. 33. stackato.yml file
  34. 34. Directory layout
  35. 35. OpenShift by Redhat Open source, Auto-scaling, Jenkins buildshttp://appsembler.com/blog/django-deployment-using-openshift/
  36. 36. Install the rhc client $ sudo gem install rhc $ rhc setup ... $ rhc domain status 7 tests, 12 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passedYou may need to add the SSH key and start the SSH agent $ ssh-add ~/.ssh/id_rsa $ ssh-agent
  37. 37. Quick ‘n dirty instructions$ rhc app create -a mezzanineopenshift -t python 2.6$ rhc cartridge add -c mysql-5.1 -a mezzanineopenshift$ cd mezzanineopenshift$ git remote add paasbakeoff git://github.com/appsembler/paasbakeoff.git$ git fetch paasbakeoff$ git merge paasbakeoff/openshift$ git push
  38. 38. Action hooks for running commands during build, deploy, post-deploy, etc./data/ dir to store uploaded media files Anatomy of an OpenShift repo .htaccess to serve up static files application inside of wsgi dir setup.py instead of requirements.txt
  39. 39. /wsgi/application
  40. 40. setup.py
  41. 41. STATIC_ROOT and MEDIA_ROOT
  42. 42. /wsgi/static/.htaccess
  43. 43. .openshift/action_hooks/deploy
  44. 44. .openshift/action_hooks/build
  45. 45. Create and bind the database $ rhc cartridge add -c mysql-5.1 -a mezz Password: ****** Adding mysql-5.1 to application mezz Success mysql-5.1 ========= Properties ========== Connection URL = mysql://127.12.26.129:3306/ Database Name = mezz Password = ********** Username = admin Similar for PostgreSQL $ rhc cartridge add -c postgresql-8.4 -a mezz
  46. 46. Git push to deploy$ git pushCounting objects: 5, done.Delta compression using up to 2 threads.Compressing objects: 100% (3/3), done.Writing objects: 100% (3/3), 498 bytes, done.Total 3 (delta 1), reused 0 (delta 0)remote: restart_on_add=falseremote: Waiting for stop to finishremote: Doneremote: restart_on_add=falseremote: ~/git/mezz.git ~/git/mezz.gitremote: ~/git/mezz.gitremote: Running .openshift/action_hooks/pre_buildremote: setup.py found. Setting up virtualenvremote: New python executable in /var/lib/openshift/x/python-2.6/virtenv/bin/pythonremote: Installing setuptools............done.remote: Installing pip...............done....remote: Running .openshift/action_hooks/deployremote: hot_deploy_added=falseremote: MySQL already runningremote: Doneremote: Running .openshift/action_hooks/post_deployTo ssh://0e94a6186e07430f8d9b989fdf702362@mezz-natea.rhcloud.com/~/git/mezz.git/ 03605bf..e05607c master -> master
  47. 47. More resources• Getting started with Django on OpenShift https://openshift.redhat.com/community/get-started/django• openshift-django-example https://bitbucket.org/mdoglio/openshift-django-sample• Rapid Python and Django app deployment https://openshift.redhat.com/community/blogs/rapid-python- and-django-app-deployment-to-the-cloud-with-a-paas
  48. 48. Dotcloudpolyglot from the start, very flexible, most Python centric
  49. 49. Install the Dotcloud client$ sudo pip install dotcloud$ dotcloud setupdotCloud username or email: natea@jazkarta.comPassword:==> dotCloud authentication is complete!You are recommended to run `dotcloud check` now.$ dotcloud check==> Checking the authentication status==> Client is authenticated as natea
  50. 50. Create and push an app$ dotcloud create mezz==> Creating a sandbox application named "mezz"==> Application "mezz" created.Connect the current directory to "mezz"? [Y/n]:==> Connecting with the application "mezz"==> Connected with default push options: --rsync$ dotcloud push==> Pushing code with rsync from "./" to application mezzbuilding file list ... done14:17:51: [www.0] Migrating stateful data located in ~/data14:18:05: [www.0] Launching...14:18:07: [www.0] Re-routing traffic to the new build...14:18:08: [www.0] Successfully installed build revision rsync instance #014:18:08: [www.0] Installation successful for service (www) instance #014:18:08: --> Application (mezz) fully installed==> Application is live at http://mezz-natea.dotcloud.com$ dotcloud open==> Opening service "www" in a browser: http://mezz-natea.dotcloud.com
  51. 51. Anatomy of a Django app on Dotcloudcustomized settings.py for Dotcloudcreatedb.py to create the databasedotcloud.yml to store config infomkadmin.py to make the admin usernginx.conf to config URL rewritingpostinstall to run syncdb, collectstaticwsgi.py to serve using uWSGI
  52. 52. dotcloud.yml
  53. 53. DATABASE in settings.py
  54. 54. STATIC_ROOT andMEDIA_ROOT in settings.py
  55. 55. nginx.conf
  56. 56. postinstall
  57. 57. createdb.py and mkadmin.py createdb.pyhttps://github.com/dotcloud/django-on-dotcloud/blob/master/createdb.py mkadmin.py
  58. 58. More resources• Dotcloud Python docs http://docs.dotcloud.com/0.9/services/python/• Dotcloud Django docs http://docs.dotcloud.com/0.9/tutorials/python/django/• django-on-dotcloud https://github.com/dotcloud/django-on-dotcloud/• python-on-dotcloud https://github.com/kencochrane/python-on-dotcloud
  59. 59. Heroku
  60. 60. Install the Heroku toolbeltDownload the Heroku Toolbelthttp://toolbelt.herokuapp.com/osx/download$ heroku loginEnter your Heroku credentials.Email: someone@example.comPassword: ******Could not find an existing public key.Would you like to generate one? [Yn]Generating new SSH public key.Uploading ssh public key /Users/someone/.ssh/id_rsa.pub
  61. 61. Create app and DB$ heroku create paasbakeoffCreating paasbakeoff... done, stack is cedarhttp://paasbakeoff.herokuapp.com/ | git@heroku.com:paasbakeoff.gitGit remote heroku added$ heroku addons:add heroku-postgresql:devAdding heroku-postgresql:dev on paasbakeoff... done, v3 (free)Attached as HEROKU_POSTGRESQL_GREEN_URLDatabase has been created and is availableUse `heroku addons:docs heroku-postgresql:dev` to view documentation.$ heroku pg:info=== HEROKU_POSTGRESQL_GREEN_URLPlan: DevStatus: availableConnections: 0PG Version: 9.1.6Created: 2012-11-15 20:59 UTCData Size: 5.9 MBTables: 0Rows: 0/10000 (In compliance)Fork/Follow: Unavailable
  62. 62. Set DB env variables$ heroku config=== paasbakeoff Config VarsHEROKU_POSTGRESQL_GREEN_URL: postgres://x:y@z.com:5432/d2b3c9ichbauv0$ heroku pg:promote HEROKU_POSTGRESQL_GREENPromoting HEROKU_POSTGRESQL_GREEN_URL to DATABASE_URL... done$ heroku config=== paasbakeoff Config VarsDATABASE_URL: postgres://x:y@z.com:5432/d2b3c9ichbauv0HEROKU_POSTGRESQL_GREEN_URL: postgres://x:y@z.com:5432/d2b3c9ichbauv0
  63. 63. Add to settings.pySet the RACK_ENV environment variable to production $ heroku config:set RACK_ENV=production
  64. 64. Use S3 for servingstatic and media files And Sendgrid for sending emails
  65. 65. Procfile
  66. 66. $ git push heroku masterCounting objects: 8, done.Delta compression using up to 2 threads. Deploy with git pushCompressing objects: 100% (6/6), done.Writing objects: 100% (6/6), 616 bytes, done.Total 6 (delta 3), reused 0 (delta 0)-----> Heroku receiving push-----> Python/Django app detected-----> Preparing Python interpreter (2.7.2)-----> Creating Virtualenv version 1.7.2 New python executable in .heroku/venv/bin/python2.7 ... Running virtualenv with interpreter /usr/local/bin/python2.7-----> Activating virtualenv-----> Installing dependencies using pip version 1.1 Downloading/unpacking Django==1.4.2 (from -r requirements.txt (line 1)) ... Cleaning up...-----> Collecting static files 0 static files copied.-----> Discovering process types Procfile declares types -> (none) Default types for Python/Django -> web-----> Compiled slug size: 9.4MB-----> Launching... done, v7 http://djangosample.herokuapp.com deployed to HerokuTo git@heroku.com:djangosample.git af73905..3046deb master -> master
  67. 67. More Heroku resources• Getting Started with Django on Heroku https://devcenter.heroku.com/articles/django• Heroku Hackers Guide ($10 eBook) http://theherokuhackersguide.com• Developers Guide to Running Django Applications on Heroku http://kencochrane.net/blog/2011/11/developers-guide-for-running-django-apps-on-heroku/
  68. 68. Stackato OpenShift Dotcloud HerokuPython 2.7, 3.2 2.6 (2.7) 2.6.5, 2.7.2, 2.7.2 stackato runtimes 3.1.2, 3.2.2PostgreSQL 9.1 8.4 9.0 9.1.6MySQL 5.5 5.1 5.1 (Yes, via RDS)Persisted FS Yes Yes Yes (Yes, via S3)Redis Yes, 2.4 No Yes, 2.4.11 (Yes, via addon)MongoDB Yes, 2.0 Yes, 2.2 Yes, 2.2.1 (Yes, via addon)Memcached Yes, 1.4 No Yes (Yes, via addon)RabbitMQ Yes, 2.4 No Yes, 2.8.5 (Yes, via addon)Solr No No Yes, 3.4.0 (Yes, via Websolr)Cron Yes Yes Yes YesExtensible Yes, apt-get install Yes, DIY cartridge Yes, custom service Yes, buildpacksWebSockets Yes Yes Yes Yes, via Pusher add-on
  69. 69. Other resources• Wrap-up from PaaS bake-off http://appsembler.com/blog/wrap-up-from-paas-bake-off/• Django deployment using PaaS http://appsembler.com/blog/django-deployment-using-paas/• django-deployer https://github.com/natea/django-deployer• paasbakeoff - code examples https://github.com/appsembler/paasbakeoff/

    Be the first to comment

    Login to see the comments

  • zhuangdeyouxiang

    May. 11, 2014
  • juanmruiz

    Jun. 2, 2014
  • franmer7

    Jun. 3, 2014
  • anirimot

    Jun. 4, 2014
  • smorghead

    Jul. 20, 2014
  • pavandevarakonda1

    Jul. 21, 2014
  • mmrelkholy

    Aug. 6, 2014
  • kaixofire

    Aug. 27, 2014
  • christophrholmes

    Nov. 7, 2014
  • IwansyahXhaa

    Nov. 28, 2014
  • ubigiannis

    Dec. 5, 2014
  • AaronHuang3

    Dec. 24, 2014
  • prathamesh

    Jan. 18, 2015
  • neelimac

    Mar. 8, 2015
  • lordk1

    Apr. 11, 2015
  • fasoulas

    Aug. 2, 2015
  • AKSHAYPRATAP0

    Aug. 4, 2015
  • helioit

    Mar. 28, 2016
  • DescartesChen

    Sep. 15, 2017
  • NajmulHoqueSharif

    Nov. 25, 2020

This presentation was given at the Boston Django meetup on November 16, and surveyed several leading PaaS providers including Stackato, Dotcloud, OpenShift and Heroku. For each PaaS provider, I documented the steps necessary to deploy Mezzanine, a popular Django-based CMS and blogging platform. At the end of the presentation, I do a wrap-up of the different providers and provide a comparison matrix showing which providers have which features. This matrix is likely to go out-of-date quickly because these providers are adding new features all the time.

Views

Total views

63,346

On Slideshare

0

From embeds

0

Number of embeds

56,043

Actions

Downloads

0

Shares

0

Comments

0

Likes

44

×