My first Chef definition: create a virtualenv. Be nice.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An example of the below | |
virtualenv "/home/dvcsmirrors/hg" do | |
owner "root" | |
group "dvcsmirrors" | |
mode 0775 | |
packages "Mercurial" => "1.6.3", | |
"hgsubversion" => "1.1.2" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Definition to create virtualenvs | |
# | |
# For example:: | |
# | |
# virtualenv "/home/me/myenv" do | |
# packages "Django" => "1.2.3" | |
# end | |
# | |
# This would create a new virtualenv in /home/me/myenv and install | |
# Django 1.2.3. "packages" is a hash, so you can include multiple | |
# packages there. Right now there's nothing to say "latest version" | |
# because I don't know Ruby that well! | |
# | |
# The definition also accepts path, owner, group, and mode arguments, just | |
# like the directory resource. | |
# | |
# TODO: support a requirements file. | |
# | |
define :virtualenv, :action => :create, :owner => "root", :group => "root", :mode => 0755, :packages => {} do | |
path = params[:path] ? params[:path] : params[:name] | |
if params[:action] == :create | |
# Manage the directory. | |
directory path do | |
owner params[:owner] | |
group params[:group] | |
mode params[:mode] | |
end | |
execute "create-virtualenv-#{path}" do | |
command "virtualenv #{path}" | |
not_if "test -f #{path}/bin/python" | |
end | |
params[:packages].each_pair do |package, version| | |
pip = "#{path}/bin/pip" | |
execute "install-#{package}-#{path}" do | |
command "#{pip} install #{package}==#{version}" | |
not_if "[ `#{pip} freeze | grep #{package} | cut -d'=' -f3` = '#{version}' ]" | |
end | |
end | |
elsif params[:action] == :delete | |
directory path do | |
action :delete | |
recursive true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice!