From 8fd856b5944dfb638749a9e581cae5cd0da43dd2 Mon Sep 17 00:00:00 2001 From: Christopher Aedo Date: Fri, 13 Nov 2015 12:02:48 -0800 Subject: [PATCH] Add python WSGI server This commit adds and configures mod_wsgi for apps.openstack.org. Change-Id: I860ba015aff8e555a69c361b414e3214e9a2107f Depends-On: I2fa9686d3e5db4ee43a02aa7d09b998472e02bf6 --- manifests/init.pp | 32 +++++++++++++++++ templates/local_settings.erb | 3 ++ templates/vhost.erb | 67 +++++++++++------------------------- 3 files changed, 56 insertions(+), 46 deletions(-) create mode 100644 templates/local_settings.erb diff --git a/manifests/init.pp b/manifests/init.pp index 64d79ed..6f36236 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -13,6 +13,7 @@ class apps_site ( $ssl_chain_file = '/etc/ssl/certs/ca-certificates.crt', ) { include ::httpd::ssl + include ::httpd::mod::wsgi if !defined(Package['git']) { package { 'git': @@ -98,6 +99,37 @@ class apps_site ( } } + file { "${root_dir}/openstack_catalog/local_settings.py": + ensure => present, + mode => '0644', + content => template('apps_site/local_settings.erb'), + require => Vcsrepo[$root_dir], + } + + exec { 'install-app_catalog' : + command => "/usr/local/bin/pip install ${root_dir}", + cwd => $root_dir, + refreshonly => true, + subscribe => Vcsrepo[$root_dir], + require => File["${root_dir}/openstack_catalog/local_settings.py"], + notify => Service['httpd'], + } + + file { "${root_dir}/openstack_catalog/web/static/CACHE": + ensure => directory, + owner => 'www-data', + group => 'www-data', + mode => '0755', + require => Vcsrepo[$root_dir], + } + + exec { 'collect-static' : + command => "/usr/bin/python ${root_dir}/manage.py collectstatic --noinput", + refreshonly => true, + subscribe => Vcsrepo[$root_dir], + require => File["${root_dir}/openstack_catalog/web/static/CACHE"], + } + exec { 'make_assets_json' : command => "${root_dir}/tools/update_assets.sh", path => '/usr/local/bin:/usr/bin:/bin', diff --git a/templates/local_settings.erb b/templates/local_settings.erb new file mode 100644 index 0000000..6cb43c6 --- /dev/null +++ b/templates/local_settings.erb @@ -0,0 +1,3 @@ +ASSETS_FILE = '<%= @root_dir %>/openstack_catalog/web/api/v1/assets' +STATIC_ROOT = '<%= @root_dir %>/openstack_catalog/web/static' +COMPRESS_ENABLED = True diff --git a/templates/vhost.erb b/templates/vhost.erb index 2fe92c9..75288cf 100644 --- a/templates/vhost.erb +++ b/templates/vhost.erb @@ -2,6 +2,12 @@ ServerAdmin <%= @serveradmin %> ServerName <%= @vhost_name %> + WSGIProcessGroup appcatalog + WSGIDaemonProcess appcatalog user=www-data group=www-data threads=5 python-path=/usr/lib/python2.7:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages + WSGIScriptAlias / /usr/local/lib/python2.7/dist-packages/openstack_catalog/wsgi.py + + Alias /static/ <%= @root_dir %>/openstack_catalog/web/static/ + DocumentRoot <%= @docroot %> Options FollowSymLinks @@ -11,28 +17,11 @@ Allow from all Satisfy Any - - Header set Access-Control-Allow-Origin "*" - Header set Content-type "application/json" - Header set Access-Control-Allow-Headers "Origin, Accept-Encoding, Content-Type, X-App-Catalog-Versions" - Header set Access-Control-Max-Age 3600 - Header set Cache-Control max-age=3600 - Header set Access-Control-Allow-Methods "GET, OPTIONS" - SetOutputFilter DEFLATE - - - RewriteEngine On - - RewriteRule "^/api/v1/assets\.gz$" "-" [T=application/json,E=no-gzip:1] - - RewriteCond %{REQUEST_METHOD} OPTIONS - RewriteRule ^(/api/v1/assets)$ /static/blank.json [QSA,L] - - RewriteCond "%{HTTP:Accept-Encoding}" "gzip" - RewriteCond "%{REQUEST_FILENAME}\.gz" -s - RewriteRule "^(/api/v1/assets)" "$1\.gz" [QSA] - - RedirectMatch ^/api/v1/murano_repo/liberty/(.*)$ http://storage.apps.openstack.org/$1 + + Order allow,deny + Allow from all + Satisfy Any + ErrorLog /var/log/apache2/app_site-error.log @@ -48,8 +37,11 @@ ServerAdmin <%= @serveradmin %> ServerName <%= @vhost_name %> - ErrorLog ${APACHE_LOG_DIR}/<%= @vhost_name %>-ssl-error.log - CustomLog ${APACHE_LOG_DIR}/<%= @vhost_name %>-ssl-access.log combined + WSGIProcessGroup appcatalogssl + WSGIDaemonProcess appcatalogssl user=www-data group=www-data threads=5 python-path=/usr/lib/python2.7:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages + WSGIScriptAlias / /usr/local/lib/python2.7/dist-packages/openstack_catalog/wsgi.py + + Alias /static/ <%= @root_dir %>/openstack_catalog/web/static/ SSLEngine on SSLProtocol All -SSLv2 -SSLv3 @@ -75,28 +67,11 @@ Allow from all Satisfy Any - - Header set Access-Control-Allow-Origin "*" - Header set Content-type "application/json" - Header set Access-Control-Allow-Headers "Origin, Accept-Encoding, Content-Type, X-App-Catalog-Versions" - Header set Access-Control-Max-Age 3600 - Header set Cache-Control max-age=3600 - Header set Access-Control-Allow-Methods "GET, OPTIONS" - SetOutputFilter DEFLATE - - - RewriteEngine On - - RewriteRule "^/api/v1/assets\.gz$" "-" [T=application/json,E=no-gzip:1] - - RewriteCond %{REQUEST_METHOD} OPTIONS - RewriteRule ^(/api/v1/assets)$ /static/blank.json [QSA,L] - - RewriteCond "%{HTTP:Accept-Encoding}" "gzip" - RewriteCond "%{REQUEST_FILENAME}\.gz" -s - RewriteRule "^(/api/v1/assets)" "$1\.gz" [QSA] - - RedirectMatch ^/api/v1/murano_repo/liberty/(.*)$ http://storage.apps.openstack.org/$1 + + Order allow,deny + Allow from all + Satisfy Any + ErrorLog /var/log/apache2/app_site-error.log