Skip to content

Commit 86a980d

Browse files
author
Andrea Campi
committed
Initial documentation for the application_python cookbook.
1 parent 7750f22 commit 86a980d

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

README.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
Description
2+
===========
3+
4+
This cookbook is designed to be able to describe and deploy Python web applications. Currently supported:
5+
6+
* plain python web applications
7+
* Django
8+
* Green Unicorn
9+
* Celery
10+
11+
Note that this cookbook provides the Python-specific bindings for the `application` cookbook; you will find general documentation in that cookbook.
12+
13+
Other application stacks may be supported at a later date.
14+
15+
Requirements
16+
============
17+
18+
Chef 0.10.0 or higher required (for Chef environment use).
19+
20+
The following Opscode cookbooks are dependencies:
21+
22+
* application
23+
* python
24+
* gunicorn
25+
* supervisor
26+
27+
Resources/Providers
28+
==========
29+
30+
The LWRPs provided by this cookbook are not meant to be used by themselves; make sure you are familiar with the `application` cookbook before proceeding.
31+
32+
django
33+
------
34+
35+
The `django` sub-resource LWRP deals with deploying Django webapps from an SCM repository. It uses the `deploy_revision` LWRP to perform the bulk of its tasks, and many concepts and parameters map directly to it. Check the documentation for `deploy_revision` for more information.
36+
37+
A new virtualenv will be created for the application in "#{path}/shared/env"; pip package will be installed in that virtualenv.
38+
39+
# Attribute Parameters
40+
41+
- packages: an Array of pip packages to install
42+
- requirements: the relative path to a requirements file. If not specified the provider will look for one in the project root, named either "requirements/#{chef_environment}.txt" or "requirements.txt"
43+
- database\_master\_role: if a role name is provided, a Chef search will be run to find a node with than role in the same environment as the current role. If a node is found, its IP address will be used when rendering the context file, but see the "Database block parameters" section below
44+
- local\_settings\_file: the name of the local settings file to be generated by template. Defaults to "local_settings.py"
45+
- settings\_template: the name of template that will be rendered to create the local settings file; if specified it will be looked up in the application cookbook. Defaults to "settings.py.erb" from this cookbook
46+
- settings: a Hash of additional settings that will be made available to the template
47+
- database: a block containing additional parameters for configuring the database connection
48+
- legacy\_database\_settings: if true, the default settings template will generate legacy database config variables. Defaults to false
49+
- debug: used by the default settings template to control debugging. Defaults to false
50+
- collectstatic: controls the behavior of the `staticfiles` app. If true, if will invoke manage.py with `collectstatic --noinput`; you can also pass a String with an explicit command (see Usage below). Defaults to false
51+
52+
# Database block parameters
53+
54+
The database block can accept any method, which will result in an entry being created in the `@database` Hash which is passed to the context template. See Usage below for more information.
55+
56+
gunicorn
57+
--------
58+
59+
The `gunicorn` sub-resource LWRP configures Green Unicorn to run the application.
60+
61+
If used with a Django application, it will install gunicorn into the same virtualenv and run it with `manage.py run_gunicorn`. For other applications, gunicorn will be run with `gunicorn #{app_module}`.
62+
63+
# Attribute Parameters
64+
65+
- app_module: mandatory. If set to :django, gunicorn will be configured to run a Django application; if set to another String or Symbol, it will be used to build the gunicorn base command.
66+
- settings\_template: the template to render to create the `gunicorn_config.py` file; if specified it will be looked up in the application cookbook. Defaults to "se.py.erb" from the `gunicorn` cookbook
67+
- host: passed to the `gunicorn_config` LWRP
68+
- port: passed to the `gunicorn_config` LWRP
69+
- backlog: passed to the `gunicorn_config` LWRP
70+
- workers: passed to the `gunicorn_config` LWRP
71+
- worker_class: passed to the `gunicorn_config` LWRP
72+
- worker_connections: passed to the `gunicorn_config` LWRP
73+
- max_requests: passed to the `gunicorn_config` LWRP
74+
- timeout: passed to the `gunicorn_config` LWRP
75+
- keepalive: passed to the `gunicorn_config` LWRP
76+
- debug: passed to the `gunicorn_config` LWRP
77+
- trace: passed to the `gunicorn_config` LWRP
78+
- preload_app: passed to the `gunicorn_config` LWRP
79+
- daemon: passed to the `gunicorn_config` LWRP
80+
- pidfile: passed to the `gunicorn_config` LWRP
81+
- umask: passed to the `gunicorn_config` LWRP
82+
- logfile: passed to the `gunicorn_config` LWRP
83+
- loglevel: passed to the `gunicorn_config` LWRP
84+
- proc_name: passed to the `gunicorn_config` LWRP
85+
86+
Usage
87+
=====
88+
89+
A sample application that needs a database connection:
90+
91+
application "packaginator" do
92+
path "/srv/packaginator"
93+
owner "nobody"
94+
group "nogroup"
95+
repository "https://github.com/coderanger/packaginator.git"
96+
revision "master"
97+
migrate true
98+
packages ["libpq-dev", "git-core", "mercurial"]
99+
100+
django do
101+
packages ["redis"]
102+
requirements "requirements/mkii.txt"
103+
settings_template "settings.py.erb"
104+
debug true
105+
collectstatic "build_static --noinput"
106+
database do
107+
database "packaginator"
108+
engine "postgresql_psycopg2"
109+
username "packaginator"
110+
password "awesome_password"
111+
end
112+
database_master_role "packaginator_database_master"
113+
end
114+
end
115+
116+
You can invoke any method on the database block:
117+
118+
application "my-app" do
119+
path "/srv/packaginator"
120+
repository "..."
121+
revision "..."
122+
123+
django do
124+
database_master_role "packaginator_database_master"
125+
database do
126+
database 'name'
127+
quorum 2
128+
replicas %w[Huey Dewey Louie]
129+
end
130+
end
131+
end
132+
133+
The corresponding entries will be passed to the context template:
134+
135+
<%= @database['quorum']
136+
<%= @database['replicas'].join(',') %>
137+
138+
License and Author
139+
==================
140+
141+
Author:: Adam Jacob (<adam@opscode.com>)
142+
Author:: Andrea Campi (<andrea.campi@zephirworks.com.com>)
143+
Author:: Joshua Timberman (<joshua@opscode.com>)
144+
Author:: Noah Kantrowitz (<noah@coderanger.net>)
145+
Author:: Seth Chisamore (<schisamo@opscode.com>)
146+
147+
Copyright 2009-2012, Opscode, Inc.
148+
149+
Licensed under the Apache License, Version 2.0 (the "License");
150+
you may not use this file except in compliance with the License.
151+
You may obtain a copy of the License at
152+
153+
http://www.apache.org/licenses/LICENSE-2.0
154+
155+
Unless required by applicable law or agreed to in writing, software
156+
distributed under the License is distributed on an "AS IS" BASIS,
157+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
158+
See the License for the specific language governing permissions and
159+
limitations under the License.

0 commit comments

Comments
 (0)