Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Add support for virtualenv and pip
Browse files Browse the repository at this point in the history
Change-Id: I09647b254f6d7c17bbbbba6351c5e9abe0081bbd
  • Loading branch information
garethr authored and Patrick Bozeman committed Aug 12, 2011
1 parent b09383d commit f8791f8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cloud_controller/staging/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
require File.expand_path('../gemfile_task', __FILE__)
require File.expand_path('../gem_cache', __FILE__)

require File.expand_path('../virtualenv_support', __FILE__)
require File.expand_path('../pip_support', __FILE__)

# TODO - Separate the common staging helper methods from the 'StagingPlugin' base class, for more clarity.
# Staging plugins (at least the ones written in Ruby) are expected to subclass this. See ruby/sinatra for a simple example.
Expand Down
13 changes: 13 additions & 0 deletions cloud_controller/staging/pip_support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module PipSupport

REQUIREMENTS_FILE = 'requirements.txt'

def uses_pip?
File.exists?(File.join(source_directory, REQUIREMENTS_FILE))
end

def install_requirements
"../env/bin/pip install -r #{REQUIREMENTS_FILE}"
end

end
10 changes: 10 additions & 0 deletions cloud_controller/staging/virtualenv_support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module VirtualenvSupport

def setup_virtualenv
cmds = []
cmds << "virtualenv --no-site-packages env"
cmds << "env/bin/pip install gunicorn"
cmds.join("\n")
end

end
14 changes: 12 additions & 2 deletions cloud_controller/staging/wsgi/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class WsgiPlugin < StagingPlugin
include VirtualenvSupport
include PipSupport

def framework
'wsgi'
end
Expand All @@ -13,13 +16,20 @@ def stage_application
end

def start_command
"gunicorn -c ../gunicorn.config app:app"
cmds = []
if uses_pip?
cmds << install_requirements
end
cmds << "../env/bin/gunicorn -c ../gunicorn.config app:app"
cmds.join("\n")
end

private
def startup_script
vars = environment_hash
generate_startup_script(vars)
generate_startup_script(vars) do
setup_virtualenv
end
end

def create_gunicorn_config
Expand Down

0 comments on commit f8791f8

Please sign in to comment.