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

Commit

Permalink
Install to Python virtualenv
Browse files Browse the repository at this point in the history
Install Graphite, Carbon, Whisper, and (nearly) all dependencies into a
virtualenv using the `stankevich/python` module. This retains the same
sandboxing that `--install-option`/`--prefix` was doing, but with the added
benefit of:

- Allowing the version param to upgrade and downgrade the packages without
  writing the `pip` logic ourselves.
- Isolating dependencies from the system's Python/pip paths.

Absolute binary paths are used to reference the virtualenv without needing
to `source bin/activate` each time. Cairo is shimmed into the virtualenv
from the system package because of the reasons described in the class doc.
I've rebased the dependencies against Graphite's `requirements.txt` to
reference specific versions and dropped:

- LDAP support: because it has compile dependencies and I'm not aware of
  anyone currently using this functionality from the module.
- pysqlite2: because Python >=2.6 has this builtin.

I'm using an earlier version of the `python` module because of the following
bug which causes the virtualenv to be recreated on every run:

- voxpupuli/puppet-python#46

Tests will be committed separately because they depend on refactoring
currently in unmerged PR #16.
  • Loading branch information
dcarley committed Jan 3, 2014
1 parent 1a60469 commit 778da32
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 50 deletions.
2 changes: 2 additions & 0 deletions Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ license 'MIT'
summary 'Module to manage the Graphite monitoring tool'
source 'https://github.com/gds-operations/puppet-graphite'
project_page 'https://github.com/gds-operations/puppet-graphite'

dependency 'puppetlabs/stdlib', '>= 2.5.0'
dependency 'stankevich/python', '>= 1.2.0'
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@ Status](https://secure.travis-ci.org/gds-operations/puppet-graphite.png)](http:/

# Usage

Nice and simple, mainly because it's not yet very configurable.
You will need Python, Python's development headers/libs, pip and virtualenv
installed. If you're not already managing these you can use the `python`
module, which is included as a dependency:

include graphite
```puppet
class { 'python':
pip => true,
dev => true,
virtualenv => true,
}
```

Then for the simplest possible configuration:

```puppet
include graphite
```

## Configuration

Expand Down
12 changes: 11 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ DEBIAN_FRONTEND=noninteractive apt-get -qy update
if [ ! -e /etc/puppet/modules/stdlib ]; then
puppet module install puppetlabs-stdlib --modulepath /etc/puppet/modules
fi
if [ ! -e /etc/puppet/modules/python ]; then
puppet module install stankevich-python --modulepath /etc/puppet/modules
fi
puppet apply --verbose -e "node default { \
class { 'graphite': root_dir => '/var/lib/graphite' } \
class { 'python': \
pip => true, \
dev => true, \
virtualenv => true, \
} \
class { 'graphite': \
root_dir => '/var/lib/graphite', \
} \
}"
EOM

Expand Down
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
}

exec { 'init-db':
command => '/usr/bin/python manage.py syncdb --noinput',
command => "${root_dir}/bin/python manage.py syncdb --noinput",
cwd => "${root_dir}/webapp/graphite",
creates => "${root_dir}/storage/graphite.db",
subscribe => File["${root_dir}/storage"],
Expand Down
41 changes: 28 additions & 13 deletions manifests/deps.pp
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
# == Class: graphite::deps
#
# Class to install all graphite dependency packages
# Class to create a Python virtualenv and install all graphite dependencies
# within that sandbox.
#
# With the exception of pycairo which can't be installed by pip. It is
# installed as a system package and symlinked into the virtualenv. This is a
# slightly hacky alternative to `--system-site-packages` which would mess
# with Graphite's other dependencies.
#
class graphite::deps {
$root_dir = $::graphite::root_dir

ensure_packages([
'python-ldap',
'python-cairo',
'python-django',
'python-twisted',
'python-django-tagging',
'python-simplejson',
'python-memcache',
'python-pysqlite2',
'python-support',
'python-pip',
python::virtualenv { $root_dir: } ->
python::pip { [
'gunicorn',
])
'twisted==11.1.0',
'django==1.4.10',
'django-tagging==0.3.1',
'python-memcached==1.47',
'simplejson==2.1.6',
]:
virtualenv => $root_dir,
}

ensure_packages(['python-cairo'])

file { "${root_dir}/lib/python2.7/site-packages/cairo":
ensure => link,
target => '/usr/lib/python2.7/dist-packages/cairo',
require => [
Python::Virtualenv[$root_dir],
Package['python-cairo'],
],
}
}
37 changes: 6 additions & 31 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,12 @@
$root_dir = $::graphite::root_dir
$ver = $::graphite::version

package { 'whisper':
ensure => $ver,
provider => pip,
}

$carbon_pip_args = [
"--install-option=\"--prefix=${root_dir}\"",
"--install-option=\"--install-lib=${root_dir}/lib\"",
]
$carbon_args = join($carbon_pip_args, ' ')

exec { 'graphite/install carbon':
command => "/usr/bin/pip install ${carbon_args} carbon==${ver}",
creates => "${root_dir}/bin/carbon-cache.py",
}

$graphite_pip_args = [
"--install-option=\"--prefix=${root_dir}\"",
"--install-option=\"--install-lib=${root_dir}/webapp\""
]
$graphite_web_args = join($graphite_pip_args, ' ')

exec { 'graphite/install graphite-web':
command => "/usr/bin/pip install ${graphite_web_args} graphite-web==${ver}",
creates => "${root_dir}/webapp/graphite/manage.py",
}

file { '/var/log/carbon':
ensure => directory,
owner => www-data,
group => www-data,
python::pip { [
"whisper==${ver}",
"carbon==${ver}",
"graphite-web==${ver}"
]:
virtualenv => $root_dir,
}

}
2 changes: 1 addition & 1 deletion templates/upstart/carbon-cache.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ pre-start exec rm -f '<%= @root_dir %>'/storage/carbon-cache.pid
chdir '<%= @root_dir %>'
env GRAPHITE_STORAGE_DIR='<%= @root_dir %>/storage'
env GRAPHITE_CONF_DIR='<%= @root_dir %>/conf'
exec python '<%= @root_dir %>/bin/carbon-cache.py' --debug start
exec <%= @root_dir %>/bin/carbon-cache.py --debug start
2 changes: 1 addition & 1 deletion templates/upstart/graphite-web.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ chdir '<%= @root_dir %>/webapp'
env PYTHONPATH='<%= @root_dir %>/webapp'
env GRAPHITE_STORAGE_DIR='<%= @root_dir %>/storage'
env GRAPHITE_CONF_DIR='<%= @root_dir %>/conf'
exec /usr/bin/gunicorn_django -b127.0.0.1:<%= @port %> -w2 graphite/settings.py
exec <%= @root_dir %>/bin/gunicorn_django -b127.0.0.1:<%= @port %> -w2 graphite/settings.py

0 comments on commit 778da32

Please sign in to comment.