├── django_deployer ├── __init__.py ├── paas_templates │ ├── __init__.py │ ├── appengine │ │ ├── __init__.py │ │ ├── requirements.txt │ │ ├── requirements_deploy.txt │ │ ├── README.rst │ │ ├── urls_appengine.py │ │ ├── app.yaml │ │ ├── manage.sh │ │ └── settings_appengine.py │ ├── dotcloud │ │ ├── __init__.py │ │ ├── requirements.txt │ │ ├── nginx.conf │ │ ├── postinstall │ │ ├── mkadmin.py │ │ ├── wsgi.py │ │ ├── dotcloud.yml │ │ ├── README.rst │ │ ├── settings_dotcloud.py │ │ └── createdb.py │ ├── gondor │ │ ├── __init__.py │ │ ├── settings_gondor.py │ │ ├── README.rst │ │ └── gondor.yml │ ├── stackato │ │ ├── __init__.py │ │ ├── requirements.txt │ │ ├── README.rst │ │ ├── settings_stackato.py │ │ └── stackato.yml │ └── wsgi.py ├── fabfile.py ├── main.py ├── utils.py ├── helpers.py ├── tasks.py └── providers.py ├── MANIFEST.in ├── .gitignore ├── docs ├── index.rst ├── git_template.rst ├── make.bat ├── Makefile └── conf.py ├── LICENSE.txt ├── CHANGES.rst ├── setup.py └── README.rst /django_deployer/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/appengine/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/dotcloud/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/gondor/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/stackato/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_deployer/fabfile.py: -------------------------------------------------------------------------------- 1 | from django_deployer.tasks import * 2 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/appengine/requirements.txt: -------------------------------------------------------------------------------- 1 | -r {{ requirements }} -------------------------------------------------------------------------------- /django_deployer/paas_templates/dotcloud/requirements.txt: -------------------------------------------------------------------------------- 1 | -r {{ requirements }} -------------------------------------------------------------------------------- /django_deployer/paas_templates/stackato/requirements.txt: -------------------------------------------------------------------------------- 1 | -r {{ requirements }} -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst LICENSE.txt CHANGES.rst 2 | recursive-include django_deployer/paas_templates * -------------------------------------------------------------------------------- /django_deployer/paas_templates/appengine/requirements_deploy.txt: -------------------------------------------------------------------------------- 1 | django_rocket_engine 2 | django-google-storage 3 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/appengine/README.rst: -------------------------------------------------------------------------------- 1 | TODO: write a README that describes a typical GAE project layout. See the other providers README files for examples. -------------------------------------------------------------------------------- /django_deployer/paas_templates/dotcloud/nginx.conf: -------------------------------------------------------------------------------- 1 | location {{ media_url }} { root /home/dotcloud/data ; } 2 | location {{ static_url }} { root /home/dotcloud/volatile ; } -------------------------------------------------------------------------------- /django_deployer/paas_templates/appengine/urls_appengine.py: -------------------------------------------------------------------------------- 1 | from urls import * 2 | 3 | urlpatterns += patterns( 4 | url(r'^media/(?P.*)/$','rocket_engine.views.file_serve'), 5 | ) 6 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/dotcloud/postinstall: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | python createdb.py 3 | python {{ managepy }} syncdb --noinput 4 | python mkadmin.py 5 | mkdir -p /home/dotcloud/data/media /home/dotcloud/volatile/static 6 | python {{ managepy }} collectstatic --noinput -------------------------------------------------------------------------------- /django_deployer/paas_templates/dotcloud/mkadmin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from wsgi import * 3 | from django.contrib.auth.models import User 4 | u, created = User.objects.get_or_create(username='admin') 5 | if created: 6 | u.set_password('{{ admin_password }}') 7 | u.is_superuser = True 8 | u.is_staff = True 9 | u.save() -------------------------------------------------------------------------------- /django_deployer/paas_templates/wsgi.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),'{{ project_name }}'))) 4 | os.environ['DJANGO_SETTINGS_MODULE'] = '{{ django_settings }}_{{ provider }}' 5 | import django.core.handlers.wsgi 6 | application = django.core.handlers.wsgi.WSGIHandler() -------------------------------------------------------------------------------- /django_deployer/paas_templates/dotcloud/wsgi.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),'{{ project_name }}'))) 5 | os.environ['DJANGO_SETTINGS_MODULE'] = '{{ django_settings }}_{{ provider }}' 6 | 7 | import django.core.handlers.wsgi 8 | application = django.core.handlers.wsgi.WSGIHandler() -------------------------------------------------------------------------------- /django_deployer/paas_templates/stackato/README.rst: -------------------------------------------------------------------------------- 1 | Sample apps 2 | =========== 3 | 4 | Here are some sample Django apps that are already configured to deploy to Stackato: 5 | 6 | https://github.com/Stackato-Apps/django-gtd/ 7 | https://github.com/Stackato-Apps/django-bookbuzz/ 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[co] 2 | 3 | # Packages 4 | *.egg 5 | *.egg-info 6 | dist 7 | build 8 | eggs 9 | parts 10 | bin 11 | var 12 | sdist 13 | develop-eggs 14 | .installed.cfg 15 | 16 | # Installer logs 17 | pip-log.txt 18 | 19 | # Unit test / coverage reports 20 | .coverage 21 | .tox 22 | 23 | #Translations 24 | *.mo 25 | 26 | #Mr Developer 27 | .mr.developer.cfg 28 | 29 | # Sphinx build 30 | docs/_build/ 31 | /.project 32 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/dotcloud/dotcloud.yml: -------------------------------------------------------------------------------- 1 | www: 2 | type: python 3 | config: 4 | python_version: {{ pyversion }} 5 | environment: 6 | DJANGO_SETTINGS_MODULE: {{ django_settings }}_{{ provider }} 7 | LANG: en_US.UTF-8 8 | LC_ALL: en_US.UTF-8 9 | db: 10 | {%- if database == 'PostgreSQL' %} 11 | type: postgresql 12 | {%- endif %} 13 | {%- if database == 'MySQL' %} 14 | type: mysql 15 | {%- endif %} 16 | # cache: 17 | # type: redis 18 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. django-deployer documentation master file, created by 2 | sphinx-quickstart on Mon Mar 18 10:06:23 2013. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to django-deployer's documentation! 7 | =========================================== 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | 15 | 16 | Indices and tables 17 | ================== 18 | 19 | * :ref:`genindex` 20 | * :ref:`modindex` 21 | * :ref:`search` 22 | 23 | -------------------------------------------------------------------------------- /django_deployer/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import shutil 5 | 6 | 7 | 8 | PACKAGE_ROOT = os.path.dirname(__file__) 9 | 10 | 11 | def add_fabfile(): 12 | """ 13 | Copy the base fabfile.py to the current working directory. 14 | """ 15 | fabfile_src = os.path.join(PACKAGE_ROOT, 'fabfile.py') 16 | fabfile_dest = os.path.join(os.getcwd(), 'fabfile_deployer.py') 17 | 18 | if os.path.exists(fabfile_dest): 19 | print "`fabfile.py` exists in the current directory. " \ 20 | "Please remove or rename it and try again." 21 | return 22 | 23 | shutil.copyfile(fabfile_src, fabfile_dest) 24 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/appengine/app.yaml: -------------------------------------------------------------------------------- 1 | application: {{ application_id }} 2 | version: 1 3 | runtime: python27 4 | api_version: 1 5 | threadsafe: true 6 | 7 | libraries: 8 | - name: django 9 | version: "latest" 10 | - name: PIL 11 | version: "latest" 12 | 13 | builtins: 14 | - django_wsgi: on 15 | 16 | env_variables: 17 | DJANGO_SETTINGS_MODULE: '{{ project_name }}.settings_appengine' 18 | 19 | skip_files: 20 | - ^(.*/)?app\.yaml 21 | - ^(.*/)?app\.yml 22 | - ^(.*/)?index\.yaml 23 | - ^(.*/)?index\.yml 24 | - ^(.*/)?#.*# 25 | - ^(.*/)?.*~ 26 | - ^(.*/)?.*\.py[co] 27 | - ^(.*/)?.*/RCS/.* 28 | - ^(.*/)?\..* 29 | - ^env/.*$ 30 | 31 | handlers: 32 | - url: /static/ 33 | static_dir: {{ project_name }}/static 34 | -------------------------------------------------------------------------------- /docs/git_template.rst: -------------------------------------------------------------------------------- 1 | Git Template Repository 2 | ======================= 3 | 4 | Now django-deployer supports templating by fetching from remote git repository, to create a new provider class, you could implement a new class which inherits to ``django_deployer.providers.PaaSProvider``. 5 | 6 | The only two attributes that does matter is ``git_template`` and ``git_template_url``, you should define the provider class as following: 7 | 8 | 9 | .. code:: python 10 | 11 | 12 | class YourProvider(PaaSProvider): 13 | name = 'yourprovider' 14 | 15 | PYVERSIONS = { 16 | "Python2.7": "v2.7" 17 | } 18 | 19 | setup_instruction = """ 20 | the instruction which will show up after setup 21 | """ 22 | 23 | git_template = True 24 | git_template_url = "" 25 | 26 | 27 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/stackato/settings_stackato.py: -------------------------------------------------------------------------------- 1 | import os 2 | import dj_database_url 3 | 4 | from .settings import * 5 | 6 | DEBUG = True 7 | TEMPLATE_DEBUG = DEBUG 8 | 9 | DATABASES = { 10 | "default": dj_database_url.config(env["DATABASE_URL"]), 11 | } 12 | 13 | MEDIA_ROOT = os.environ['STACKATO_FILESYSTEM'] 14 | 15 | LOGGING = { 16 | "version": 1, 17 | "disable_existing_loggers": False, 18 | "formatters": { 19 | "simple": { 20 | "format": "%(levelname)s %(message)s" 21 | }, 22 | }, 23 | "handlers": { 24 | "console": { 25 | "level": "DEBUG", 26 | "class": "logging.StreamHandler", 27 | "formatter": "simple" 28 | } 29 | }, 30 | "loggers": { 31 | "": { 32 | "handlers": ["console"], 33 | "level": "INFO", 34 | }, 35 | "django.request": { 36 | "propagate": True, 37 | }, 38 | } 39 | } -------------------------------------------------------------------------------- /django_deployer/paas_templates/stackato/stackato.yml: -------------------------------------------------------------------------------- 1 | name: {{ project_name }} 2 | framework: 3 | type: python 4 | runtime: {{ pyversion }} 5 | home-dir: app 6 | env: 7 | DJANGO_SETTINGS_MODULE: {{ django_settings }}_stackato 8 | #requirements: 9 | # pypm: 10 | # - psycopg2 11 | # - django 12 | # - south 13 | # pip: 14 | # - python-memcached 15 | processes: 16 | web: $STACKATO_UWSGI --static-map {{ static_url }}=$HOME/static 17 | services: 18 | {%- if database == 'PostgreSQL' %} 19 | postgresql-{{ project_name }}: postgresql 20 | {%- endif %} 21 | {%- if database == 'MySQL' %} 22 | mysql-{{ project_name }}: mysql 23 | {%- endif %} 24 | filesystem-{{ project_name }}: filesystem 25 | # ${name}-cache: memcached 26 | hooks: 27 | post-staging: 28 | - python manage.py syncdb --noinput 29 | - python manage.py migrate 30 | - echo "Run 'stackato run python manage.py createsuperuser' to create an admin user" 31 | ignores: 32 | - .git 33 | - dev.db -------------------------------------------------------------------------------- /django_deployer/paas_templates/gondor/settings_gondor.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import dj_database_url 4 | 5 | from .settings import * 6 | 7 | DEBUG = True 8 | TEMPLATE_DEBUG = DEBUG 9 | 10 | DATABASES = { 11 | "default": dj_database_url.config(env="GONDOR_DATABASE_URL"), 12 | } 13 | 14 | MEDIA_ROOT = os.path.join(os.environ["GONDOR_DATA_DIR"], "site_media", "media") 15 | 16 | LOGGING = { 17 | "version": 1, 18 | "disable_existing_loggers": False, 19 | "formatters": { 20 | "simple": { 21 | "format": "%(levelname)s %(message)s" 22 | }, 23 | }, 24 | "handlers": { 25 | "console": { 26 | "level": "DEBUG", 27 | "class": "logging.StreamHandler", 28 | "formatter": "simple" 29 | } 30 | }, 31 | "loggers": { 32 | "": { 33 | "handlers": ["console"], 34 | "level": "INFO", 35 | }, 36 | "django.request": { 37 | "propagate": True, 38 | }, 39 | } 40 | } -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Nate Aune 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/gondor/README.rst: -------------------------------------------------------------------------------- 1 | Tutorial 2 | ======== 3 | 4 | This is a tutorial for how to deploy a Django app with Gondor: 5 | https://gondor.io/support/django/setup/ 6 | 7 | Sample apps 8 | =========== 9 | 10 | Sample Django project ready to deploy to Gondor: 11 | https://github.com/eldarion/gondor-project-django 12 | 13 | Project layout 14 | ============== 15 | 16 | Here is a sample directory structure for a Django project: 17 | 18 | gondor-project-django/ 19 | .git or .hg (version control metadata) 20 | fixtures/ 21 | initial_data.json (where any data that should be loaded into the database on each deploy) 22 | **gondor.yml** (Gondor configuration file) 23 | manage.py 24 | project_name/ (project's Python package) 25 | __init__.py 26 | settings.py 27 | **settings_gondor.py** (Django settings for use on Gondor) 28 | static/ (see README in directory) 29 | templates/ (where templates for your project goes) 30 | urls.py 31 | **wsgi.py** (WSGI entry point for Django) 32 | requirements.txt (pip file to declare dependencies) -------------------------------------------------------------------------------- /django_deployer/paas_templates/dotcloud/README.rst: -------------------------------------------------------------------------------- 1 | Sample apps 2 | =========== 3 | 4 | See an example of a Django project ready to deploy to Dotcloud: 5 | https://github.com/dotcloud/django-on-dotcloud 6 | 7 | Tutorial 8 | ======== 9 | 10 | Tutorial for deploying a Django app to Dotcloud: 11 | http://docs.dotcloud.com/0.4/tutorials/python/django/ 12 | 13 | Handing static assetts 14 | ====================== 15 | 16 | http://docs.dotcloud.com/0.4/tutorials/python/django/#handle-static-and-media-assets 17 | 18 | Project layout 19 | ============== 20 | 21 | The dotCloud directory structure will look like :: 22 | 23 | . 24 | ├── **dotcloud.yml** 25 | ├── hellodjango/ 26 | │ ├── __init__.py 27 | │ ├── manage.py 28 | │ ├── settings.py 29 | | |── **settings_dotcloud.py** 30 | │ ├── helloapp/ 31 | │ │ ├── __init__.py 32 | │ │ ├── models.py 33 | │ │ ├── tests.py 34 | │ │ └── views.py 35 | │ ├── someotherapp/ 36 | │ │ ├── __init__.py 37 | │ │ ├── models.py 38 | │ │ ├── tests.py 39 | │ │ └── views.py 40 | │ └── urls.py 41 | ├── static/ 42 | ├── mkadmin.py 43 | ├── nginx.conf 44 | ├── **postinstall** 45 | ├── requirements.txt 46 | └── **wsgi.py** 47 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/appengine/manage.sh: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="{{ project_name }}" 2 | CLOUDSQL_DATABASENAME="{{ databasename }}" 3 | CLOUDSQL_INSTANCENAME="{{ instancename }}" 4 | APPENGINE_SDK_LOCATION={{ sdk_location }} 5 | MANAGE_SCRIPT_LOCATION="{{ managepy }}" 6 | APPLICATION_ID="{{ application_id }}" 7 | PATH="$APPENGINE_SDK_LOCATION:$PATH" 8 | 9 | export PYTHONPATH="env/lib/python2.7:$APPENGINE_SDK_LOCATION:$APPENGINE_SDK_LOCATION/lib/django-1.4" 10 | export DJANGO_SETTINGS_MODULE="$PROJECT_NAME.settings_appengine" 11 | export APPLICATION_ID 12 | 13 | args=$@ 14 | 15 | manage_script () { 16 | env/bin/python $MANAGE_SCRIPT_LOCATION $@ --settings=$DJANGO_SETTINGS_MODULE 17 | } 18 | 19 | 20 | case "$1" in 21 | cloudcreatedb) 22 | echo "create database $CLOUDSQL_DATABASENAME;" | $APPENGINE_SDK_LOCATION/google_sql.py $CLOUDSQL_INSTANCENAME 23 | ;; 24 | cloudsyncdb) 25 | export SETTINGS_MODE=prod && manage_script syncdb 26 | ;; 27 | clouddbshell) 28 | export SETTINGS_MODE=prod && manage_script dbshell 29 | ;; 30 | deploy) 31 | # packaging site-packages 32 | cp -r env/lib/python2.7/site-packages ./ 33 | cd site-packages 34 | rm -rf *.so django PIL 35 | cd - 36 | # deploy 37 | appcfg.py update --oauth2 . 38 | rm -rf site-packages 39 | ;; 40 | *) 41 | manage_script $args 42 | esac 43 | -------------------------------------------------------------------------------- /CHANGES.rst: -------------------------------------------------------------------------------- 1 | Changelog 2 | --------- 3 | 4 | 0.1.6 (2013-04-10) 5 | ++++++++++++++++++ 6 | 7 | - Use a createdb.py that handles timeouts better 8 | - Remove dj-database-url since it doesn't work with Dotcloud 9 | - Prompt for location of manage.py (for discrepancy in project layouts in Django 1.3 vs 1.4) 10 | - dotcloud.yml file needs DJANGO_SETTINGS_MODULE or else manage.py won't work 11 | - dotcloud.yml file needs UTF-8 or else browsing Mezzanine gallery won't work 12 | - Let user choose their admin password instead of hardcoding it 13 | - Make sure STATIC_ROOT and MEDIA_ROOT are defined in settings_dotcloud.py 14 | - If project already has a top level requirements.txt, don't do anything 15 | - Add validators for ensuring that requirements file exists, 16 | - Validate the admin password and that the user chose a valid provider 17 | - Ensure that the user doesn't leave fields blank 18 | 19 | 0.1.5 (2013-04-08) 20 | ++++++++++++++++++ 21 | 22 | - Need a MANIFEST.in in order to find the .txt and .rst files (@natea) 23 | - Fixed bug with misnamed CHANGES.txt -> CHANGES.rst (@natea) 24 | - Fixed bug with missing README.rst (@natea) 25 | 26 | 0.1.1 (2013-03-26) 27 | ++++++++++++++++++ 28 | 29 | - Added support for Google App Engine (@natea, @littleq0903) 30 | 31 | 0.1.0 (2012-09-07) 32 | ++++++++++++++++++ 33 | 34 | - Initial version for Stackato and Dotcloud (@natea, @johnthedebs) -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | from setuptools import setup, find_packages 5 | 6 | 7 | setup( 8 | name="django-deployer", 9 | version="0.1.6", 10 | description="Django deployment tool for popular PaaS providers", 11 | long_description=open('README.rst').read() + '\n\n' + open('CHANGES.rst').read(), 12 | keywords="PaaS Django Dotcloud Stackato Heroku Gondor AWS OpenShift GAE appengine fabric deployment", 13 | author="Nate Aune", 14 | author_email="nate@appsembler.com", 15 | url="http://natea.github.io/django-deployer", 16 | license="MIT", 17 | packages=find_packages(), 18 | include_package_data = True, 19 | install_requires=[ 20 | 'fabric==1.6.0', # formerly 1.4.3 21 | 'jinja2==2.6', 22 | 'heroku==0.1.2', 23 | 'dotcloud==0.9.4', 24 | 'gondor==1.2.2', 25 | 'pyyaml==3.10', 26 | 'sphinx==1.1.3', 27 | 'requests==0.14.2', 28 | 'GitPython', 29 | ], 30 | classifiers=( 31 | "Development Status :: 3 - Alpha", 32 | "Environment :: Web Environment", 33 | "Framework :: Django", 34 | "Intended Audience :: Developers", 35 | "License :: OSI Approved :: MIT License", 36 | "Programming Language :: Python", 37 | "Programming Language :: Python :: 2.7", 38 | ), 39 | entry_points={ 40 | 'console_scripts': [ 41 | 'deployer-init = django_deployer.main:add_fabfile', 42 | ] 43 | }, 44 | ) 45 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/gondor/gondor.yml: -------------------------------------------------------------------------------- 1 | # The key associated to your site. 2 | key: 3 | 4 | # Version control system used locally for your project. 5 | vcs: 6 | 7 | # Framework to use on Gondor. 8 | framework: wsgi 9 | 10 | # This path is relative to your project root (the directory gondor.yml lives in.) 11 | requirements_file: {{ requirements }} 12 | 13 | # Commands to be executed during deployment. These can handle migrations or 14 | # moving static files into place. Accepts same parameters as gondor run. 15 | on_deploy: 16 | - manage.py syncdb --noinput 17 | - manage.py collectstatic --noinput 18 | 19 | # URLs which should be served by Gondor mapping to a filesystem location 20 | # relative to your writable storage area. 21 | static_urls: 22 | - /site_media: 23 | root: site_media/ 24 | 25 | wsgi: 26 | # The WSGI entry point of your application in two parts separated by a 27 | # colon. Example: 28 | # 29 | # wsgi:application 30 | # 31 | # wsgi = the Python module which should be importable 32 | # application = the callable in the Python module 33 | entry_point: {{ project_name }}.wsgi:application 34 | 35 | # Options for gunicorn which runs your WSGI project. 36 | gunicorn: 37 | # The worker class used to run gunicorn (possible values include: 38 | # sync, eventlet and gevent) 39 | worker_class: sync 40 | 41 | # Adds extra environment variables to the instance environment. 42 | env: 43 | DJANGO_SETTINGS_MODULE: {{ project_name }}.settings_gondor -------------------------------------------------------------------------------- /django_deployer/paas_templates/dotcloud/settings_dotcloud.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | with open('/home/dotcloud/environment.json') as f: 4 | env = json.load(f) 5 | 6 | from .settings import * 7 | 8 | STATIC_ROOT = '/home/dotcloud/volatile/static/' 9 | STATIC_URL = '{{ static_url }}' 10 | 11 | MEDIA_ROOT = '/home/dotcloud/data/media/' 12 | MEDIA_URL = '{{ media_url }}' 13 | 14 | if 'DOTCLOUD_DATA_MYSQL_HOST' in env: 15 | DATABASES = { 16 | 'default': { 17 | 'ENGINE': 'django.db.backends.mysql', 18 | 'NAME': env['DOTCLOUD_PROJECT'], 19 | 'USER': env['DOTCLOUD_DATA_MYSQL_LOGIN'], 20 | 'PASSWORD': env['DOTCLOUD_DATA_MYSQL_PASSWORD'], 21 | 'HOST': env['DOTCLOUD_DATA_MYSQL_HOST'], 22 | 'PORT': int(env['DOTCLOUD_DATA_MYSQL_PORT']), 23 | } 24 | } 25 | elif 'DOTCLOUD_DB_SQL_HOST' in env: 26 | DATABASES = { 27 | 'default': { 28 | 'ENGINE': 'django.db.backends.postgresql_psycopg2', 29 | 'NAME': env['DOTCLOUD_PROJECT'], 30 | 'USER': env['DOTCLOUD_DB_SQL_LOGIN'], 31 | 'PASSWORD': env['DOTCLOUD_DB_SQL_PASSWORD'], 32 | 'HOST': env['DOTCLOUD_DB_SQL_HOST'], 33 | 'PORT': int(env['DOTCLOUD_DB_SQL_PORT']), 34 | } 35 | } 36 | 37 | LOGGING = { 38 | "version": 1, 39 | "disable_existing_loggers": False, 40 | "formatters": { 41 | "simple": { 42 | "format": "%(levelname)s %(message)s" 43 | }, 44 | }, 45 | "handlers": { 46 | "console": { 47 | "level": "DEBUG", 48 | "class": "logging.StreamHandler", 49 | "formatter": "simple" 50 | } 51 | }, 52 | "loggers": { 53 | "": { 54 | "handlers": ["console"], 55 | "level": "INFO", 56 | }, 57 | "django.request": { 58 | "propagate": True, 59 | }, 60 | } 61 | } -------------------------------------------------------------------------------- /django_deployer/paas_templates/appengine/settings_appengine.py: -------------------------------------------------------------------------------- 1 | try: 2 | import dev_appserver 3 | dev_appserver.fix_sys_path() 4 | except: 5 | pass 6 | 7 | 8 | import os 9 | import sys 10 | 11 | PROJECT_ROOT = os.path.dirname(__file__) 12 | 13 | on_appengine = os.getenv('SERVER_SOFTWARE','').startswith('Google App Engine') 14 | 15 | # insert libraries 16 | REQUIRE_LIB_PATH = os.path.join(os.path.dirname(__file__), '..', 'site-packages') 17 | 18 | lib_to_insert = [REQUIRE_LIB_PATH] 19 | map(lambda path: sys.path.insert(0, path), lib_to_insert) 20 | 21 | # settings need to be after insertion of libraries' location 22 | from settings import * 23 | 24 | # use cloudsql while on the production 25 | if (on_appengine or 26 | os.getenv('SETTINGS_MODE') == 'prod'): 27 | # here must use 'SETTINGS_MODE' == 'prod', it's not included in rocket_engine.on_appengine 28 | # Running on production App Engine, so use a Google Cloud SQL database. 29 | DATABASES = { 30 | 'default': { 31 | 'ENGINE': 'google.appengine.ext.django.backends.rdbms', 32 | 'INSTANCE': '{{ instancename }}', 33 | 'NAME': '{{ databasename }}', 34 | } 35 | } 36 | else: 37 | DATABASES = { 38 | 'default': { 39 | 'ENGINE': 'django.db.backends.sqlite3', 40 | 'NAME': 'django_deployer_default', 41 | 'USER': '', 42 | 'PASSWORD': '', 43 | } 44 | } 45 | 46 | # Installed apps for django-deployer 47 | PAAS_INSTALLED_APPS = ( 48 | 'rocket_engine', 49 | ) 50 | 51 | INSTALLED_APPS = tuple(list(INSTALLED_APPS) + list(PAAS_INSTALLED_APPS)) 52 | 53 | # django email backend for appengine 54 | EMAIL_BACKEND = 'rocket_engine.mail.EmailBackend' 55 | DEFAULT_FROM_EMAIL='example@example.com' 56 | #NOTICE: DEFAULT_FROM_EMAIL need to be authorized beforehand in AppEngine console, you must be verified with the permission to access that mail address. 57 | #Steps: 58 | #1. Change DEFAULT_FROM_EMAIL above to an valid email address and you have the permission to access it. 59 | #2. Log in to your Google App Engine Account. 60 | #3. Under Administration, click Permissions, and add the email address. 61 | #4. Log out, and check for the validation email. 62 | 63 | # use Blob datastore for default file storage 64 | DEFAULT_FILE_STORAGE = 'django-google-storage.storage.GoogleStorage' 65 | GS_ACCESS_KEY_ID = '' 66 | GS_SECRET_ACCESS_KEY = '' 67 | GS_STORAGE_BUCKET_NAME = '' 68 | 69 | if not (GS_ACCESS_KEY_ID and GS_SECRET_ACCESS_KEY and GS_STORAGE_BUCKET_NAME): 70 | print 'Warning: no correct settings for Google Storage, please provide it in settings_appengine.py' 71 | 72 | # static_url 73 | STATIC_URL = '/static/' 74 | STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static') 75 | 76 | # media url 77 | MEDIA_URL = '/media/' 78 | MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media') 79 | 80 | # use overwriting urls 81 | ROOT_URLCONF = "{{ project_name }}.urls_appengine" 82 | -------------------------------------------------------------------------------- /django_deployer/paas_templates/dotcloud/createdb.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | 4 | import MySQLdb 5 | import psycopg2 6 | import _mysql_exceptions 7 | from wsgi import * 8 | 9 | 10 | def create_dbs(): 11 | deadline = time.time() + 60 12 | while time.time() < deadline: 13 | try: 14 | print("create_dbs: let's go.") 15 | django_settings = __import__(os.environ['DJANGO_SETTINGS_MODULE'], fromlist='DATABASES') 16 | print("create_dbs: got settings.") 17 | databases = django_settings.DATABASES 18 | for name, db in databases.iteritems(): 19 | host = db['HOST'] 20 | user = db['USER'] 21 | password = db['PASSWORD'] 22 | port = db['PORT'] 23 | db_name = db['NAME'] 24 | db_type = db['ENGINE'] 25 | # see if it is mysql 26 | if db_type.endswith('mysql'): 27 | print 'creating database %s on %s' % (db_name, host) 28 | db = MySQLdb.connect(user=user, 29 | passwd=password, 30 | host=host, 31 | port=port) 32 | cur = db.cursor() 33 | print("Check if database is already there.") 34 | cur.execute("""SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA 35 | WHERE SCHEMA_NAME = %s""", (db_name,)) 36 | results = cur.fetchone() 37 | if not results: 38 | print("Database %s doesn't exist, lets create it." % db_name) 39 | sql = """CREATE DATABASE IF NOT EXISTS %s """ % (db_name,) 40 | print("> %s" % sql) 41 | cur.execute(sql) 42 | print(".....") 43 | else: 44 | print("database already exists, moving on to next step.") 45 | exit(0) 46 | # see if it is postgresql 47 | elif db_type.endswith('postgresql_psycopg2'): 48 | print 'creating database %s on %s' % (db_name, host) 49 | con = psycopg2.connect(host=host, user=user, password=password, port=port, database='postgres') 50 | con.set_isolation_level(0) 51 | cur = con.cursor() 52 | try: 53 | cur.execute('CREATE DATABASE %s' % db_name) 54 | except psycopg2.ProgrammingError as detail: 55 | print detail 56 | print 'moving right along...' 57 | exit(0) 58 | else: 59 | print("ERROR: {0} is not supported by this script, you will need to create your database by hand.".format(db_type)) 60 | exit(1) 61 | except psycopg2.OperationalError: 62 | print "Could not connect to database. Waiting a little bit." 63 | time.sleep(10) 64 | except _mysql_exceptions.OperationalError: 65 | print "Could not connect to database. Waiting a little bit." 66 | time.sleep(10) 67 | 68 | print 'Could not connect to database after 1 minutes. Something is wrong.' 69 | exit(1) 70 | 71 | if __name__ == '__main__': 72 | import sys 73 | print("create_dbs start") 74 | create_dbs() 75 | print("create_dbs all done") 76 | -------------------------------------------------------------------------------- /django_deployer/utils.py: -------------------------------------------------------------------------------- 1 | import git 2 | import uuid 3 | import os 4 | from jinja2 import Template 5 | 6 | def clone_git_repo(repo_url): 7 | """ 8 | input: repo_url 9 | output: path of the cloned repository 10 | steps: 11 | 1. clone the repo 12 | 2. parse 'site' into for templating 13 | 14 | assumptions: 15 | repo_url = "git@github.com:littleq0903/django-deployer-template-openshift-experiment.git" 16 | repo_local_location = "/tmp/djangodeployer-cache-xxxx" # xxxx here will be some short uuid for identify different downloads 17 | """ 18 | REPO_PREFIX = "djangodeployer-cache-" 19 | REPO_POSTFIX_UUID = str(uuid.uuid4()).split('-')[-1] 20 | REPO_CACHE_NAME = REPO_PREFIX + REPO_POSTFIX_UUID 21 | REPO_CACHE_LOCATION = '/tmp/%s' % REPO_CACHE_NAME 22 | 23 | repo = git.Repo.clone_from(repo_url, REPO_CACHE_LOCATION) 24 | return REPO_CACHE_LOCATION 25 | 26 | def get_template_filelist(repo_path, ignore_files=[], ignore_folders=[]): 27 | """ 28 | input: local repo path 29 | output: path list of files which need to be rendered 30 | """ 31 | 32 | default_ignore_files = ['.gitignore'] 33 | default_ignore_folders = ['.git'] 34 | 35 | ignore_files += default_ignore_files 36 | ignore_folders += default_ignore_folders 37 | 38 | filelist = [] 39 | 40 | for root, folders, files in os.walk(repo_path): 41 | for ignore_file in ignore_files: 42 | if ignore_file in files: 43 | files.remove(ignore_file) 44 | 45 | for ignore_folder in ignore_folders: 46 | if ignore_folder in folders: 47 | folders.remove(ignore_folder) 48 | 49 | for file_name in files: 50 | filelist.append( '%s/%s' % (root, file_name)) 51 | 52 | return filelist 53 | 54 | 55 | def render_from_repo(repo_path, to_path, template_params, settings_dir): 56 | """ 57 | rendering all files into the target directory 58 | """ 59 | TEMPLATE_PROJECT_FOLDER_PLACEHOLDER_NAME = 'deployer_project' 60 | 61 | repo_path = repo_path.rstrip('/') 62 | to_path = to_path.rstrip('/') 63 | files_to_render = get_template_filelist(repo_path, ignore_folders=[TEMPLATE_PROJECT_FOLDER_PLACEHOLDER_NAME]) 64 | 65 | 66 | # rendering generic deploy files 67 | for single_file_path in files_to_render: 68 | source_file_path = single_file_path 69 | dest_file_path = source_file_path.replace(repo_path, to_path) 70 | 71 | render_from_single_file(source_file_path, dest_file_path, template_params) 72 | 73 | settings_template_dir = os.path.join(repo_path, TEMPLATE_PROJECT_FOLDER_PLACEHOLDER_NAME) 74 | settings_files = get_template_filelist(settings_template_dir) 75 | 76 | # rendering settings file 77 | for single_file_path in settings_files: 78 | source = single_file_path 79 | dest = single_file_path.replace(settings_template_dir, settings_dir) 80 | render_from_single_file(source, dest, template_params) 81 | 82 | 83 | 84 | def render_from_single_file(file_path, dest_file_path, template_params): 85 | 86 | dest_dirname = os.path.dirname(dest_file_path) 87 | 88 | if not os.path.exists(dest_dirname): 89 | os.makedirs(dest_dirname) 90 | 91 | with open(file_path) as source_file_p: 92 | template = Template(source_file_p.read()) 93 | rendered_content = template.render(**template_params) 94 | 95 | with open(dest_file_path, 'w') as dest_file_p: 96 | dest_file_p.write(rendered_content) 97 | 98 | 99 | -------------------------------------------------------------------------------- /django_deployer/helpers.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import yaml 4 | 5 | from fabric.colors import green, red, yellow 6 | 7 | 8 | DEPLOY_YAML = os.path.join(os.getcwd(), 'deploy.yml') 9 | 10 | 11 | # 12 | # Helpers 13 | # 14 | 15 | def _create_deploy_yaml(site): 16 | _green("Creating a deploy.yml with your app's deploy info...") 17 | _write_file(DEPLOY_YAML, yaml.safe_dump(site, default_flow_style=False)) 18 | _green("Created %s" % DEPLOY_YAML) 19 | 20 | 21 | def _validate_django_settings(django_settings): 22 | django_settings_regex = r"^[\d\w_.]+$" 23 | 24 | pattern = re.compile(django_settings_regex) 25 | if not pattern.match(django_settings): 26 | raise ValueError(red("You must enter a valid dotted module path to continue!")) 27 | 28 | django_settings_path = django_settings.replace('.', '/') + '.py' 29 | if not os.path.exists(django_settings_path): 30 | raise ValueError(red( 31 | "Couldn't find a settings file at that dotted path.\n" 32 | "Make sure you're using django-deployer from your project root." 33 | )) 34 | 35 | return django_settings 36 | 37 | 38 | def _validate_project_name(project_name): 39 | project_name_regex = r"^.+$" 40 | 41 | pattern = re.compile(project_name_regex) 42 | if not pattern.match(project_name): 43 | raise ValueError(red("You must enter a project name to continue!")) 44 | 45 | if not os.path.exists(os.path.join(os.getcwd(), project_name)): 46 | raise ValueError(red( 47 | "Couldn't find that directory name under the current directory.\n" 48 | "Make sure you're using django-deployer from your project root." 49 | )) 50 | 51 | return project_name 52 | 53 | 54 | def _validate_requirements(requirements): 55 | 56 | if not requirements.endswith(".txt"): 57 | raise ValueError(red("Requirements file must end with .txt")) 58 | 59 | if not os.path.exists(os.path.join(os.getcwd(), requirements)): 60 | raise ValueError(red( 61 | "Couldn't find requirements.txt at the path you gave.\n" 62 | "Make sure you're using django-deployer from your project root." 63 | )) 64 | 65 | return requirements 66 | 67 | 68 | def _validate_managepy(managepy): 69 | managepy_regex = r"^.+manage.py$" 70 | 71 | pattern = re.compile(managepy_regex) 72 | if not pattern.match(managepy): 73 | raise ValueError(red( 74 | "Couldn't find manage.py at the path you gave.\n" 75 | "You must enter the relative path to your manage.py file to continue!" 76 | )) 77 | 78 | if not os.path.exists(os.path.join(os.getcwd(), managepy)): 79 | raise ValueError(red( 80 | "Couldn't find manage.py at the path you gave.\n" 81 | "Make sure you're using django-deployer from your project root." 82 | )) 83 | 84 | return managepy 85 | 86 | 87 | def _validate_admin_password(admin_password): 88 | password_regex = r"[A-Za-z0-9@#$%^&+=]{6,}" 89 | 90 | pattern = re.compile(password_regex) 91 | if not pattern.match(admin_password): 92 | raise ValueError(red( 93 | "The password must be at least 6 characters and contain only the following characters:\n" 94 | "A-Za-z0-9@#$%^&+=" 95 | )) 96 | 97 | return admin_password 98 | 99 | 100 | def _validate_providers(provider): 101 | providers = ['stackato', 'dotcloud', 'appengine', 'openshift'] 102 | 103 | if provider not in providers: 104 | raise ValueError(red( 105 | "Invalid provider. You must choose one of these providers:\n" 106 | "%s" % providers 107 | )) 108 | 109 | return provider 110 | 111 | 112 | # 113 | # Utils 114 | # 115 | 116 | def _write_file(path, contents): 117 | file = open(path, 'w') 118 | file.write(contents) 119 | file.close() 120 | 121 | 122 | def _read_file(path): 123 | file = open(path, 'r') 124 | contents = file.read() 125 | file.close() 126 | return contents 127 | 128 | 129 | def _join(*args): 130 | """ 131 | Convenience wrapper around os.path.join to make the rest of our 132 | functions more readable. 133 | """ 134 | return os.path.join(*args) 135 | 136 | 137 | # 138 | # Pretty colors 139 | # 140 | 141 | def _green(text): 142 | print green(text) 143 | 144 | 145 | def _red(text): 146 | print red(text) 147 | 148 | 149 | def _yellow(text): 150 | print yellow(text) 151 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | django-deployer 2 | =============== 3 | 4 | django-deployer is a deployment tool for Django that currently deploys any Django app to the following PaaS providers: Dotcloud, Stackato, OpenShift and Google App Engine. The goal of django-deployer is to minimize the effort to deploy a Django app to any of the popular PaaS providers. It asks a series of questions about your Django project, and then generates a generic deploy.yml file that captures all of your project's requirements. django-deployer then uses this deploy.yml file to translate these requirements into specific configurations for each PaaS. 5 | 6 | See the roadmap below for adding support for more providers: Heroku, OpenShift, Elastic Beanstalk and Gondor. 7 | 8 | Getting Started 9 | --------------- 10 | 11 | To install django-deployer, use ``pip`` to fetch the package from PyPi: 12 | 13 | .. code:: bash 14 | 15 | $ pip install django-deployer 16 | 17 | Now from your project's root directory run the ``deployer-init`` command once, and then run ``fab setup``. 18 | 19 | In this example (using `paasbakeoff `_), we are going to tell django-deployer to prepare our project to deploy to Google App Engine. 20 | 21 | .. code:: bash 22 | 23 | $ deployer-init 24 | $ fab -f fabfile_deployer.py setup 25 | 26 | We need to ask a few questions before we can deploy your Django app 27 | * What is your Django settings module? [settings] 28 | * Where is your manage.py file? [./manage.py] 29 | * Where is your requirements.txt file? [requirements.txt] 30 | * What version of Python does your app need? [Python2.7] 31 | * What is your STATIC_URL? [/static/] 32 | * What is your MEDIA_URL? [/media/] 33 | * Which provider would you like to deploy to (dotcloud, appengine, stackato, openshift)? 34 | * What's your Google App Engine application ID (see https://appengine.google.com/)? 35 | * What's the full instance ID of your Cloud SQL instance (should be in format "projectid:instanceid" found at https://code.google.com/apis/console/)? * What's your database name? 36 | * Where is your Google App Engine SDK location? [/usr/local/google_appengine] 37 | * What do you want to set as the admin password? 38 | Creating a deploy.yml with your app's deploy info... 39 | Created /Users/nateaune/Dropbox/code/paasbakeoff/deploy.yml 40 | 41 | Just a few more steps before you're ready to deploy your app! 42 | 43 | 1. Run this command to create the virtualenv with all the packages and deploy: 44 | 45 | $ fab -f fabfile_deployer.py deploy 46 | 47 | 2. Create and sync the db on the Cloud SQL: 48 | 49 | $ sh manage.sh cloudcreatedb 50 | $ sh manage.sh cloudsyncdb 51 | 52 | 3. Everything is set up now, you can run other commands that will execute on your remotely deployed app, such as: 53 | 54 | $ sh manage.sh dbshell 55 | 56 | Done. 57 | 58 | Now inspect your project directory and you will see that a file ``deploy.yml`` and various config files were created. 59 | 60 | **Note:** if you're going to try different PaaS providers, it's recommended that you make a separate git branch for each one, because when you re-run ``fab setup`` it could inadvertently overwrite the config files from the first run. 61 | 62 | Upgrading 63 | --------- 64 | 65 | You will notice that when we ran ``pip install django-deployer`` it created a script ``deployer-init``. When you ran this script, it created a fabfile.py in your current directory that imports the tasks module from the ``django-deployer`` project. 66 | 67 | .. code:: python 68 | 69 | from django_deployer.tasks import * 70 | 71 | This means that you can update the django-deployer package and don't need to regenerate the fabfile. 72 | 73 | .. code:: bash 74 | 75 | $ pip install -U django-deployer 76 | 77 | 78 | Contribute 79 | ---------- 80 | 81 | If you want to develop django-deployer, you can clone it and install it into your project's virtualenv: 82 | 83 | .. code:: bash 84 | 85 | $ source bin/activate 86 | (venv)$ git clone git://github.com/natea/django-deployer.git 87 | (venv)$ cd django-deployer 88 | (venv)$ python setup.py develop 89 | 90 | Or you can also install an editable source version of it using pip: 91 | 92 | .. code:: bash 93 | 94 | $ source bin/activate 95 | (venv)$ pip install -e git+git://github.com/natea/django-deployer.git#django-deployer 96 | 97 | Which will clone the git repo into the ``src`` directory of your project's virtualenv. 98 | 99 | Roadmap 100 | ------- 101 | 102 | - Add support for Heroku, OpenShift, Amazon Elastic Beanstalk and Gondor 103 | - Perform some intelligent code analysis to better guess the settings (see the djangolint project - https://github.com/yumike/djangolint) 104 | - Write tests! 105 | - Caching (Redis, Memcache) 106 | - Celery 107 | - Email 108 | - SSL 109 | 110 | 111 | .. image:: https://d2weczhvl823v0.cloudfront.net/natea/django-deployer/trend.png 112 | :alt: Bitdeli badge 113 | :target: https://bitdeli.com/free 114 | 115 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. linkcheck to check all external links for integrity 37 | echo. doctest to run all doctests embedded in the documentation if enabled 38 | goto end 39 | ) 40 | 41 | if "%1" == "clean" ( 42 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 43 | del /q /s %BUILDDIR%\* 44 | goto end 45 | ) 46 | 47 | if "%1" == "html" ( 48 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 49 | if errorlevel 1 exit /b 1 50 | echo. 51 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 52 | goto end 53 | ) 54 | 55 | if "%1" == "dirhtml" ( 56 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 57 | if errorlevel 1 exit /b 1 58 | echo. 59 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 60 | goto end 61 | ) 62 | 63 | if "%1" == "singlehtml" ( 64 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 68 | goto end 69 | ) 70 | 71 | if "%1" == "pickle" ( 72 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished; now you can process the pickle files. 76 | goto end 77 | ) 78 | 79 | if "%1" == "json" ( 80 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished; now you can process the JSON files. 84 | goto end 85 | ) 86 | 87 | if "%1" == "htmlhelp" ( 88 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can run HTML Help Workshop with the ^ 92 | .hhp project file in %BUILDDIR%/htmlhelp. 93 | goto end 94 | ) 95 | 96 | if "%1" == "qthelp" ( 97 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 98 | if errorlevel 1 exit /b 1 99 | echo. 100 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 101 | .qhcp project file in %BUILDDIR%/qthelp, like this: 102 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\django-deployer.qhcp 103 | echo.To view the help file: 104 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\django-deployer.ghc 105 | goto end 106 | ) 107 | 108 | if "%1" == "devhelp" ( 109 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 110 | if errorlevel 1 exit /b 1 111 | echo. 112 | echo.Build finished. 113 | goto end 114 | ) 115 | 116 | if "%1" == "epub" ( 117 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 118 | if errorlevel 1 exit /b 1 119 | echo. 120 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 121 | goto end 122 | ) 123 | 124 | if "%1" == "latex" ( 125 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 129 | goto end 130 | ) 131 | 132 | if "%1" == "text" ( 133 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The text files are in %BUILDDIR%/text. 137 | goto end 138 | ) 139 | 140 | if "%1" == "man" ( 141 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 145 | goto end 146 | ) 147 | 148 | if "%1" == "texinfo" ( 149 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 150 | if errorlevel 1 exit /b 1 151 | echo. 152 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 153 | goto end 154 | ) 155 | 156 | if "%1" == "gettext" ( 157 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 158 | if errorlevel 1 exit /b 1 159 | echo. 160 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 161 | goto end 162 | ) 163 | 164 | if "%1" == "changes" ( 165 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 166 | if errorlevel 1 exit /b 1 167 | echo. 168 | echo.The overview file is in %BUILDDIR%/changes. 169 | goto end 170 | ) 171 | 172 | if "%1" == "linkcheck" ( 173 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 174 | if errorlevel 1 exit /b 1 175 | echo. 176 | echo.Link check complete; look for any errors in the above output ^ 177 | or in %BUILDDIR%/linkcheck/output.txt. 178 | goto end 179 | ) 180 | 181 | if "%1" == "doctest" ( 182 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 183 | if errorlevel 1 exit /b 1 184 | echo. 185 | echo.Testing of doctests in the sources finished, look at the ^ 186 | results in %BUILDDIR%/doctest/output.txt. 187 | goto end 188 | ) 189 | 190 | :end 191 | -------------------------------------------------------------------------------- /django_deployer/tasks.py: -------------------------------------------------------------------------------- 1 | import os 2 | import yaml 3 | 4 | from fabric.api import prompt 5 | 6 | from django_deployer.helpers import ( 7 | DEPLOY_YAML, 8 | _create_deploy_yaml, 9 | _validate_django_settings, 10 | _validate_project_name, 11 | _validate_managepy, 12 | _validate_requirements, 13 | _validate_admin_password, 14 | _validate_providers, 15 | _read_file, 16 | _green, 17 | _yellow, 18 | _red, 19 | ) 20 | 21 | from .providers import PROVIDERS 22 | 23 | 24 | def init(provider=None): 25 | """ 26 | Runs through a questionnaire to set up your project's deploy settings 27 | """ 28 | if os.path.exists(DEPLOY_YAML): 29 | _yellow("\nIt looks like you've already gone through the questionnaire.") 30 | cont = prompt("Do you want to go through it again and overwrite the current one?", default="No") 31 | 32 | if cont.strip().lower() == "no": 33 | return None 34 | _green("\nWelcome to the django-deployer!") 35 | _green("\nWe need to ask a few questions in order to set up your project to be deployed to a PaaS provider.") 36 | 37 | # TODO: identify the project dir based on where we find the settings.py or urls.py 38 | 39 | django_settings = prompt( 40 | "* What is your Django settings module?", 41 | default="settings", 42 | validate=_validate_django_settings 43 | ) 44 | 45 | managepy = prompt( 46 | "* Where is your manage.py file?", 47 | default="./manage.py", 48 | validate=_validate_managepy 49 | ) 50 | 51 | requirements = prompt( 52 | "* Where is your requirements.txt file?", 53 | default="requirements.txt", 54 | validate=_validate_requirements 55 | ) 56 | # TODO: confirm that the file exists 57 | # parse the requirements file and warn the user about best practices: 58 | # Django==1.4.1 59 | # psycopg2 if they selected PostgreSQL 60 | # MySQL-python if they selected MySQL 61 | # South for database migrations 62 | # dj-database-url 63 | 64 | pyversion = prompt("* What version of Python does your app need?", default="Python2.7") 65 | 66 | # TODO: get these values by reading the settings.py file 67 | static_url = prompt("* What is your STATIC_URL?", default="/static/") 68 | media_url = prompt("* What is your MEDIA_URL?", default="/media/") 69 | 70 | if not provider: 71 | provider = prompt("* Which provider would you like to deploy to (dotcloud, appengine, stackato, openshift)?", 72 | validate=_validate_providers) 73 | 74 | # Where to place the provider specific questions 75 | site = {} 76 | additional_site = {} 77 | 78 | if provider == "appengine": 79 | applicationid = prompt("* What's your Google App Engine application ID (see https://appengine.google.com/)?", validate=r'.+') 80 | instancename = prompt("* What's the full instance ID of your Cloud SQL instance\n" 81 | "(should be in format \"projectid:instanceid\" found at https://code.google.com/apis/console/)?", validate=r'.+:.+') 82 | databasename = prompt("* What's your database name?", validate=r'.+') 83 | sdk_location = prompt("* Where is your Google App Engine SDK location?", 84 | default="/usr/local/google_appengine", 85 | validate=r'.+' # TODO: validate that this path exists 86 | ) 87 | 88 | additional_site.update({ 89 | # quotes for the yaml issue 90 | 'application_id': applicationid, 91 | 'instancename': instancename, 92 | 'databasename': databasename, 93 | 'sdk_location': sdk_location, 94 | }) 95 | 96 | # only option with Google App Engine is MySQL, so we'll just hardcode it 97 | site = { 98 | 'database': 'MySQL' 99 | } 100 | 101 | elif provider == "openshift": 102 | application_name = prompt("* What is your openshift application name?") 103 | 104 | site = { 105 | 'application_name': application_name 106 | } 107 | 108 | else: 109 | database = prompt("* What database does your app use?", default="PostgreSQL") 110 | site = { 111 | 'database': database, 112 | } 113 | 114 | # TODO: add some validation that the admin password is valid 115 | # TODO: let the user choose the admin username instead of hardcoding it to 'admin' 116 | admin_password = prompt("* What do you want to set as the admin password?", 117 | validate=_validate_admin_password 118 | ) 119 | 120 | import random 121 | SECRET_KEY = ''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) 122 | SECRET_KEY = "'" + SECRET_KEY + "'" 123 | 124 | site.update({ 125 | 'pyversion': pyversion, 126 | 'django_settings': django_settings, 127 | 'managepy': managepy, 128 | 'requirements': requirements, 129 | 'static_url': static_url, 130 | 'media_url': media_url, 131 | 'provider': provider, 132 | 'admin_password': admin_password, 133 | 'secret_key': SECRET_KEY, 134 | }) 135 | 136 | site.update(additional_site) 137 | 138 | _create_deploy_yaml(site) 139 | 140 | return site 141 | 142 | 143 | def setup(provider=None): 144 | """ 145 | Creates the provider config files needed to deploy your project 146 | """ 147 | site = init(provider) 148 | if not site: 149 | site = yaml.safe_load(_read_file(DEPLOY_YAML)) 150 | 151 | provider_class = PROVIDERS[site['provider']] 152 | provider_class.init(site) 153 | 154 | 155 | def deploy(provider=None): 156 | """ 157 | Deploys your project 158 | """ 159 | if os.path.exists(DEPLOY_YAML): 160 | site = yaml.safe_load(_read_file(DEPLOY_YAML)) 161 | 162 | provider_class = PROVIDERS[site['provider']] 163 | provider_class.deploy() 164 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/django-deployer.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/django-deployer.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/django-deployer" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/django-deployer" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # django-deployer documentation build configuration file, created by 4 | # sphinx-quickstart on Mon Mar 18 10:06:23 2013. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | # -- General configuration ----------------------------------------------------- 22 | 23 | # If your documentation needs a minimal Sphinx version, state it here. 24 | #needs_sphinx = '1.0' 25 | 26 | # Add any Sphinx extension module names here, as strings. They can be extensions 27 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 28 | extensions = [] 29 | 30 | # Add any paths that contain templates here, relative to this directory. 31 | templates_path = ['_templates'] 32 | 33 | # The suffix of source filenames. 34 | source_suffix = '.rst' 35 | 36 | # The encoding of source files. 37 | #source_encoding = 'utf-8-sig' 38 | 39 | # The master toctree document. 40 | master_doc = 'index' 41 | 42 | # General information about the project. 43 | project = u'django-deployer' 44 | copyright = u'2013, Nate Aune' 45 | 46 | # The version info for the project you're documenting, acts as replacement for 47 | # |version| and |release|, also used in various other places throughout the 48 | # built documents. 49 | # 50 | # The short X.Y version. 51 | version = '0.1' 52 | # The full version, including alpha/beta/rc tags. 53 | release = '0.1' 54 | 55 | # The language for content autogenerated by Sphinx. Refer to documentation 56 | # for a list of supported languages. 57 | #language = None 58 | 59 | # There are two options for replacing |today|: either, you set today to some 60 | # non-false value, then it is used: 61 | #today = '' 62 | # Else, today_fmt is used as the format for a strftime call. 63 | #today_fmt = '%B %d, %Y' 64 | 65 | # List of patterns, relative to source directory, that match files and 66 | # directories to ignore when looking for source files. 67 | exclude_patterns = ['_build'] 68 | 69 | # The reST default role (used for this markup: `text`) to use for all documents. 70 | #default_role = None 71 | 72 | # If true, '()' will be appended to :func: etc. cross-reference text. 73 | #add_function_parentheses = True 74 | 75 | # If true, the current module name will be prepended to all description 76 | # unit titles (such as .. function::). 77 | #add_module_names = True 78 | 79 | # If true, sectionauthor and moduleauthor directives will be shown in the 80 | # output. They are ignored by default. 81 | #show_authors = False 82 | 83 | # The name of the Pygments (syntax highlighting) style to use. 84 | pygments_style = 'sphinx' 85 | 86 | # A list of ignored prefixes for module index sorting. 87 | #modindex_common_prefix = [] 88 | 89 | 90 | # -- Options for HTML output --------------------------------------------------- 91 | 92 | # The theme to use for HTML and HTML Help pages. See the documentation for 93 | # a list of builtin themes. 94 | html_theme = 'default' 95 | 96 | # Theme options are theme-specific and customize the look and feel of a theme 97 | # further. For a list of options available for each theme, see the 98 | # documentation. 99 | #html_theme_options = {} 100 | 101 | # Add any paths that contain custom themes here, relative to this directory. 102 | #html_theme_path = [] 103 | 104 | # The name for this set of Sphinx documents. If None, it defaults to 105 | # " v documentation". 106 | #html_title = None 107 | 108 | # A shorter title for the navigation bar. Default is the same as html_title. 109 | #html_short_title = None 110 | 111 | # The name of an image file (relative to this directory) to place at the top 112 | # of the sidebar. 113 | #html_logo = None 114 | 115 | # The name of an image file (within the static path) to use as favicon of the 116 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 117 | # pixels large. 118 | #html_favicon = None 119 | 120 | # Add any paths that contain custom static files (such as style sheets) here, 121 | # relative to this directory. They are copied after the builtin static files, 122 | # so a file named "default.css" will overwrite the builtin "default.css". 123 | html_static_path = ['_static'] 124 | 125 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 126 | # using the given strftime format. 127 | #html_last_updated_fmt = '%b %d, %Y' 128 | 129 | # If true, SmartyPants will be used to convert quotes and dashes to 130 | # typographically correct entities. 131 | #html_use_smartypants = True 132 | 133 | # Custom sidebar templates, maps document names to template names. 134 | #html_sidebars = {} 135 | 136 | # Additional templates that should be rendered to pages, maps page names to 137 | # template names. 138 | #html_additional_pages = {} 139 | 140 | # If false, no module index is generated. 141 | #html_domain_indices = True 142 | 143 | # If false, no index is generated. 144 | #html_use_index = True 145 | 146 | # If true, the index is split into individual pages for each letter. 147 | #html_split_index = False 148 | 149 | # If true, links to the reST sources are added to the pages. 150 | #html_show_sourcelink = True 151 | 152 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 153 | #html_show_sphinx = True 154 | 155 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 156 | #html_show_copyright = True 157 | 158 | # If true, an OpenSearch description file will be output, and all pages will 159 | # contain a tag referring to it. The value of this option must be the 160 | # base URL from which the finished HTML is served. 161 | #html_use_opensearch = '' 162 | 163 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 164 | #html_file_suffix = None 165 | 166 | # Output file base name for HTML help builder. 167 | htmlhelp_basename = 'django-deployerdoc' 168 | 169 | 170 | # -- Options for LaTeX output -------------------------------------------------- 171 | 172 | latex_elements = { 173 | # The paper size ('letterpaper' or 'a4paper'). 174 | #'papersize': 'letterpaper', 175 | 176 | # The font size ('10pt', '11pt' or '12pt'). 177 | #'pointsize': '10pt', 178 | 179 | # Additional stuff for the LaTeX preamble. 180 | #'preamble': '', 181 | } 182 | 183 | # Grouping the document tree into LaTeX files. List of tuples 184 | # (source start file, target name, title, author, documentclass [howto/manual]). 185 | latex_documents = [ 186 | ('index', 'django-deployer.tex', u'django-deployer Documentation', 187 | u'Nate Aune', 'manual'), 188 | ] 189 | 190 | # The name of an image file (relative to this directory) to place at the top of 191 | # the title page. 192 | #latex_logo = None 193 | 194 | # For "manual" documents, if this is true, then toplevel headings are parts, 195 | # not chapters. 196 | #latex_use_parts = False 197 | 198 | # If true, show page references after internal links. 199 | #latex_show_pagerefs = False 200 | 201 | # If true, show URL addresses after external links. 202 | #latex_show_urls = False 203 | 204 | # Documents to append as an appendix to all manuals. 205 | #latex_appendices = [] 206 | 207 | # If false, no module index is generated. 208 | #latex_domain_indices = True 209 | 210 | 211 | # -- Options for manual page output -------------------------------------------- 212 | 213 | # One entry per manual page. List of tuples 214 | # (source start file, name, description, authors, manual section). 215 | man_pages = [ 216 | ('index', 'django-deployer', u'django-deployer Documentation', 217 | [u'Nate Aune'], 1) 218 | ] 219 | 220 | # If true, show URL addresses after external links. 221 | #man_show_urls = False 222 | 223 | 224 | # -- Options for Texinfo output ------------------------------------------------ 225 | 226 | # Grouping the document tree into Texinfo files. List of tuples 227 | # (source start file, target name, title, author, 228 | # dir menu entry, description, category) 229 | texinfo_documents = [ 230 | ('index', 'django-deployer', u'django-deployer Documentation', 231 | u'Nate Aune', 'django-deployer', 'One line description of project.', 232 | 'Miscellaneous'), 233 | ] 234 | 235 | # Documents to append as an appendix to all manuals. 236 | #texinfo_appendices = [] 237 | 238 | # If false, no module index is generated. 239 | #texinfo_domain_indices = True 240 | 241 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 242 | #texinfo_show_urls = 'footnote' 243 | -------------------------------------------------------------------------------- /django_deployer/providers.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | 4 | from jinja2 import Environment, PackageLoader 5 | 6 | from django_deployer.helpers import _write_file 7 | from django_deployer import utils 8 | 9 | from fabric.operations import local 10 | from fabric.context_managers import shell_env 11 | 12 | 13 | template_env = Environment(loader=PackageLoader('django_deployer', 'paas_templates')) 14 | 15 | def run_hooks(script_name): 16 | HOOKS_FOLDER = 'deployer_hooks' 17 | local('bash %s/%s' % (HOOKS_FOLDER, script_name) ) 18 | 19 | 20 | class PaaSProvider(object): 21 | """ 22 | Base PaasProvider class. PaaS providers should inherit from this 23 | class and override all methods. 24 | """ 25 | 26 | # Subclasses should override these 27 | name = "" 28 | setup_instructions = "" 29 | PYVERSIONS = {} 30 | provider_yml_name = "%s.yml" % name 31 | git_template = False 32 | git_template_url = "" 33 | 34 | @classmethod 35 | def init(cls, site): 36 | """ 37 | put site settings in the header of the script 38 | """ 39 | bash_header = "" 40 | for k,v in site.items(): 41 | bash_header += "%s=%s" % (k.upper(), v) 42 | bash_header += '\n' 43 | site['bash_header'] = bash_header 44 | 45 | # TODO: execute before_deploy 46 | # P.S. running init_before seems like impossible, because the file hasn't been rendered. 47 | if cls.git_template: 48 | # do render from git repo 49 | print "Cloning template files..." 50 | repo_local_copy = utils.clone_git_repo(cls.git_template_url) 51 | print "Rendering files from templates..." 52 | target_path = os.getcwd() 53 | settings_dir = '/'.join(site['django_settings'].split('.')[:-1]) 54 | site['project_name'] = settings_dir.replace('/', '.') 55 | settings_dir_path = target_path 56 | if settings_dir: 57 | settings_dir_path += '/' + settings_dir 58 | utils.render_from_repo(repo_local_copy, target_path, site, settings_dir_path) 59 | else: 60 | cls._create_configs(site) 61 | print cls.setup_instructions 62 | # TODO: execute after_deploy 63 | run_hooks('init_after') 64 | 65 | @classmethod 66 | def deploy(cls): 67 | run_hooks('deploy_before') 68 | run_hooks('deploy') 69 | run_hooks('deploy_after') 70 | 71 | @classmethod 72 | def delete(cls): 73 | raise NotImplementedError() 74 | 75 | @classmethod 76 | def _create_configs(cls, site): 77 | """ 78 | This is going to generate the following configuration: 79 | * wsgi.py 80 | * .yml 81 | * settings_.py 82 | """ 83 | provider = cls.name 84 | 85 | cls._render_config('wsgi.py', 'wsgi.py', site) 86 | 87 | # create yaml file 88 | yaml_template_name = os.path.join(provider, cls.provider_yml_name) 89 | cls._render_config(cls.provider_yml_name, yaml_template_name, site) 90 | 91 | # create requirements file 92 | # don't do anything if the requirements file is called requirements.txt and in the root of the project 93 | requirements_filename = "requirements.txt" 94 | if site['requirements'] != requirements_filename: # providers expect the file to be called requirements.txt 95 | requirements_template_name = os.path.join(provider, requirements_filename) 96 | cls._render_config(requirements_filename, requirements_template_name, site) 97 | 98 | # create settings file 99 | settings_template_name = os.path.join(provider, 'settings_%s.py' % provider) 100 | settings_path = site['django_settings'].replace('.', '/') + '_%s.py' % provider 101 | cls._render_config(settings_path, settings_template_name, site) 102 | 103 | @classmethod 104 | def _render_config(cls, dest, template_name, template_args): 105 | """ 106 | Renders and writes a template_name to a dest given some template_args. 107 | 108 | This is for platform-specific configurations 109 | """ 110 | template_args = template_args.copy() 111 | 112 | # Substitute values here 113 | pyversion = template_args['pyversion'] 114 | template_args['pyversion'] = cls.PYVERSIONS[pyversion] 115 | 116 | template = template_env.get_template(template_name) 117 | contents = template.render(**template_args) 118 | _write_file(dest, contents) 119 | 120 | 121 | class Stackato(PaaSProvider): 122 | """ 123 | ActiveState Stackato PaaSProvider. 124 | """ 125 | name = "stackato" 126 | 127 | PYVERSIONS = { 128 | "Python2.7": "python27", 129 | "Python3.2": "python32", 130 | } 131 | 132 | setup_instructions = """ 133 | Just a few more steps before you're ready to deploy your app! 134 | 135 | 1. Go to http://www.activestate.com/stackato/download_client to download 136 | the Stackato client, and then add the executable somewhere in your PATH. 137 | If you're not sure where to place it, you can simply drop it in your 138 | project's root directory (the same directory as the fabfile.py created 139 | by django-deployer). 140 | 141 | 2. Once you've done that, target the stackato api with: 142 | 143 | $ stackato target api.stacka.to 144 | 145 | and then login. You can find your sandbox password at 146 | https://account.activestate.com, which you'll need when 147 | using the command: 148 | 149 | $ stackato login --email 150 | 151 | 3. You can push your app the first time with: 152 | 153 | $ stackato push -n 154 | 155 | and make subsequent updates with: 156 | 157 | $ stackato update 158 | 159 | """ 160 | 161 | provider_yml_name = "stackato.yml" 162 | 163 | def init(): 164 | pass 165 | 166 | def deploy(): 167 | pass 168 | 169 | def delete(): 170 | pass 171 | 172 | 173 | class DotCloud(PaaSProvider): 174 | """ 175 | Dotcloud PaaSProvider. 176 | """ 177 | 178 | name = "dotcloud" 179 | 180 | PYVERSIONS = { 181 | "Python2.6": "v2.6", 182 | "Python2.7": "v2.7", 183 | "Python3.2": "v3.2", 184 | } 185 | 186 | setup_instructions = """ 187 | Just a few more steps before you're ready to deploy your app! 188 | 189 | 1. Install the dotcloud command line tool with: 190 | 191 | $ pip install dotcloud 192 | 193 | 2. Once you've done that, setup your Dotcloud environment for the first time: 194 | 195 | $ dotcloud setup 196 | dotCloud username or email: appsembler 197 | Password: 198 | ==> dotCloud authentication is complete! You are recommended to run `dotcloud check` now. 199 | 200 | $ dotcloud check 201 | ==> Checking the authentication status 202 | ==> Client is authenticated as appsembler 203 | 204 | 3. You can create the app with: 205 | 206 | $ dotcloud create myapp 207 | 208 | and deploy it with: 209 | 210 | $ dotcloud push 211 | 212 | """ 213 | 214 | provider_yml_name = "dotcloud.yml" 215 | 216 | @classmethod 217 | def init(cls, site): 218 | super(DotCloud, cls).init(site) 219 | 220 | # config_list: files to put in project folder, django_config_list: files to put in django project folder 221 | config_list = [ 222 | 'createdb.py', 223 | 'mkadmin.py', 224 | 'nginx.conf', 225 | 'postinstall', 226 | 'wsgi.py', 227 | ] 228 | 229 | # for rendering configs under root 230 | get_config = lambda filename: cls._render_config(filename, os.path.join(cls.name, filename), site) 231 | map(get_config, config_list) 232 | 233 | def deploy(): 234 | pass 235 | 236 | def delete(): 237 | pass 238 | 239 | 240 | class AppEngine(PaaSProvider): 241 | """ 242 | AppEngine PaaSProvider 243 | """ 244 | 245 | name = 'appengine' 246 | 247 | PYVERSIONS = { 248 | "Python2.7": "v2.7" 249 | } 250 | 251 | setup_instructions = """ 252 | Just a few more steps before you're ready to deploy your app! 253 | 254 | 1. Run this command to create the virtualenv with all the packages and deploy: 255 | 256 | $ fab -f fabfile_deployer.py deploy 257 | 258 | 2. Create and sync the db on the Cloud SQL: 259 | 260 | $ sh manage.sh cloudcreatedb 261 | $ sh manage.sh cloudsyncdb 262 | 263 | 3. Everything is set up now, you can run other commands that will execute on your remotely deployed app, such as: 264 | 265 | $ sh manage.sh dbshell 266 | 267 | """ 268 | 269 | provider_yml_name = "app.yaml" 270 | 271 | # switch to the git repo 272 | git_template = True 273 | git_template_url = "git@github.com:littleq0903/django-deployer-template-appengine.git" 274 | 275 | @classmethod 276 | def init(cls, site): 277 | super(AppEngine, cls).init(site) 278 | 279 | 280 | def delete(): 281 | pass 282 | 283 | class OpenShift(PaaSProvider): 284 | """ 285 | OpenShift PaaSProvider 286 | """ 287 | name = 'openshift' 288 | 289 | PYVERSIONS = { 290 | "Python2.6": "v2.6" 291 | } 292 | 293 | setup_instructions = "" 294 | git_template = True 295 | git_template_url = "git@github.com:littleq0903/django-deployer-template-openshift-experiment.git" 296 | 297 | @classmethod 298 | def init(cls, site): 299 | super(OpenShift, cls).init(site) 300 | 301 | #set git url to rhc 302 | 303 | # the first time deployment need to do "git push rhc --force" 304 | 305 | 306 | 307 | PROVIDERS = { 308 | 'stackato': Stackato, 309 | 'dotcloud': DotCloud, 310 | 'openshift': OpenShift, 311 | 'appengine': AppEngine 312 | } 313 | --------------------------------------------------------------------------------