From 92ad5a7b0e5e1771115c8ebe2911bb494b43e952 Mon Sep 17 00:00:00 2001 From: Paul Van Eck Date: Thu, 18 Feb 2016 01:58:37 -0800 Subject: [PATCH] Make puppet pull releases from Pypi This commit merges api.pp and app.pp into one file to remove duplication and for easier dependency chaining. This commit also makes puppet pull new RefStack releases from pypi so we don't have to keep bumping versions in puppet-refstack. Change-Id: Ic6f5e30ea46d3c053c49b8a45168001bcbd2b46e --- manifests/apache/http.pp | 9 ++- manifests/apache/https.pp | 9 ++- manifests/api.pp | 102 ------------------------------ manifests/app.pp | 127 ++++++++++++++++++++++++++++++-------- manifests/init.pp | 1 - manifests/params.pp | 6 +- 6 files changed, 110 insertions(+), 144 deletions(-) delete mode 100644 manifests/api.pp diff --git a/manifests/apache/http.pp b/manifests/apache/http.pp index 432550b..105e3d9 100644 --- a/manifests/apache/http.pp +++ b/manifests/apache/http.pp @@ -19,12 +19,11 @@ # class refstack::apache::http () { require ::refstack::params - require ::refstack::api require ::refstack::app # Pull various variables into this module, for slightly saner templates. $install_www_root = $::refstack::params::install_www_root - $src_www_root = $::refstack::params::src_www_root + $src_root = $::refstack::params::src_root $hostname = $::refstack::params::hostname $user = $::refstack::params::user $group = $::refstack::params::group @@ -41,9 +40,9 @@ class refstack::apache::http () { owner => $::httpd::params::user, group => $::httpd::params::group, mode => '0644', - source => "${src_www_root}/refstack/api/app.wsgi", + source => "${src_root}/refstack/api/app.wsgi", require => [ - Class['refstack::api'] + Class['refstack::app'] ], notify => Service['httpd'], } @@ -53,7 +52,7 @@ class refstack::apache::http () { ensure => directory, owner => $::httpd::params::user, group => $::httpd::params::group, - source => "${src_www_root}/refstack-ui/app", + source => "${src_root}/refstack-ui/app", recurse => true, purge => true, force => true, diff --git a/manifests/apache/https.pp b/manifests/apache/https.pp index eb9d40b..cd73c72 100644 --- a/manifests/apache/https.pp +++ b/manifests/apache/https.pp @@ -19,12 +19,11 @@ # class refstack::apache::https () { require ::refstack::params - require ::refstack::api require ::refstack::app # Pull various variables into this module, for slightly saner templates. $install_www_root = $::refstack::params::install_www_root - $src_www_root = $::refstack::params::src_www_root + $src_root = $::refstack::params::src_root $hostname = $::refstack::params::hostname $user = $::refstack::params::user $group = $::refstack::params::group @@ -48,9 +47,9 @@ class refstack::apache::https () { owner => $::httpd::params::user, group => $::httpd::params::group, mode => '0644', - source => "${src_www_root}/refstack/api/app.wsgi", + source => "${src_root}/refstack/api/app.wsgi", require => [ - Class['refstack::api'] + Class['refstack::app'] ], notify => Service['httpd'], } @@ -90,7 +89,7 @@ class refstack::apache::https () { ensure => directory, owner => $::httpd::params::user, group => $::httpd::params::group, - source => "${src_www_root}/refstack-ui/app", + source => "${src_root}/refstack-ui/app", recurse => true, purge => true, force => true, diff --git a/manifests/api.pp b/manifests/api.pp deleted file mode 100644 index 990411f..0000000 --- a/manifests/api.pp +++ /dev/null @@ -1,102 +0,0 @@ -# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# == Class: refstack::api -# -# This class installs the RefStack API so that it may be run via wsgi. -# -class refstack::api () { - require ::refstack::params - require ::refstack::user - - # Import parameters into local scope. - $src_api_root = $::refstack::params::src_api_root - $user = $::refstack::params::user - $group = $::refstack::params::group - - # Ensure Git is present - if !defined(Package['git']) { - package { 'git': - ensure => present - } - } - - # Ensure python-dev is present - if !defined(Package['python-dev']) { - package { 'python-dev': - ensure => present - } - } - - # Ensure OpenSSL is present - if !defined(Package['libssl-dev']) { - package { 'libssl-dev': - ensure => present - } - } - - # Create the RefStack configuration directory. - file { '/etc/refstack': - ensure => directory, - owner => $user, - group => $group, - mode => '0755', - } - - # Configure the RefStack API. - file { '/etc/refstack/refstack.conf': - ensure => present, - owner => $user, - group => $group, - mode => '0644', - content => template('refstack/refstack.conf.erb'), - require => [ - File['/etc/refstack'] - ] - } - - # Download the latest RefStack Source. - vcsrepo { $src_api_root: - ensure => present, - provider => git, - revision => $refstack::params::release_revision, - source => 'https://git.openstack.org/openstack/refstack/', - require => Package['git'] - } - - # Install RefStack using pip. - exec { 'install-refstack': - command => "pip install ${src_api_root}", - path => '/usr/local/bin:/usr/bin:/bin', - refreshonly => true, - require => Vcsrepo[$src_api_root], - subscribe => Vcsrepo[$src_api_root], - notify => Service['httpd'], - } - - # Migrate the database. - exec { 'migrate-refstack-db': - command => 'refstack-manage --config-file /etc/refstack/refstack.conf upgrade --revision head', - path => '/usr/local/bin:/usr/bin:/bin', - refreshonly => true, - subscribe => [ - Exec['install-refstack'], - File['/etc/refstack/refstack.conf'], - ], - require => [ - Exec['install-refstack'], - File['/etc/refstack/refstack.conf'], - ], - } -} diff --git a/manifests/app.pp b/manifests/app.pp index 6170801..50dc861 100644 --- a/manifests/app.pp +++ b/manifests/app.pp @@ -14,25 +14,28 @@ # == Class: refstack::app # -# This class installs the RefStack JavaScript Webclient (or app). -# -# Much of this module is duplicated in ::refstack::api, however it's separated -# here so that any future project splits (api vs. client) can be treated -# similarly in the puppet module. +# This class installs the RefStack application (API and UI) so that it may be +# run via wsgi. # class refstack::app () { require ::refstack::params require ::refstack::user # Import parameters into local scope. - $src_www_root = $::refstack::params::src_www_root - $install_www_root = $::refstack::params::install_www_root + $src_root = $::refstack::params::src_root $user = $::refstack::params::user $group = $::refstack::params::group - # Ensure Git is present - if !defined(Package['git']) { - package { 'git': + # Ensure python-dev is present + if !defined(Package['python-dev']) { + package { 'python-dev': + ensure => present + } + } + + # Ensure OpenSSL is present + if !defined(Package['libssl-dev']) { + package { 'libssl-dev': ensure => present } } @@ -43,42 +46,111 @@ class refstack::app () { ensure => present } } + if !defined(Package['nodejs']) { package { 'nodejs': ensure => present } } + if !defined(Package['nodejs-legacy']) { package { 'nodejs-legacy': ensure => present } } - # Download the latest RefStack Source. - vcsrepo { $src_www_root: - ensure => present, - owner => $user, - group => $group, - provider => git, - revision => $refstack::params::release_revision, - source => 'https://git.openstack.org/openstack/refstack/', - require => Package['git'] + # Create the RefStack configuration directory. + file { '/etc/refstack': + ensure => directory, + owner => $user, + group => $group, + mode => '0755', + } + + file { $src_root: + ensure => 'directory', + owner => $user, + group => $group, + mode => '0755', + } + + # Configure the RefStack API. + file { '/etc/refstack/refstack.conf': + ensure => present, + owner => $user, + group => $group, + mode => '0644', + content => template('refstack/refstack.conf.erb'), + require => [ + File['/etc/refstack'] + ] + } + + # Download the RefStack tar.gz source distribution from pypi only if a new + # one is available. + exec { 'download-refstack': + command => 'pip install refstack -d /tmp --no-deps --no-binary :all:', + path => '/usr/local/bin:/usr/bin:/bin', + user => $user, + group => $group, + onlyif => 'pip list --outdated | grep -c refstack || test `pip freeze | grep -c refstack` -eq 0' + } + + # Untar the source contents. + exec { 'untar-refstack' : + command => "tar -xvzf /tmp/refstack-*.tar.gz -C ${src_root} --strip-components=1", + path => '/usr/local/bin:/usr/bin:/bin', + refreshonly => true, + user => $user, + group => $group, + require => File[$src_root], + subscribe => Exec['download-refstack'] + } + + # Remove tar.gz file after extracting. + exec { 'remove-tar': + command => 'rm -f /tmp/refstack-*.tar.gz', + path => '/usr/local/bin:/usr/bin:/bin', + refreshonly => true, + subscribe => Exec['untar-refstack'] + } + + # Install RefStack using pip. + exec { 'install-refstack': + command => "pip install -U ${src_root}", + path => '/usr/local/bin:/usr/bin:/bin', + refreshonly => true, + require => File[$src_root], + subscribe => Exec['untar-refstack'], + notify => Service['httpd'] + } + + # Migrate the database. + exec { 'migrate-refstack-db': + command => 'refstack-manage --config-file /etc/refstack/refstack.conf upgrade --revision head', + path => '/usr/local/bin:/usr/bin:/bin', + refreshonly => true, + subscribe => [ + Exec['install-refstack'], + File['/etc/refstack/refstack.conf'], + ], + require => [ + Exec['install-refstack'], + File['/etc/refstack/refstack.conf'], + ] } # Run NPM Install. exec { 'npm install': command => 'npm install', path => '/usr/local/bin:/usr/bin:/bin/', - cwd => $src_www_root, + cwd => $src_root, user => $user, group => $group, refreshonly => true, - subscribe => [ - Vcsrepo[$src_www_root], - ], + subscribe => Exec['untar-refstack'], require => [ Package['npm'], - Vcsrepo[$src_www_root], ], environment => [ # This is not automatically set by exec. @@ -87,9 +159,12 @@ class refstack::app () { } # Create config.json file. - file { "${src_www_root}/refstack-ui/app/config.json": + file { "${src_root}/refstack-ui/app/config.json": ensure => file, content => '{"refstackApiUrl": "/api/v1"}', - require => Vcsrepo[$src_www_root], + require => [ + File[$src_root], + Exec['untar-refstack'], + ] } } diff --git a/manifests/init.pp b/manifests/init.pp index 2af686b..576a71c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -52,7 +52,6 @@ class refstack ( include ::refstack::mysql include ::refstack::app - include ::refstack::api if $protocol == 'https' { include ::refstack::apache::https diff --git a/manifests/params.pp b/manifests/params.pp index 096817a..d46977e 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -18,12 +18,8 @@ # class refstack::params ( - # Current release revision - $release_revision = '1.0.0', - # Source and install directories. - $src_api_root = '/opt/refstack-api', - $src_www_root = '/opt/refstack-www', + $src_root = '/opt/refstack', $install_www_root = '/var/www/refstack-www', # The user under which refstack will run.