1
Juju charm python-django
2
========================
4
:Author: Patrick Hetu <patrick.hetu@gmail.com> and Bruno Girin
9
Django is a high-level web application framework that loosely follows
10
the model-view-controller design pattern. Python's equivalent to Ruby
11
on Rails, Django lets you build complex data-driven websites quickly
12
and easily - Django focuses on automating as much as possible and
13
adhering to the "Don't Repeat Yourself" (DRY) principle. Django
14
additionally emphasizes reusability and "pluggability" of components;
15
many generic third-party "applications" are available to enhance
16
projects or to simply to reduce development time even further.
18
Notable features include:
20
* An object-relational mapper (ORM)
21
* Automatic admin interface
22
* Elegant URL dispatcher
23
* Form serialization and validation system
25
* Lightweight, standalone web server for development and testing
26
* Internationalization support
27
* Testing framework and client
32
This charm will install Django. It can also install your Django
33
project and his dependencies from either a template or from a
34
version control system.
36
It can also link your project to a database and sync the schemas.
37
This charm also come with a Fabric fabfile to interact with the
38
deployement in a cloud aware manner.
47
juju deploy python-django
49
juju deploy postgresql
50
juju add-relation python-django postgresql:db
53
juju add-relation python-django gunicorn
54
juju expose python-django
56
In a couple of minute, your new (vanilla) Django site should be ready at
57
the public address of gunicorn. You can find it in the output of the
58
`juju status` command.
60
This is roughtly equivalent to the `Creating a project`_ step in Django's
63
.. _`Creating a project`: https://docs.djangoproject.com/en/1.5/intro/tutorial01/#creating-a-project
65
Example: Deploying using site a template
66
----------------------------------------
68
Setup your Django specific parameters in mydjangosite.yaml like this one::
71
project_template_url: https://github.com/xenith/django-base-template/zipball/master
72
project_template_extension: py,md,rst
76
If your using juju-core you must remove the first line
77
of the file and the indentation for the rest of the file.
79
2. Deployment with `Gunicorn`::
82
juju deploy --config mydjangosite.yaml mydjangosite
84
juju deploy postgresql
85
juju add-relation mydjangosite postgresql:db
88
juju add-relation mydjangosite gunicorn
89
juju expose mydjangosite
92
Example: Deploying using code repository
93
----------------------------------------
95
1. Setup your Django specific parameters in mydjangosite.yaml like this one::
99
repos_url: lp:~patrick-hetu/my_site
103
If your using juju-core you must remove the first line
104
of the file and the indentation for the rest of the file.
106
2. Deployment with `Gunicorn`::
109
juju deploy --config mydjangosite.yaml python-django
111
juju deploy postgresql
112
juju add-relation python-django postgresql:db
115
juju add-relation python-django gunicorn
116
juju expose python-django
120
If your using juju-core you must add --upload-tools to the
121
`juju bootstrap` command.
123
3. Accessing your new Django site should be ready at the public address of
124
Gunicorn. To find it look for it in the output of the `juju status` command.
127
Project layout and code injection
128
---------------------------------
130
Taking the previous example, your web site should be on the Django node at::
134
As you can see there the charm have inject some code at the end of your settings.py
135
file (or created it if it was not there) to be able to import what's in the
136
`juju_settings/` directory.
138
It's recommended to make your vcs to ignore database and secret files or
139
any files that have information that you don't want to be publish.
145
This charm allow you to upgrade your deployment using the Juju's
146
`upgrade-charm` command. This command will:
149
* upgrade additionnal pip packages
150
* upgrade additionnal Debian packages
151
* upgrade using requirements files in your project
153
Management with Fabric
154
----------------------
156
Fabric_ is a Python (2.5 or higher) library and command-line tool for
157
streamlining the use of SSH for application deployment or systems
158
administration tasks.
160
It provides a basic suite of operations for executing
161
local or remote shell commands (normally or via sudo) and uploading/downloading
162
files, as well as auxiliary functionality such as prompting the running user
163
for input, or aborting execution.
165
.. _Fabric: http://docs.fabfile.org
167
This charm includes a Fabric script that use Juju's information to perform various
170
For a list of tasks type this command after bootstraping your Juju environment::
174
For example, with a python-django service deployed you can run commands on all its units::
176
fab -R python-django pull
177
[10.0.0.2] Executing task 'pull'
178
[10.0.0.2] run: bzr pull lp:~my_name/django_code/my_site
180
[10.0.0.2] run: invoke-rc.d gunicorn restart
183
Or you can also run commands on a single unit::
185
fab -R python-django/0 manage:createsuperuser
187
[10.0.0.2] out: Username (leave blank to use 'ubuntu'):
192
* You can only execute task for one role at the time.
193
But it can be a service or unit.
195
If you want to extend the fabfile check out fabtools_ .
197
.. _fabtools: http://fabtools.readthedocs.org/
202
Note that if your using a *requirement.txt* file the packages will
203
be downloaded with *pip* and it doesn't do any cryptographic
204
verification of its downloads.
206
Writing application charm
207
-------------------------
209
To create an application subordinate charm that can be related to this charm you need
210
at least to define an interface named `directory-path` in your `metadate.yaml` file
216
interface: directory-path
220
When you will add a relation between your charm and the python-django charm
221
the hook you will be able to get those relation variables:
228
now your charm will be informed about where it need to add new settings
229
and urls files and how to run additionnal Django commands.
230
The Django charm reload Gunicorn after the relation to catch the changes.
239
* Rewrite the charm using python instead of BASH scripts
240
* Django projects now need no modification to work with the charm
241
* Use the `django-admin startproject` command with configurable arguments if no repos is specified
242
* Juju's generated settings and urls files are now added in a juju_settings
243
and a juju_urls directories by default
244
* New MongoDB relation (server side is yet to be done)
245
* New upgrade hook that upgrade pip and debian packages
246
* Expose ports is now handle by the charm
248
Configuration changes:
250
* default user and group is now ubuntu
251
* new install_root option
252
* new django_version option
253
* new additional_pip_packages option
254
* new repos_branch,repos_username,repos_password options
255
* new project_name, project_template_extension, project_template_url options
256
* new urls_dir_name and settings_dir_name options
257
* new project_template_url and project_template_extension options
258
* database, uploads, static, secret and cache settings locations are now configurable
259
* extra_deb_pkg was renamed additional_distro_packages
260
* requirements was renamed requirements_pip_files and now support multiple files
261
* if python_path is empty set as install_root
263
Backwards incompatible changes:
265
* swift support was moved to a subordinate charm
266
* postgresql relation hook was rename pgsql instead of db
272
* You can configure all wsgi (Gunicorn) settings via the config.yaml file
273
* Juju compatible Fabric fabfile.py is included for PAAS commands
274
* Swift storage backend is now optional
276
Backwards incompatible changes:
278
* Use splited settings and urls
279
* Permissons are now based on WSGI's user and group instead of just being www-data
280
* media and static files are now in new directories ./uploads and ./static/
281
* Deprecated configuration variables: site_domain, site_username, site_password, site_admin_email
291
* http://www.deploydjango.com
292
* http://lincolnloop.com/django-best-practices/
293
* https://github.com/30loops/djangocms-on-30loops.git
294
* https://github.com/openshift/django-example
295
* http://lincolnloop.com/blog/2013/feb/15/django-settings-parity-youre-doing-it-wrong/
296
* http://tech.yipit.com/2011/11/02/django-settings-what-to-do-about-settings-py/
297
* http://www.rdegges.com/the-perfect-django-settings-file/
298
* https://github.com/xenith/django-base-template.git
299
* https://github.com/transifex/transifex/blob/devel/transifex/settings.py
300
* http://peterlyons.com/problog/2010/02/environment-variables-considered-harmful