Add virtualenv support

The python environment including askbot requirements moved under
/usr/askbot-env to provide proper pip dependency resolution. The
change affects the python manage calls, celeryd daemon upstart
script and mod wsgi exec env.

Change-Id: Id2031e4c51fd71c0e4630b2f1e71845223833bba
This commit is contained in:
Marton Kiss 2015-07-18 22:08:15 +02:00
parent e449a2ce34
commit 2ab8bfa972
5 changed files with 64 additions and 35 deletions

View File

@ -15,73 +15,101 @@ class askbot::install (
}
}
if !defined(Package['python-pip']) {
package { 'python-pip':
if !defined(Package['virtualenv']) {
package { 'virtualenv':
ensure => present,
}
}
if !defined(Package['python-dev']) {
package { 'python-dev':
ensure => present,
}
python::virtualenv { '/usr/askbot-env':
ensure => present,
owner => 'root',
group => 'root',
timeout => 0,
require => Package['virtualenv'],
}
case $db_provider {
'mysql': {
$db_provider_package = 'python-mysqldb'
package { 'libmysqlclient-dev':
ensure => present,
}
python::pip { 'MySQL-python':
ensure => '1.2.3',
pkgname => 'MySQL-python',
virtualenv => '/usr/askbot-env',
require => [ Package['libmysqlclient-dev'], Python::Virtualenv['/usr/askbot-env'] ],
}
}
'pgsql': {
$db_provider_package = 'python-psycopg2'
package { 'libpq-dev':
ensure => present,
}
python::pip { 'psycopg2':
ensure => '2.4.5',
pkgname => 'psycopg2',
virtualenv => '/usr/askbot-env',
require => [ Package['libpq-dev'], Python::Virtualenv['/usr/askbot-env'] ],
}
}
default: {
fail("Unsupported database provider: ${db_provider}")
}
}
if ! defined(Package[$db_provider_package]) {
package { $db_provider_package:
ensure => present,
}
}
if $redis_enabled {
package { 'django-redis-cache':
ensure => present,
provider => 'pip',
python::pip { 'redis':
ensure => '1.3.0',
pkgname => 'django-redis-cache',
virtualenv => '/usr/askbot-env',
require => Python::Virtualenv['/usr/askbot-env'],
}
}
include ::apache::mod::wsgi
if $solr_enabled {
package { [ 'django-haystack', 'pysolr' ]:
ensure => present,
provider => 'pip',
python::pip { 'django-haystack':
ensure => '2.3.1',
pkgname => 'django-haystack',
virtualenv => '/usr/askbot-env',
require => Python::Virtualenv['/usr/askbot-env'],
}
}
package { 'stopforumspam':
ensure => present,
provider => 'pip',
before => Exec['askbot-install'],
python::pip { 'pysolr':
ensure => '3.3.0',
pkgname => 'pysolr',
virtualenv => '/usr/askbot-env',
require => Python::Virtualenv['/usr/askbot-env'],
}
}
exec { 'pip-requirements-install':
path => [ '/bin', '/sbin' , '/usr/bin', '/usr/sbin', '/usr/local/bin' ],
command => "pip install -q -r ${dist_root}/askbot/askbot_requirements.txt",
command => "/usr/askbot-env/bin/pip install -q -r ${dist_root}/askbot/askbot_requirements.txt",
cwd => "${dist_root}/askbot",
logoutput => on_failure,
subscribe => Vcsrepo["${dist_root}/askbot"],
refreshonly => true,
}
python::pip { 'stopforumspam':
ensure => present,
pkgname => 'stopforumspam',
virtualenv => '/usr/askbot-env',
require => Python::Virtualenv['/usr/askbot-env'],
}
include ::apache::mod::wsgi
exec { 'askbot-install':
path => [ '/bin', '/sbin' , '/usr/bin', '/usr/sbin', '/usr/local/bin' ],
cwd => "${dist_root}/askbot",
command => 'python setup.py -q install',
command => '/usr/askbot-env/bin/python setup.py -q install',
logoutput => on_failure,
subscribe => Vcsrepo["${dist_root}/askbot"],
refreshonly => true,
require => Exec[ 'pip-requirements-install'],
}
}

View File

@ -74,7 +74,7 @@ class askbot::site::config (
exec { 'askbot-static-generate':
cwd => "${site_root}/config",
command => 'python manage.py collectstatic --noinput',
command => '/usr/askbot-env/bin/python manage.py collectstatic --noinput',
require => $post_config_dependency,
subscribe => [Vcsrepo["${dist_root}/askbot"], File["${site_root}/config/settings.py"] ],
refreshonly => true,
@ -82,7 +82,7 @@ class askbot::site::config (
exec { 'askbot-syncdb':
cwd => "${site_root}/config",
command => 'python manage.py syncdb --noinput',
command => '/usr/askbot-env/bin/python manage.py syncdb --noinput',
require => $post_config_dependency,
subscribe => [Vcsrepo["${dist_root}/askbot"], File["${site_root}/config/settings.py"] ],
refreshonly => true,
@ -91,7 +91,7 @@ class askbot::site::config (
# TODO: end of chain: notify httpd, celeryd
exec { 'askbot-migrate':
cwd => "${site_root}/config",
command => 'python manage.py migrate --noinput',
command => '/usr/askbot-env/bin/python manage.py migrate --noinput',
require => Exec['askbot-syncdb'],
subscribe => [Vcsrepo["${dist_root}/askbot"], File["${site_root}/config/settings.py"] ],
refreshonly => true,

View File

@ -24,6 +24,7 @@
{ "name": "puppetlabs/mysql", "version_requirement": "= 0.6.1" },
{ "name": "puppetlabs/apache", "version_requirement": "= 0.0.4" },
{ "name": "openstackinfra/redis", "version_requirement": "= 0.0.1" },
{ "name": "openstackinfra/vcsrepo", "version_requirement": "= 0.0.1" }
{ "name": "openstackinfra/vcsrepo", "version_requirement": "= 0.0.1" },
{ "name": "stankevich/python", "version_requirement": "= 1.9.4" }
]
}

View File

@ -45,7 +45,7 @@ NameVirtualHost <%= @vhost_name %>:443
</Directory>
# wsgi daemon
WSGIDaemonProcess askbot user=<%= @www_user %> group=<%= @www_group %> maximum-requests=1000 display-name=askbot processes=2 threads=1 shutdown-timeout=10 python-path=<%= @docroot %>
WSGIDaemonProcess askbot user=<%= @www_user %> group=<%= @www_group %> maximum-requests=1000 display-name=askbot processes=2 threads=1 shutdown-timeout=10 python-path=<%= @docroot %>:/usr/askbot-env/lib/python2.7/site-packages
WSGIScriptAlias / <%= @docroot %>/config/django.wsgi

View File

@ -8,5 +8,5 @@ kill timeout 30
respawn
script
chdir /srv/askbot-site/config
exec su -s /bin/sh -c 'exec "$0" "$@"' www-data -- /usr/bin/python manage.py celeryd -c 5 --maxtasksperchild=1000 --time-limit=30
end script
exec su -s /bin/sh -c 'exec "$0" "$@"' www-data -- /usr/askbot-env/bin/python manage.py celeryd -c 5 --maxtasksperchild=1000 --time-limit=30
end script