From d9d101b22467925ea8f333d9e29799899eaf3ff5 Mon Sep 17 00:00:00 2001 From: Chance Zibolski Date: Tue, 20 Aug 2013 14:02:30 -0700 Subject: [PATCH 1/3] Replace instances of manage.py with new manage_file attribute. Useful for Django 1.4 and newer projects where the manage.py file is not in the root of the project by default. --- README.md | 1 + providers/celery.rb | 2 +- providers/django.rb | 4 ++-- providers/gunicorn.rb | 2 +- resources/django.rb | 1 + 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 90084ad..aa0c03b 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ A new virtualenv will be created for the application in "#{path}/shared/env"; pi - local\_settings\_file: the name of the local settings file to be generated by template. Defaults to "local_settings.py" - 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 - settings: a Hash of additional settings that will be made available to the template +- manage\_file: the location of the manage.py file. Defaults to "manage.py" in the root of the project. - database: a block containing additional parameters for configuring the database connection - legacy\_database\_settings: if true, the default settings template will generate legacy database config variables. Defaults to false - debug: used by the default settings template to control debugging. Defaults to false diff --git a/providers/celery.rb b/providers/celery.rb index f33b3d5..e183d63 100644 --- a/providers/celery.rb +++ b/providers/celery.rb @@ -91,7 +91,7 @@ if new_resource.django django_resource = new_resource.application.sub_resources.select{|res| res.type == :django}.first raise "No Django deployment resource found" unless django_resource - command "#{::File.join(django_resource.virtualenv, "bin", "python")} manage.py #{cmd}" + command "#{::File.join(django_resource.virtualenv, "bin", "python")} #{django_resource.manage_file} #{cmd}" environment new_resource.environment else command cmd diff --git a/providers/django.rb b/providers/django.rb index bf66e59..bf7c2bf 100644 --- a/providers/django.rb +++ b/providers/django.rb @@ -26,7 +26,7 @@ include_recipe 'python' - new_resource.migration_command "#{::File.join(new_resource.virtualenv, "bin", "python")} manage.py syncdb --noinput" if !new_resource.migration_command + new_resource.migration_command "#{::File.join(new_resource.virtualenv, "bin", "python")} #{new_resource.manage_file} syncdb --noinput" if !new_resource.migration_command new_resource.symlink_before_migrate.update({ new_resource.local_settings_base => new_resource.local_settings_file, @@ -82,7 +82,7 @@ if new_resource.collectstatic cmd = new_resource.collectstatic.is_a?(String) ? new_resource.collectstatic : "collectstatic --noinput" - execute "#{::File.join(new_resource.virtualenv, "bin", "python")} manage.py #{cmd}" do + execute "#{::File.join(new_resource.virtualenv, "bin", "python")} #{new_resource.manage_file} #{cmd}" do user new_resource.owner group new_resource.group cwd new_resource.release_path diff --git a/providers/gunicorn.rb b/providers/gunicorn.rb index 3668cdf..b5d1448 100644 --- a/providers/gunicorn.rb +++ b/providers/gunicorn.rb @@ -78,7 +78,7 @@ if new_resource.app_module == :django django_resource = new_resource.application.sub_resources.select{|res| res.type == :django}.first raise "No Django deployment resource found" unless django_resource - base_command = "#{::File.join(django_resource.virtualenv, "bin", "python")} manage.py run_gunicorn" + base_command = "#{::File.join(django_resource.virtualenv, "bin", "python")} #{django_resource.manage_file} run_gunicorn" else gunicorn_command = new_resource.virtualenv.nil? ? "gunicorn" : "#{::File.join(new_resource.virtualenv, "bin", "gunicorn")}" base_command = "#{gunicorn_command} #{new_resource.app_module}" diff --git a/resources/django.rb b/resources/django.rb index 5c5e601..5bc3c94 100644 --- a/resources/django.rb +++ b/resources/django.rb @@ -28,6 +28,7 @@ # Actually defaults to "settings.py.erb", but nil means it wasn't set by the user attribute :settings_template, :kind_of => [String, NilClass], :default => nil attribute :local_settings_file, :kind_of => String, :default => 'local_settings.py' +attribute :manage_file, :kind_of => String, :default => 'manage.py' attribute :debug, :kind_of => [TrueClass, FalseClass], :default => false attribute :collectstatic, :kind_of => [TrueClass, FalseClass, String], :default => false From d21eb2d3acbf8d69fa2949ed4f04b9d217683a29 Mon Sep 17 00:00:00 2001 From: Chance Zibolski Date: Wed, 21 Aug 2013 14:34:43 -0700 Subject: [PATCH 2/3] Check for django virtualenv if available --- providers/gunicorn.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/providers/gunicorn.rb b/providers/gunicorn.rb index b5d1448..5f10815 100644 --- a/providers/gunicorn.rb +++ b/providers/gunicorn.rb @@ -75,12 +75,19 @@ if new_resource.environment environment new_resource.environment end + django_resource = new_resource.application.sub_resources.select{|res| res.type == :django}.first if new_resource.app_module == :django - django_resource = new_resource.application.sub_resources.select{|res| res.type == :django}.first raise "No Django deployment resource found" unless django_resource base_command = "#{::File.join(django_resource.virtualenv, "bin", "python")} #{django_resource.manage_file} run_gunicorn" else - gunicorn_command = new_resource.virtualenv.nil? ? "gunicorn" : "#{::File.join(new_resource.virtualenv, "bin", "gunicorn")}" + # Check for a gunicorn virtualenv, fall back to django virtualenv if there + virtualenv = new_resource.virtualenv || django_resource.virtualenv if django_resource + gunicorn_command = + if virtualenv + "#{::File.join(virtualenv, "bin", "gunicorn")}" + else + "gunicorn" + end base_command = "#{gunicorn_command} #{new_resource.app_module}" end command "#{base_command} -c #{new_resource.application.path}/shared/gunicorn_config.py" From 9794e062c413576966b521d4d758c23d81bd19a7 Mon Sep 17 00:00:00 2001 From: Chance Zibolski Date: Thu, 22 Aug 2013 16:47:55 -0700 Subject: [PATCH 3/3] Better virtualenv check --- providers/gunicorn.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/gunicorn.rb b/providers/gunicorn.rb index 5f10815..311b56d 100644 --- a/providers/gunicorn.rb +++ b/providers/gunicorn.rb @@ -80,8 +80,8 @@ raise "No Django deployment resource found" unless django_resource base_command = "#{::File.join(django_resource.virtualenv, "bin", "python")} #{django_resource.manage_file} run_gunicorn" else - # Check for a gunicorn virtualenv, fall back to django virtualenv if there - virtualenv = new_resource.virtualenv || django_resource.virtualenv if django_resource + # Check for a django virtualenv, install there or into gunicorn venv + virtualenv = django_resource ? django_resource.virtualenv : new_resource.virtualenv gunicorn_command = if virtualenv "#{::File.join(virtualenv, "bin", "gunicorn")}"