0

I have a git repository with two Django 1.5 projects: one for a website, the other for a REST api. The git repository looks like this:

api_project/
www_project/
logs/
manage.py
my_app_1/
my_app_2/

The manage.py file defaults to www_project.settings. To launch the api_project, I run:

DJANGO_SETTINGS_MODULE=api_project.settings ./manage.py shell

I guess I could setup 3 git repositories, one with the common apps, one for the api project and one for the www project, using git submodules and all, but it really seems overkill. Up to now, everything worked fine.

But now I'm trying to deploy this setup using Chef. I'd like to use the application and application_python cookbooks, and run my django projects with gunicorn, but these cookbooks seem to be meant to deploy only one project at a time.

Here's what my chef recipe looks like for the www_project:

application "django_app" do
    path "/var/django"
    owner "django"
    group "django"
    repository "git.example.com:blabla"
    revision "master"
    migrate true
    packages ["libevent-dev", "libpq5" , "git"]
      # libevent-dev for gevent (for gunicorn), libpq5 for postgresql
    environment "DJANGO_SETTINGS_MODULE" => "www_project.settings"
      # for syncdb and migrate

    django do
        local_settings_file "www_project/settings.py"
        settings_template "settings.py.erb"
        purge_before_symlink ["logs"]
        symlinks "logs" => "logs"
        collectstatic true
        database do
            database "blabla"
            engine "postgresql_psycopg2"
            username "django"
            password "super!password"
        end
        database_master_role "blabla_postgresql_master"
        migration_command "/var/django/shared/env/bin/python manage.py" +
           " syncdb --noinput && /var/django/shared/env/bin/python" +
           " manage.py migrate"
    end

    gunicorn do
        app_module "www_project.wsgi:application"
        preload_app true
        worker_class "egg:gunicorn#gevent"
        workers node['cpu']['total'].to_i * 2 + 1
        port 8081
        proc_name "blabla_www"
    end
end

I would just like to know how to add another gunicorn ressource for the api_project. Has anyone run into a similar problem? Would you recommend patching my local copy of the application_python cookbook to allow multiple projects in one git repo? Or should I go through the pain of setting up 3 separate git repositories? Or any other solution?

Thanks!

MiniQuark
  • 46,633
  • 36
  • 147
  • 183
  • 1
    Faced a similar scenario in the past. Though every solution in this case have its own pros and cons, what I would recommend is to have separate repositories and create a pluggable python package or django-app for common stuff. – Amyth Mar 25 '13 at 11:16
  • Ok, so you recommend the "3 git repositories" route. Oh well, I hoped I could avoid that. Thanks for your feedback. – MiniQuark Mar 25 '13 at 11:19

1 Answers1

0

You can separate your code into two separate "application" blocks, as all the resources defined inside are sub-resources and the actual execution is done at the level of "application".

Another solution would be to fork/patch the application_python providers django and gunicorn to allow more complex behaviors, for example allowing more than one application to be deployed. Although it is probably not required by so many users to merit all the effort and complexity.

Evgeny
  • 6,533
  • 5
  • 58
  • 64