Home

Awesome

Application_Python Cookbook

Build Status Gem Version Cookbook Version Coverage Gemnasium License

A Chef cookbook to deploy Python applications.

Quick Start

To deploy a Django application from git:

application '/srv/myapp' do
  git 'https://github.com/example/myapp.git'
  virtualenv
  pip_requirements
  django do
    database 'sqlite:///test_django.db'
    secret_key 'd78fe08df56c9'
    migrate true
  end
  gunicorn do
    port 8000
  end
end

Requirements

Chef 12.1 or newer is required.

Resources

application_celery_beat

The application_celery_beat resource creates a service for the celery beat process.

application '/srv/myapp' do
  celery_beat do
    app_module 'myapp.tasks'
  end
end

Actions

Properties

user – User to run the service as. (default: application owner)

application_celery_config

The application_celery_config creates a celeryconfig.py configuration file.

application '/srv/myapp' do
  celery_config do
    options do
      broker_url 'amqp://'
    end
  end
end

Actions

Properties

application_celery_worker

The application_celery_worker resource creates a service for the celery worker process.

application '/srv/myapp' do
  celery_worker do
    app_module 'myapp.tasks'
  end
end

Actions

Properties

user – User to run the service as. (default: application owner)

application_django

The application_django resource creates configuration files and runs commands for a Django application deployment.

application '/srv/myapp' do
  django do
    database 'sqlite:///test_django.db'
    migrate true
  end
end

Actions

Properties

Database Parameters

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:

django do
  database 'postgres://myuser@dbhost/myapp'
end

Passing 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:

django do
  database do
    engine 'postgres'
    user 'myuser'
    host 'dbhost'
    name 'myapp'
  end
end

django do
  database({
    engine: 'postgres',
    user: 'myuser',
    host: 'dbhost',
    name: 'myapp',
  })
end

application_gunicorn

The application_gunicorn resource creates a service for the Gunicorn application server.

application '/srv/myapp' do
  gunicorn do
    port 8000
    preload_app true
  end
end

Actions

Properties

application_pip_requirements

The application_pip_requirements resource installs Python packages based on a requirements.txt file.

application '/srv/myapp' do
  pip_requirements
end

All actions and properties are the same as the pip_requirements resource.

application_python

The application_python resource installs a Python runtime for the deployment.

application '/srv/myapp' do
  python '2.7'
end

All actions and properties are the same as the python_runtime resource.

application_python_execute

The application_python_execute resource runs Python commands for the deployment.

application '/srv/myapp' do
  python_execute 'setup.py install'
end

All 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.

application_python_package

The application_python_package resource installs Python packages for the deployment.

application '/srv/myapp' do
  python_package 'requests'
end

All 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.

application_virtualenv

The application_virtualenv resource creates a Python virtualenv for the deployment.

application '/srv/myapp' do
  virtualenv
end

If 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.

Examples

Some test recipes are available as examples for common application frameworks:

Sponsors

Development sponsored by Chef Software, Symonds & Son, and Orion.

The Poise test server infrastructure is sponsored by Rackspace.

License

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.