A Chef cookbook to deploy Python applications.
To deploy a Django application from git:
application'/srv/myapp'dogit'https://github.com/example/myapp.git'virtualenvpip_requirementsdjangododatabase'sqlite:///test_django.db'secret_key'd78fe08df56c9'migratetrueendgunicorndoport8000endendChef 12.1 or newer is required.
The application_celery_beat resource creates a service for the celery beat process.
application'/srv/myapp'docelery_beatdoapp_module'myapp.tasks'endend:enable– Create, enable and start the service. (default):disable– Stop, disable, and destroy the service.:start– Start the service.:stop– Stop the service.:restart– Stop and then start the service.:reload– Send the configured reload signal to the service.
path– Base path for the application. (name attribute)app_module– Celery application module. (default: auto-detect)service_name– Name of the service to create. (default: auto-detect)
The application_celery_config creates a celeryconfig.py configuration file.
application'/srv/myapp'docelery_configdooptionsdobroker_url'amqp://'endendend:deploy– Create the configuration file. (default)
path– Path to write the configuration file to. If given as a directory, createpath/celeryconfig.py. (name attribute)options– Hash or block of options to set in the configuration file.
The application_celery_worker resource creates a service for the celery worker process.
application'/srv/myapp'docelery_workerdoapp_module'myapp.tasks'endend:enable– Create, enable and start the service. (default):disable– Stop, disable, and destroy the service.:start– Start the service.:stop– Stop the service.:restart– Stop and then start the service.:reload– Send the configured reload signal to the service.
path– Base path for the application. (name attribute)app_module– Celery application module. (default: auto-detect)worker_pool– The Pool implementation used by the Celery worker (gevent,eventlet or prefork). (default: prefork)service_name– Name of the service to create. (default: auto-detect)
The application_django resource creates configuration files and runs commands for a Django application deployment.
application'/srv/myapp'dodjangododatabase'sqlite:///test_django.db'migratetrueendend:deploy– Create config files and run required deployments steps. (default)
path– Base path for the application. (name attribute)allowed_hosts– Value forALLOWED_HOSTSin the Django settings. (default: [])collectstatic– Runmanage.py collectstaticduring deployment. (default: true)database– Database settings for the default connection. See the database section below for more information. (option collector)debug– Enable debug mode for Django. (default: false)local_settings– A Poise template property for the content of the local settings configuration file.local_settings_path– Path to write local settings to. If given as a relative path, will be expanded against path. Set to false to disable writing local settings. (default: local_settings.py next to settings_module)migrate– Runmanage.py migrateduring deployment. (default: false)manage_path– Path tomanage.py. (default: auto-detect)secret_key– Value forSECRET_KEYin the Django settings. If unset, no key is added to the local settings.settings_module– Django settings module in dotted notation. (default: auto-detect)syncdb– Runmanage.py syncdbduring deployment. (default: false)wsgi_module– WSGI application module in dotted notation. (default: auto-detect)
The database parameters can be set in three ways: URL, hash, and block.
If you have a single URL for the parameters, you can pass it directly to database:
djangododatabase'postgres://myuser@dbhost/myapp'endPassing a single URL will also set the $DATABASE_URL environment variable automatically for compatibility with Heroku-based applications.
As with other option collector resources, you can pass individual settings as either a hash or block:
djangododatabasedoengine'postgres'user'myuser'host'dbhost'name'myapp'endenddjangododatabase({engine: 'postgres',user: 'myuser',host: 'dbhost',name: 'myapp',})endThe application_gunicorn resource creates a service for the Gunicorn application server.
application'/srv/myapp'dogunicorndoport8000preload_apptrueendend:enable– Create, enable and start the service. (default):disable– Stop, disable, and destroy the service.:start– Start the service.:stop– Stop the service.:restart– Stop and then start the service.:reload– Send the configured reload signal to the service.
path– Base path for the application. (name attribute)app_module– WSGI module to run as an application. (default: auto-detect)bind– One or more addresses/ports to bind to.config– Path to a Guncorn configuration file.preload_app– Enable code preloading. (default: false)port– Port to listen on. Alias forbind("0.0.0.0:#{port}").service_name– Name of the service to create. (default: auto-detect)user– User to run the service as. (default: application owner)version– Version of Gunicorn to install. If set to true, use the latest version. If set to false, do not install Gunicorn. (default: true)
The application_pip_requirements resource installs Python packages based on a requirements.txt file.
application'/srv/myapp'dopip_requirementsendAll actions and properties are the same as the pip_requirements resource.
The application_python resource installs a Python runtime for the deployment.
application'/srv/myapp'dopython'2.7'endAll actions and properties are the same as the python_runtime resource.
The application_python_execute resource runs Python commands for the deployment.
application'/srv/myapp'dopython_execute'setup.py install'endAll actions and properties are the same as the python_execute resource, except that the cwd, environment, group, and user properties default to the application-level data if not specified.
The application_python_package resource installs Python packages for the deployment.
application'/srv/myapp'dopython_package'requests'endAll actions and properties are the same as the python_package resource, except that the group and user properties default to the application-level data if not specified.
The application_virtualenv resource creates a Python virtualenv for the deployment.
application'/srv/myapp'dovirtualenvendIf no path property is given, the default is to create a .env/ inside the application deployment path.
All actions and properties are the same as the python_virtualenv resource.
Some test recipes are available as examples for common application frameworks:
Development sponsored by Chef Software, Symonds & Son, and Orion.
The Poise test server infrastructure is sponsored by Rackspace.
Copyright 2015-2017, Noah Kantrowitz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.