From 289a00a149ac08d01b8ee638620d8c2928966fa3 Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 15 Nov 2013 01:02:25 -0800 Subject: improvements to webapp deployment: allow for greater customization, allow for custom git source, improve apache config. --- provider_base/services/webapp.json | 12 ++-- .../site_apache/manifests/module/expires.pp | 4 ++ .../templates/vhosts.d/leap_webapp.conf.erb | 8 +++ puppet/modules/site_webapp/manifests/apache.pp | 1 + puppet/modules/site_webapp/manifests/init.pp | 64 ++++------------------ 5 files changed, 29 insertions(+), 60 deletions(-) create mode 100644 puppet/modules/site_apache/manifests/module/expires.pp diff --git a/provider_base/services/webapp.json b/provider_base/services/webapp.json index 9b02afce..392375ff 100644 --- a/provider_base/services/webapp.json +++ b/provider_base/services/webapp.json @@ -4,18 +4,18 @@ "modules": ["user", "billing", "help"], "couchdb_admin_user": "= global.services[:couchdb].couch.users[:admin]", "couchdb_webapp_user": "= global.services[:couchdb].couch.users[:webapp]", - "favicon": "= file_path 'branding/favicon.ico'", - "tail_scss": "= file_path 'branding/tail.scss'", - "head_scss": "= file_path 'branding/head.scss'", - "img_dir": "= file_path 'branding/img'", - "home_page": "= file_path 'branding/views/home.html.haml'", + "customization_dir": "= file_path 'webapp'", "client_certificates": "= global.provider.ca.client_certificates", "allow_limited_certs": "= global.provider.service.allow_limited_bandwidth", "allow_unlimited_certs": "= global.provider.service.allow_unlimited_bandwidth", "allow_anonymous_certs": "= global.provider.service.allow_anonymous", "secret_token": "= secret :webapp_secret_token", "api_version": 1, - "secure": false + "secure": false, + "git": { + "source": "https://leap.se/git/leap_web", + "revision": "origin/master" + } }, "stunnel": { "couch_client": "= stunnel_client(nodes_like_me[:services => :couchdb], global.services[:couchdb].couch.port)" diff --git a/puppet/modules/site_apache/manifests/module/expires.pp b/puppet/modules/site_apache/manifests/module/expires.pp new file mode 100644 index 00000000..f73a5607 --- /dev/null +++ b/puppet/modules/site_apache/manifests/module/expires.pp @@ -0,0 +1,4 @@ +class site_apache::module::expires ( $ensure = present ) +{ + apache::module { 'expires': ensure => $ensure } +} diff --git a/puppet/modules/site_apache/templates/vhosts.d/leap_webapp.conf.erb b/puppet/modules/site_apache/templates/vhosts.d/leap_webapp.conf.erb index afc19782..a001552a 100644 --- a/puppet/modules/site_apache/templates/vhosts.d/leap_webapp.conf.erb +++ b/puppet/modules/site_apache/templates/vhosts.d/leap_webapp.conf.erb @@ -45,6 +45,14 @@ PassengerFriendlyErrorPages off SetEnv TMPDIR /var/tmp + # Allow rails assets to be cached for a very long time (since the URLs change whenever the content changes) + + Header unset ETag + FileETag None + ExpiresActive On + ExpiresDefault "access plus 1 year" + + <% if (defined? @services) and (@services.include? 'monitor') -%> PassengerEnabled off diff --git a/puppet/modules/site_webapp/manifests/apache.pp b/puppet/modules/site_webapp/manifests/apache.pp index 6a199b9e..581922cb 100644 --- a/puppet/modules/site_webapp/manifests/apache.pp +++ b/puppet/modules/site_webapp/manifests/apache.pp @@ -21,6 +21,7 @@ class site_webapp::apache { include site_apache::module::headers include site_apache::module::rewrite include site_apache::module::alias + include site_apache::module::expires class { 'passenger': use_munin => false } diff --git a/puppet/modules/site_webapp/manifests/init.pp b/puppet/modules/site_webapp/manifests/init.pp index d5687804..c090c6a0 100644 --- a/puppet/modules/site_webapp/manifests/init.pp +++ b/puppet/modules/site_webapp/manifests/init.pp @@ -40,9 +40,9 @@ class site_webapp { vcsrepo { '/srv/leap/webapp': ensure => present, force => true, - revision => 'origin/master', + revision => $webapp['git']['revision'], provider => git, - source => 'https://leap.se/git/leap_web', + source => $webapp['git']['source'], owner => 'leap-webapp', group => 'leap-webapp', require => [ User['leap-webapp'], Group['leap-webapp'] ], @@ -63,6 +63,10 @@ class site_webapp { notify => Service['apache']; } + # + # NOTE: in order to support a webapp that is running on a subpath and not the root of the domain + # assets:precompile needs to be run with RAILS_RELATIVE_URL_ROOT=/application-root + # exec { 'compile_assets': cwd => '/srv/leap/webapp', command => '/bin/bash -c "RAILS_ENV=production /usr/bin/bundle exec rake assets:precompile"', @@ -110,72 +114,24 @@ class site_webapp { } try::file { - '/srv/leap/webapp/public/favicon.ico': - ensure => present, - owner => leap-webapp, - group => leap-webapp, - mode => '0644', - require => Vcsrepo['/srv/leap/webapp'], - source => $webapp['favicon']; - - '/srv/leap/webapp/app/assets/stylesheets/tail.scss': - ensure => present, - owner => leap-webapp, - group => leap-webapp, - mode => '0644', - require => Vcsrepo['/srv/leap/webapp'], - source => $webapp['tail_scss'], - before => Exec['bundler_update']; - - '/srv/leap/webapp/app/assets/stylesheets/head.scss': - ensure => present, - owner => leap-webapp, - group => leap-webapp, - mode => '0644', - require => Vcsrepo['/srv/leap/webapp'], - source => $webapp['head_scss'], - before => Exec['bundler_update']; - - '/srv/leap/webapp/public/img': + '/srv/leap/webapp/config/customization': ensure => directory, recurse => true, purge => true, force => true, owner => leap-webapp, group => leap-webapp, - mode => '0644', - require => Vcsrepo['/srv/leap/webapp'], - source => $webapp['img_dir']; - - '/srv/leap/webapp/app/views/home/index.html.haml': - ensure => present, - owner => leap-webapp, - group => leap-webapp, - mode => '0644', + mode => 'u=rwX,go=rX', require => Vcsrepo['/srv/leap/webapp'], - source => $webapp['home_page']; + notify => Exec['compile_assets'], + source => $webapp['customization_dir']; } git::changes { - 'app/assets/stylesheets/head.scss': - cwd => '/srv/leap/webapp', - require => Vcsrepo['/srv/leap/webapp'], - user => 'leap-webapp'; - - 'app/assets/stylesheets/tail.scss': - cwd => '/srv/leap/webapp', - require => Vcsrepo['/srv/leap/webapp'], - user => 'leap-webapp'; - 'public/favicon.ico': cwd => '/srv/leap/webapp', require => Vcsrepo['/srv/leap/webapp'], user => 'leap-webapp'; - - 'app/views/home/index.html.haml': - cwd => '/srv/leap/webapp', - require => Vcsrepo['/srv/leap/webapp'], - user => 'leap-webapp'; } file { -- cgit v1.2.3