Mercurial > repos > other > Puppet
comparison modules/python/README.md @ 0:956e484adc12
Initial public release of Puppet configs
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 16 Aug 2014 19:47:38 +0000 |
parents | |
children | c42fb28cff86 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:956e484adc12 |
---|---|
1 Puppet Python Module with Virtualenv, Pip and Gunicorn support | |
2 ============================================================== | |
3 | |
4 Module for configuring Python with virtualenvs and installation | |
5 of packages inside them with pip in addition to serving | |
6 Python WSGI applications including Django through Gunicorn. | |
7 | |
8 This module support installing packages specified in a | |
9 `requirements.txt` file and update said packages when the file | |
10 changes. This way you only have to define your requirements in | |
11 one place: in the VCS for your application code. | |
12 | |
13 Tested on Debian GNU/Linux 6.0 Squeeze and Ubuntu 10.4 LTS with | |
14 Puppet 2.6. Patches for other operating systems welcome. | |
15 | |
16 | |
17 TODO | |
18 ---- | |
19 | |
20 * Use /etc/gunicorn.d/ for instance configs and simplify | |
21 /etc/init.d/gunicorn. Possibly use a single gunicorn | |
22 init script like in Debian. | |
23 * Uninstallation of packages no longer provided in the | |
24 requirements file. | |
25 | |
26 | |
27 Installation | |
28 ------------ | |
29 | |
30 Clone this repo to a python directory under your Puppet | |
31 modules directory: | |
32 | |
33 git clone git://github.com/uggedal/puppet-module-python.git python | |
34 | |
35 If you don't have a Puppet Master you can create a manifest file | |
36 based on the notes below and run Puppet in stand-alone mode | |
37 providing the module directory you cloned this repo to: | |
38 | |
39 puppet apply --modulepath=modules test_python.pp | |
40 | |
41 | |
42 Usage | |
43 ----- | |
44 | |
45 To install Python with development dependencies simply include the | |
46 module: | |
47 | |
48 include python::dev | |
49 | |
50 You can install a specific version of Python by including the | |
51 module with this special syntax: | |
52 | |
53 class { "python::dev": version => "2.5" } | |
54 | |
55 Note that classes in Puppet are singletons and not more than one | |
56 can be created even if you provide different paramters to them. | |
57 This means that the `python::dev` class can only be used to install one | |
58 version. If you need more coexising versions you could create a new | |
59 class based on the current one prefixed with the actual version. | |
60 | |
61 | |
62 ### Virtualenv | |
63 | |
64 To install and configure virtualenv, include the module: | |
65 | |
66 include python::venv | |
67 | |
68 You can also provide an owner and group which will be the owner | |
69 of the virtualenv files by including the class with this special syntax: | |
70 | |
71 class { "python::venv": owner => "www-mgr", group => "www-mgr" } | |
72 | |
73 Setting up a virtualenv is done with the `python::venv::isolate` | |
74 resource: | |
75 | |
76 python::venv::isolate { "/usr/local/venv/mediaqueri.es": } | |
77 | |
78 Note that you'll need to define a global search path for the `exec` | |
79 resource to make the `python::venv::isolate` resource function | |
80 properly. This should ideally be placed in `manifests/site.pp`: | |
81 | |
82 Exec { | |
83 path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", | |
84 } | |
85 | |
86 If you have several version of Python installed you can specifiy | |
87 which interpreter you'd like the virtualenv to contain: | |
88 | |
89 python::venv::isolate { "/usr/local/venv/mediaqueri.es": | |
90 version => "2.5", | |
91 } | |
92 | |
93 If you point to a [pip requirements file][requirements.txt] Puppet will | |
94 install the specified packages and upgrade them when the file changes: | |
95 | |
96 python::venv::isolate { "/usr/local/venv/mediaqueri.es": | |
97 requirements => "/var/www/mediaqueri.es/requirements.txt", | |
98 } | |
99 | |
100 | |
101 ### Gunicorn | |
102 | |
103 To use Gunicorn for serving WSGI applications you'll first have to include | |
104 its class which manages a directory for storing pid files and unix sockets | |
105 for all your Gunicorn instances: | |
106 | |
107 include python::gunicorn | |
108 | |
109 If you don't want all your Gunicorn instances running as root you should | |
110 specify an unprivileged user when including the Gunicorn class: | |
111 | |
112 class { "python::gunicorn": owner => "www-mgr", group => "www-mgr" } | |
113 | |
114 Serving a WSGI application is done by using the following definition type | |
115 and specifying a virtualenv, the source of your application code and | |
116 the WSGI application module: | |
117 | |
118 python::gunicorn::instance { "blog": | |
119 venv => "/usr/local/venv/blog", | |
120 src => "/usr/local/src/blog", | |
121 wsgi_module => "blog:app", | |
122 } | |
123 | |
124 A Django application does not need a WSGI application module argument: | |
125 | |
126 python::gunicorn::instance { "cms": | |
127 venv => "/usr/local/venv/cms", | |
128 src => "/usr/local/src/cms", | |
129 django => true, | |
130 } | |
131 | |
132 You can optionally provide a specific settings file to use with Django: | |
133 | |
134 python::gunicorn::instance { "cms": | |
135 venv => "/usr/local/venv/cms", | |
136 src => "/usr/local/src/cms", | |
137 django => true, | |
138 django_settings => "settings_production.py", | |
139 } | |
140 | |
141 The gunicorn instance resource installs the latest gunicorn into the | |
142 virtualenv the first time it's created. If you need a specific version | |
143 simply provide a version argument: | |
144 | |
145 python::gunicorn::instance { "cms": | |
146 venv => "/usr/local/venv/cms", | |
147 src => "/usr/local/src/cms", | |
148 django => true, | |
149 version => "0.12.1", | |
150 } | |
151 | |
152 [requirements.txt]: http://www.pip-installer.org/en/latest/requirement-format.html |