SlideServe
Menu
Préférences
© SlideServe · v2026

Django Deployment - Tips, Tricks and Best Practices

fawzi avatar
13 diapositives · 294 Views · Jul 10, 2014

The art of deploying Django applications with our comprehensive guide filled with tips, tricks, and best practices. Learn how to ensure your application runs consistently every time and everywhere. Discover the importance of reproducibility in infrastructure and applications, managing dependencies, and configurations effectively. Explore strategies for backup, security, performance, and more. With practical advice on using tools like virtualenv, pip, and packaging systems, you'll be equipped to deploy with confidence and ease.

Django Deployment - Tips, Tricks and Best Practices - slide 1
01 / 13Django Deployment - Tips, Tricks and Best Practices
1 / 17

Télécharger la présentation

Django Deployment - Tips, Tricks and Best Practices
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Django Deployment Tips, Tricks and Best Practices Erik LaBianca, WiserTogether, Inc.

  2. You mission, should you choose to accept it: • Make your application run with 1 click, everywhere it counts, every time. • Make your application run exactly the same way, everywhere it counts, every time. • Prove that the above are true. Reproducibility

  3. Reproducible Infrastructure • Reproducible Systems • Reproducible [Django] Applications • Dependencies • Configuration • Data • Deployment Steps to Reproducibility

  4. Systems: Virtual or Physical • Power Management • Console • Backup / Restore • Network Layer • Load Balancing • Security • Performance Infrastructure

  5. A Stable Foundation • Stable Operating System • Reproducible Installation • Kickstart Install • Base Image • Configuration Management • Puppet, Chef • Packaging Systems

  6. What Python? • Database? • Backup / Restore • Failover • Performance • Caching? • HTTP • Objects • Queuing? • SSL? Application Environment

  7. It’s just code, right? • Probably Not Application

  8. lib/pypi-cache: Django-1.4.3.tar.gz requirements.txt: Django==1.4.3 Type this: pip install --no-index --find-links file://$(PWD)/lib/pypi-cache -r requirements.txt • Just use pip! • Not so fast. • Lots of external dependencies • Eliminate them with a local cache • Don’t’ forget virtualenv! Dependencies

  9. settings.py: from urlparse import urljoin from os import environ import dj_database_url #courtesy of Heroku DATABASES = dj_database.config(default=“xxx”) BASE_URL = environ[‘DJANGO_BASE_URL’] STATIC_URL = urljoin(BASE_URL, ‘static’) MEDIA_URL = urljoin(BASE_URL, ‘media’) Run this: DJANGO_BASE_URL=http://cdn.com/base/django-admin.pyrunserver • settings.py • No logic allowed! • “unknown” import times • Critical • Local_settings.py • More of the same • Consider pushing configuration in externally via environ, configparser, etc Configuration

  10. fixtures/polls.py: from ..models import Poll, Choice def apply(): p = Poll.objects.get_or_create(q=‘test q’, defaults=dict(pub_date=‘1980-01-01)) c1 = Choices.objects.get_or_create(poll=p, choice_text=‘option 1’) fixtures/tests/test_poll.py: Class PollFixtureTestCase(TestCase): deftest_fixture_applied(): self.assertEquals(Poll.objects.get(q=‘test q’) • Fixtures. Consider writing them in Python! • Testable • More resilient to change • Less pkpain • Migrations! • Test them Database

  11. management/__init__.py: from django.db.models.signals import post_syncdb from south.signals import post_migrate from .. import models, fixtures defupdate_poll_fixtures(verbose=True): fixtures.poll.apply() if verbose: print "Updating dynamic fixtures for profile” defupdate_fixtures_post_syncdb(sender, **kwargs): update_poll_fixtures() defupdate_fixtures_post_migrate(app, **kwargs): if app == ’polls': update_poll_fixtures() post_syncdb.connect(fixtures_post_syncdb, sender=models) post_migrate.connect(fixtures_post_migrate)

  12. Interwebs • Back Up Everything! • Move files to Green • Fabric? • RPM? • Tar? • Git? • Rsync? • Update Stuff • syncdb • apply fixtures • Test Green! • Flip/Flop Blue/Green • (Roll back to Blue) App App Deploy / Test Data Deployment: Blue/Green

  13. Erik LaBianca, WiserTogether, Inc. erik.labianca@gmail.com @easel https://linkedin.com/in/eriklabianca/ https://slideshare.net/easel1/ https://github.com/easel/ https://github.com/WiserTogether/ Questions?