From 2a34032270bc3424593113527a6b9673573c06c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Primoz=CC=8C=20Verdnik?= Date: Fri, 20 Dec 2013 16:29:36 +0100 Subject: [PATCH] This fixes a missing directory issue when creating a virtual environment, as well as permission issues when installing pip packages --- providers/django.rb | 6 ++++++ providers/gunicorn.rb | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/providers/django.rb b/providers/django.rb index 0a58936..c785223 100644 --- a/providers/django.rb +++ b/providers/django.rb @@ -26,6 +26,12 @@ include_recipe 'python' + directory "#{new_resource.application.path}/shared" do + owner new_resource.owner + group new_resource.group + action :create + end + new_resource.migration_command "#{::File.join(new_resource.virtualenv, "bin", "python")} manage.py syncdb --noinput" if !new_resource.migration_command new_resource.symlink_before_migrate.update({ diff --git a/providers/gunicorn.rb b/providers/gunicorn.rb index fa03dcd..9edb04f 100644 --- a/providers/gunicorn.rb +++ b/providers/gunicorn.rb @@ -24,6 +24,13 @@ action :before_compile do + log "#{new_resource.virtualenv}" + directory "#{new_resource.application.path}/shared" do + owner new_resource.owner + group new_resource.group + action :create + end + include_recipe "supervisor" install_packages @@ -48,6 +55,10 @@ new_resource = @new_resource + django_resource = new_resource.application.sub_resources.select{|res| res.type == :django}.first + + virtualenv = django_resource ? django_resource.virtualenv : new_resource.virtualenv + gunicorn_config "#{new_resource.application.path}/shared/gunicorn_config.py" do action :create template new_resource.settings_template || 'gunicorn.py.erb' @@ -81,7 +92,7 @@ raise "No Django deployment resource found" unless django_resource base_command = "#{::File.join(django_resource.virtualenv, "bin", "python")} manage.py run_gunicorn" else - gunicorn_command = new_resource.virtualenv.nil? ? "gunicorn" : "#{::File.join(new_resource.virtualenv, "bin", "gunicorn")}" + gunicorn_command = virtualenv.nil? ? "gunicorn" : "#{::File.join(virtualenv, "bin", "gunicorn")}" base_command = "#{gunicorn_command} #{new_resource.app_module}" end command "#{base_command} -c #{new_resource.application.path}/shared/gunicorn_config.py" @@ -108,16 +119,33 @@ protected def install_packages + django_resource = new_resource.application.sub_resources.select{|res| res.type == :django}.first + + virtualenv = django_resource ? django_resource.virtualenv : new_resource.virtualenv + + python_virtualenv virtualenv do + path virtualenv + owner new_resource.owner + group new_resource.group + action :create + end + new_resource.packages.each do |name, ver| python_pip name do version ver if ver && ver.length > 0 - virtualenv new_resource.virtualenv + virtualenv virtualenv + user new_resource.owner + group new_resource.group action :install end end end def install_requirements + django_resource = new_resource.application.sub_resources.select{|res| res.type == :django}.first + + virtualenv = django_resource ? django_resource.virtualenv : new_resource.virtualenv + if new_resource.requirements.nil? # look for requirements.txt files in common locations [ @@ -133,13 +161,15 @@ def install_requirements if new_resource.requirements Chef::Log.info("Installing using requirements file: #{new_resource.requirements}") # TODO normalise with python/providers/pip.rb 's pip_cmd - if new_resource.virtualenv.nil? + if virtualenv.nil? pip_cmd = 'pip' else - pip_cmd = ::File.join(new_resource.virtualenv, 'bin', 'pip') + pip_cmd = ::File.join(virtualenv, 'bin', 'pip') end execute "#{pip_cmd} install --src=#{Dir.tmpdir} -r #{new_resource.requirements}" do cwd new_resource.release_path + user new_resource.owner + group new_resource.group end else Chef::Log.debug("No requirements file found")