django rainbow #3

  • By charmers
  • Latest version (#3)
  • precise
  • Stable
  • Edge

Description

Django-rainbow is a full-fledged Django web project deployment charm. One can deploy many projects onto a single instance
by maintaining individual config files pertaining to the project. Django-rainbow is a safe and convenient platform
for development or production web server management. Web sites are updated instantly using mercurial based versioning.
Your django-rainbow project file can be stored for future use, allowing anyone using juju a fail safe method to
develop and deploy your project without creating conflicting structure. Django-rainbow is a "Set it and forget it"
platform leaving development issues with the developers :)


Django Rainbow


charm name: django-rainbow

Django-rainbow is designed to automate deployment of Django web projects
to the cloud. Any Django project which resides on a hosted mercurial (hg) repository can be deployed using this charm.
Django-rainbow is a solid tool with a forgiving design regarding re-triggering.
Data is safe from deletion without becoming isolated from the charm. Database and project data are never removed, replaced, or deleted. This charm does not require additional packages or have any dependencies outside of juju. All scripts are written in/for the Bash shell using Ubuntu 12.04 64 bit (Precise Pangolin).

Use:

Put Django-rainbow into a local charm repository.
Edit the config.yaml file with your django-rainbow project customizations.
Deploy the charm with --> juju deploy --repository=. local:precise/django-rainbow
Edit the secondary project config file. This file is called
your-project.yaml by default.
The renamed your-project.yaml file is deployed with -->
juju set django-rainbow --config /path/to/your-project.yaml
Trigger the config-changed hook to update or add a project to the instance --> juju set --config=/path/to/your-project.yaml django-rainbow.


It is expected to store the your-project.yaml files in a direcory for future use. These project config files can be distributed, allowing anyone to launch the project to the cloud. The project must reside on a hosted third party mercurial repository, e.g. Bit Bucket. When the project config file is customized, the config-changed hook will,

  • Create or update the virtual host provided in the your-project.yaml file and place it in the Apache2 sites-available directory.
  • Pull or update the project from the hosted repository to the directory listed as: DocumentRoot in the provided virtual host. Note: Any changes to the repository will be public immediately.
  • Parse the project settings.py file for database,project settings, and a time stamp.
  • Create or update the database, user, and tables with mysql and/or configure the project.

Logging files contain any run-time errors according to the current revision number. Installation logs use the integer in the revision file of the charm base directory. Configuration logs will use the revision number set in the your-project.yaml or config.yaml files. These logs only contain critical errors throughout hook run-time. This allows for simple debugging regarding django-rainbow development.

Configuration:

-config.yaml-
This file is the primary settings for django-rainbow. All of the settings set in this file will install with django-rainbow. It is reasonable to include project settings in here if there is to be only one project per django-rainbow instance. If you wish to launch many Django projects per instance, the your-project.yaml file will need to be utilized.

-your-project.yaml-
All settings in this file relate to a specific Django project repository. It is expected to rename and store this file separate from the charm. One can keep many of these yaml files handy to launch or update live Django projects.

-Package installation-
Django-rainbow will automatically fetch and search your package urls for either
setup.py or configure scripts. The first match in the lowest section of the directory is assumed the installation type, e.g. Python install is assumed if setup.py is found in the next directory and a configure script in a subsequent directory of the extracted package. This applies to all package urls provided in both the config.yaml and your-project.yaml file except for the apt-get and pip packages. With this, one can include a git repository with either setup.py or binary compilation configure script. After, make, make install, commands will be issued if appropriate. Note: Remember to include a gcc compiler and any dependencies if binary code is to be fetched and compiled.

-Sites Framework-
The Django sites framework can be administered through django-rainbow. Project sites tables are created through fixture files kept in the base directory of the project. The project-site-name and project-site-domain option need to be set for this to happen. Also, django-rainbow will parse you project settings.py file for a SITE_ID declaration and django.contrib.sites listed in installed_apps. All of the above conditions need to be satisfied to allow django.sites framework updating. The sites framework will only update the first time the config-changed hook is ran. All subsequent re-triggering will maintain the initial setting of the: name, domain, and SITE_ID (this includes null settings). After the first config-changed run, setting the always-update-sites-framework is the only method to update the sites framework. Note: this is the only way to load other fixture files in your project.

-Database synchronization-
A python manage.py syncdb is only necessary when settings.py changes have occurred. For this reason, django-rainbow maintains a current time stamp of the settings.py file. When the settings.py file is modified, the config-changed hook will issue a python manage.py syncdb command. While it is redundant, this command can be ran every time a project is updated by setting the always-update-database option.

-Installation files-
The rainbow-installation-directory option sets the base directory for all django-rainbow project settings. This includes: logging, configuration files, package source files, and other django-rainbow related data.

All django-rainbow data files and package source are stored below the directory set by the rainbow-installation-directory option. This directory holds

Tips:
1) Make sure when the project repository is pulled onto the server for the first time, the DocumentRoot directory listed in the virtual host is the base directory of the project. This may require changing the project repository directory structure or virtual host settings a bit.
2) Do not edit any repository data on the instance. This data will be lost with the next config-changed hook. The project should only be updated by a config-changed trigger. This is what the revision setting is for in the config files.
3) A juju set django-rainbow --config /path/to/your-project.yaml will trigger the config-changed hook trigger. For single projects with the config.yaml file, a juju set django-rainbow revision=[num] can be used.
4) All of the django-rainbow data files are kept in the directory specified with the rainbow-installation-directory: option in config.yaml.
5) Many of the django-rainbow settings are described/explained in the config.yaml option descriptions.
6) Comment out the set -eux command in the config-changed and install hooks. This will prevent plain text printing of your repository password.


LIMITATIONS:
Django Rainbow is a generic platform to deploy Django projects. Don't expect too much versatility.
1) Django-rainbow only supports Mercurial and Bit bucket for project code hosting.
2) The only supported project database is mysql.

AUTHOR:
Surgemcgee RobertSteckroth@gmail.com
Robert Edward Steckroth II

LICENCE:

Django Rainbow is a charm written for Juju
Copyright (C) 2012  Robert Edward Steckroth II

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/)

Configuration

rainbow-packages
(string) The standard and basic packages for django-rainbow. These only include what is needed for a basic Django web server and operation of this charm. Others can be added below.
apache2 python-mysqldb libapache2-mod-wsgi git mercurial pwgen python-pip python-setuptools
always-update-sites-framework
(string) (Optional) Setting this option to non-empty will always update the project-site-name and project-site-domain options from these yaml files into the django.sites framework. Set this to empty and only the intial options from the first run of the config-changed hook will be loaded. After that, the sites settings can be altered in the Django Admin console. This can be set later to start the sites framework updating with this config.
pip-packages
(string) These will be passed to pip install.
always-update-database
(string) (Optional) Setting this option to non-empty will force a project database sync. If empty, the project database will only update when the settings.py file is modified from the current time stamp.
re-install-mysql-server
(string) Set this to true (or non-empty), if you wish to have the mysql client core removed and purged from the instance. This will effectively replace the mysql root password with a random one. This should not remove the database entries, but no garenties! This executes when django-rainbow service is destroyed and then re-deloyed or the install hook is re-triggerd. Leave empty for false.
hg-packages
(string) These need to contain either source code with a configure file, or a python package with a setup.py file. Seperate urls with a space.
project-repo-username
(string) The username of the project repository.
project-apache2-vhost
(string) The entire virtual host for this django project. This will be place in a individual file and loaded with a2ensite.
rainbow-installation-directory
(string) The directory that Django-rainbow will use to store data. This included packages, logs, and installation settings.
/var/lib/django-rainbow
bzr-packages
(string) These need to contain either source code with a configure file, or a python package with a setup.py file. Seperate urls with a space.
git-packages
(string) These need to contain either source code with a configure file, or a python package with a setup.py file. Seperate urls with a space.
project-repo-type
(string) This is the brand of repository versioning the project uses. Only hg for now... E.g. bzr, hg, git, svn, etc...
tar-packages
(string) These need to contain either source code with a configure file, or a python package with a setup.py file. These URLs need to conatain a file with tar compession. You can use either tar, gzip (tar.gz), or bzip2 (tar.bz2) compressed files. Seperate urls with a space. Note: you can change the Django version here.
https://www.djangoproject.com/download/1.4/tarball
project-repo-url
(string) The url of the project repository. Only bitbucket is supported currently. E.g. https://bitbucket.org/ubernostrum/django-registration ssh://user@your-site.com/project
project-site-domain
(string) (Optional) This is the domian given to the site. It is used with emailing and running multiple sites toupled togther. Can be changed with the Django Admin system later. This option will be ignored if your do not have django.contrib.sites and a SITE_ID specified in the settings.py file.
apt-get-packages
(string) Debian packages to install (eg. python-django-south). This string will be passed to apt-get.
project-repo-password
(string) The password of the project repository.
revision
(string) The revision number of this file.
1
project-site-name
(string) (Optional) This is the name given to the site. It is used with emailing and running multiple sites toupled togther. Can be changed with the Django Admin system later. This option will be ignored if your do not have django.contrib.sites and a SITE_ID specified in the settings.py file.
purge-instance
(string) Set this to true (or non-empty), if you wish to have all packages purged and re-installed upon re-installation of django-rainbow. This includes any additional packages that are listed above or have been installed previously with django-rainbow. Do this if you have added any packages with dependency issues native to this charm or you wish to replace off of your package config files with the default ones. This executes when django-rainbow service is destroyed and then re-deloyed or the install hook is re-ran. Leave empty for false. --------------------------------------------------------------------- DOES NOT INCLUDE MYSQL! If you want to re-install the mysql client than set the re-install-mysql-server to true. ---------------------------------------------------------------------