Skip to content

Commit

Permalink
More working with pip and virtualenv.
Browse files Browse the repository at this point in the history
  • Loading branch information
djm committed Jul 6, 2011
1 parent 0027cb8 commit ebcfa11
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 44 deletions.
3 changes: 3 additions & 0 deletions modules/deployment/manifests/development/setup.pp
@@ -0,0 +1,3 @@
define deployment::development::setup ($project_path="") {

}
3 changes: 3 additions & 0 deletions modules/deployment/manifests/production/setup.pp
@@ -0,0 +1,3 @@
define deployment::production::setup ($project_path="") {

}
33 changes: 19 additions & 14 deletions modules/djangoapp/manifests/instance.pp
Expand Up @@ -29,8 +29,8 @@
$static_path = "${project_path}current/${python_dir_name}/static/"
$media_path = "${project_path}attachments/"

$venv_path = "${project_path}venv/"
$src_path = "${project_path}src/"
$venv_path = "${project_path}venv"
$src_path = "${project_path}src"

# Create client and project paths if they
# do not currently exist.
Expand Down Expand Up @@ -71,11 +71,12 @@
}

# Create a virtualenv and run the requirements file.
python2::venv::setup { $venv:
requirements => $requirements ? {
true => "$src/requirements.pip",
default => undef,
}
python2::venv::setup { $venv_path:
requirements => $requirements ? {
true => "$src_path/requirements.pip",
default => undef,
},
require => Exec["source-checkout"],
}

# Create the site specific nginx conf.
Expand Down Expand Up @@ -104,11 +105,15 @@
db_pass => $full_project_name,
}

# Here we split depending on if this is a Vagrant
# machine or our actual staging/production.
if ( $id == 'vagrant' ) {
deployment::development::setup { $full_project_name: }
} else {
deployment::production::setup { $full_project_name: }
# Here we split depending on if this is a Vagrant
# machine or our actual staging/production.
if ( $id == 'vagrant' ) {
deployment::development::setup { $full_project_name:
project_path => $project_path,
}
} else {
deployment::production::setup { $full_project_name:
project_path => $project_path,
}
}
}
}
2 changes: 1 addition & 1 deletion modules/nginx/templates/project.conf.erb
@@ -1,7 +1,7 @@
server {

listen 80;
server_name <%= production_domain'] %> *.<%= production_domain %> <%= staging_domain %>;
server_name <%= production_domain %> *.<%= production_domain %> <%= staging_domain %>;

# Set proxy headers for the passthrough
proxy_set_header Host $host;
Expand Down
30 changes: 30 additions & 0 deletions modules/python2/manifests/pip/requirements.pp
@@ -0,0 +1,30 @@
# Adapted from https://github.com/uggedal/puppet-module-python
# Thanks to Eivind Uggedal.
define python2::pip::requirements($venv, $owner=undef, $group=undef) {
$requirements = $name
$checksum = "$venv/requirements.checksum"

file { $requirements:
ensure => present,
replace => false,
owner => $owner,
group => $group,
}

# We create a sha1 checksum of the requirements file so that
# we can detect when it changes:
exec { "create new checksum of $name requirements":
command => "sha1sum $requirements > $checksum",
unless => "sha1sum -c $checksum",
path => "/usr/local/bin:/usr/bin:/bin",
require => File[$requirements],
}

exec { "update $name requirements":
command => "$venv/bin/pip install -Ur $requirements",
cwd => $venv,
subscribe => Exec["create new checksum of $name requirements"],
refreshonly => true,
}
}

46 changes: 17 additions & 29 deletions modules/python2/manifests/venv/setup.pp
Expand Up @@ -4,47 +4,35 @@
define python2::venv::setup($requirements=undef) {

$venv_path = $name
$owner = $python::venv::owner
$group = $python::venv::group

# Does not successfully run as www-data on Debian:
exec { "python::venv $venv_path":
command => "virtualenv -p `which ${python}` ${venv_path}",
creates => $root,
# Does not successfully run as deployer for some reason.
exec { "python2::venv $venv_path":
command => "virtualenv ${venv_path}",
creates => $venv_path,
path => "/usr/local/bin:/usr/bin:/bin",
notify => Exec["update distribute and pip in $venv_path"],
require => [Package["python-dev"]],
}

# Change ownership of the venv after its created with the default user:
exec { "python::venv $root chown":
command => "chown -R $owner:$group $root",
onlyif => "find $root ! (-user $owner -group $group)",
require => Exec["python::venv $root"],
# Change ownership of the venv after its created.
exec { "python2::venv $venv_path chown":
command => "chown -R deployer:www-data $venv_path",
onlyif => "find $venv_path ! (-user deployer -group www-data)",
path => "/usr/local/bin:/usr/bin:/bin",
require => Exec["python2::venv $venv_path"],
}

# Some newer Python packages require an updated distribute
# from the one that is in repos on most systems:
exec { "update distribute and pip in $root":
command => "$root/bin/pip install -U distribute pip",
exec { "update distribute and pip in $venv_path":
command => "$venv_path/bin/pip install -U distribute pip",
refreshonly => true,
}

if $requirements {
python::pip::requirements { $requirements:
venv => $root,
owner => $owner,
group => $group,
}
}

} elsif $ensure == 'absent' {

file { $root:
ensure => $ensure,
owner => $owner,
group => $group,
recurse => true,
purge => true,
force => true,
python2::pip::requirements { $requirements:
venv => $venv_path,
require => Exec["python2::venv $venv_path"],
}
}
}

0 comments on commit ebcfa11

Please sign in to comment.