Giter Club home page Giter Club logo

django-fabric-aws's Introduction

Django Fabric AWS

A Fabric script to manage a Django deployment on Amazon AWS

This fabfile along with the provided templates can spawn EC2 instances, install and configure a stateless Django stack on them (nginx + gunicorn with Amazon S3 for staticfiles).

Furthermore it can update your instances from a git repo stored on bitbucket [private repos are free on bitbucket so you can run private stuff on your server]

Author

Ashok Fernandez

Acknowledgements

This was based on Fabulous by Giovanni Collazo.

Installation

  • Download this repo and drag the fabfile folder into the root directory of your Django project.
  • cd into the folder and run pip install -r requirements.txt

Setting up Your Django Project

See an example here of how to setup your Django project using the following instructions.

  • Create a folder in the root directory of your Django project called requirements that has three pip requirements files in it:

    • common.txt for all your common python dependancies between the server and local (add Django to this)
    • dev.txt for your local python dependancies
    • prod.txt for your server python dependancies (add boto, django-storages and psycopg2 to this)
  • Create a folder where the settings.py of your Django project is located called settings that has four Python files in it

    • _init_.py
    • common.py for all your common Django settings
    • dev.py for your local Django settings
    • prod.py for your server Django settings
  • At the top of both dev.py and prod.py add the line from <django_project_name>.settings.common import *

  • Change the os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<django_project_name>.settings") in both wsgi.py and manage.py to os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<django_project_name>.settings.prod"). This means that the project with default to the production settings, however you can run it locally using python manage.py runserver --settings=<django_project_name>.settings.dev

  • Setup a set of SSH keys for the bitbucket account where your repo is hosted

  • Provision an S3 bucket for the staticfiles and add the following to settings/prod.py

      INSTALLED_APPS += ('storages',)
      AWS_STORAGE_BUCKET_NAME = "<s3_staticfiles_bucket_name>"
      STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
      S3_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
      STATIC_URL = S3_URL
    
  • Fill out the details in fabfile/project_conf.py

Commands

After all that work you can now run these commands which will execute across all your EC2 instances

  • fab spawn instance

    • Spawns a new EC2 instance (as definied in project_conf.py) and return's it's public dns. This takes around 8 minutes to complete.
  • fab update_packages

    • Updates the python packages on the server to match those found in requirements/common.txt and requirements/prod.txt
  • fab deploy

    • Pulls the latest commit from the master branch on the server, collects the static files, syncs the db and
      restarts the server
  • fab reload_gunicorn

    • Pushes the gunicorn startup script to the servers and restarts the gunicorn process, use this if you have made changes to templates/start_gunicorn.bash
  • fab reload_nginx

    • Pushes the nginx config files to the servers and restarts the nginx, use this if you have made changes to templates/nginx-app-proxy or templates/nginx.conf
  • fab reload_supervisor

    • Pushes the supervisor config files to the servers and restarts the supervisor, use this if you have made changes to templates/supervisord-init or templates/supervisord.conf
  • fab manage:command="management command"

    • Runs a python manage.py command on the server. To run this command we need to specify an argument, eg for syncdb type the command -> fab manage:command="syncdb --no-input"

django-fabric-aws's People

Contributors

ashokfernandez avatar gcollazo avatar jannkleen avatar jpadilla avatar mo-mughrabi avatar mykwillis avatar nicferrier avatar ojengwa avatar toffer avatar yuvadm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.