diff --git a/manifests/deployment/curator/api.pp b/manifests/deployment/curator/api.pp deleted file mode 100644 index ef9265a2..00000000 --- a/manifests/deployment/curator/api.pp +++ /dev/null @@ -1,61 +0,0 @@ -class profiles::deployment::curator::api ( - String $config_source, - String $version = 'latest', - Optional[String] $puppetdb_url = lookup('data::puppet::puppetdb::url', Optional[String], 'first', undef) -) inherits ::profiles { - - $basedir = '/var/www/curator-api' - - realize Apt::Source['publiq-curator'] - - # TODO: package notify Apache::Service ? - # TODO: config file notify Apache::Service ? - - package { 'curator-api': - ensure => $version, - notify => Profiles::Deployment::Versions[$title], - require => Apt::Source['publiq-curator'] - } - - file { 'curator-api-config': - ensure => 'file', - path => "${basedir}/.env", - source => $config_source, - owner => 'www-data', - group => 'www-data', - require => Package['curator-api'] - } - - file { 'curator-api-var': - path => "${basedir}/var", - owner => 'www-data', - group => 'www-data', - recurse => true, - before => Exec['curator-api_cache_clear'] - } - - exec { 'curator-api_db_schema_update': - command => 'php bin/console doctrine:migrations:migrate --no-interaction', - cwd => $basedir, - user => 'www-data', - group => 'www-data', - path => [ '/usr/local/bin', '/usr/bin', '/bin', $basedir], - subscribe => Package['curator-api'], - refreshonly => true - } - - exec { 'curator-api_cache_clear': - command => 'php bin/console cache:clear', - cwd => $basedir, - user => 'www-data', - group => 'www-data', - path => [ '/usr/local/bin', '/usr/bin', '/bin', $basedir], - subscribe => Package['curator-api'], - require => Exec['curator-api_db_schema_update'], - refreshonly => true - } - - profiles::deployment::versions { $title: - puppetdb_url => $puppetdb_url - } -} diff --git a/manifests/deployment/udb3/search.pp b/manifests/deployment/udb3/search.pp deleted file mode 100644 index b8fce9f6..00000000 --- a/manifests/deployment/udb3/search.pp +++ /dev/null @@ -1,5 +0,0 @@ -class profiles::deployment::udb3::search ( - -) { - -} diff --git a/manifests/uitdatabank/websocket_server.pp b/manifests/uitdatabank/websocket_server.pp index d397dd6d..825ba7b6 100644 --- a/manifests/uitdatabank/websocket_server.pp +++ b/manifests/uitdatabank/websocket_server.pp @@ -1,21 +1,42 @@ class profiles::uitdatabank::websocket_server ( - Boolean $deployment = true, - Integer $listen_port = 3000 -) inherits ::profiles { + String $servername, + Variant[String,Array[String]] $serveraliases = [], + Boolean $deployment = true, + Stdlib::IP::Address::V4 $service_address = '127.0.0.1', + Integer $service_port = 3000, +) inherits ::profiles { + + $basedir = '/var/www/udb3-websocket-server' + + realize Group['www-data'] + realize User['www-data'] include ::profiles::nodejs + include ::profiles::redis - if $deployment { - include ::profiles::uitdatabank::websocket_server::deployment + file { $basedir: + ensure => 'directory', + owner => 'www-data', + group => 'www-data', + require => [Group['www-data'], User['www-data']] + } - Class['profiles::nodejs'] -> Class['profiles::uitdatabank::websocket_server::deployment'] + if $deployment { + class { 'profiles::uitdatabank::websocket_server::deployment': + service_address => $service_address, + service_port => $service_port, + require => [Class['profiles::nodejs'], Class['profiles::redis']], + before => Profiles::Apache::Vhost::Reverse_proxy["http://${servername}"] + } } - # TODO: apache + vhosts (move from hieradata here) - # TODO: firewall rules + profiles::apache::vhost::reverse_proxy { "http://${servername}": + aliases => $serveraliases, + destination => "http://${service_address}:${service_port}/", + support_websockets => true + } # include ::profiles::uitdatabank::websocket_server::monitoring # include ::profiles::uitdatabank::websocket_server::metrics - # include ::profiles::uitdatabank::websocket_server::backup # include ::profiles::uitdatabank::websocket_server::logging } diff --git a/manifests/uitdatabank/websocket_server/deployment.pp b/manifests/uitdatabank/websocket_server/deployment.pp index b73ffd75..1bbaf6df 100644 --- a/manifests/uitdatabank/websocket_server/deployment.pp +++ b/manifests/uitdatabank/websocket_server/deployment.pp @@ -1,21 +1,23 @@ class profiles::uitdatabank::websocket_server::deployment ( - String $config_source, - String $version = 'latest', - Boolean $service_manage = true, - String $service_ensure = 'running', - Boolean $service_enable = true, - Integer $listen_port = lookup('profiles::uitdatabank::websocket_server::listen_port', Integer, 'first', 3000), - Optional[String] $puppetdb_url = lookup('data::puppet::puppetdb::url', Optional[String], 'first', undef) + String $config_source, + String $version = 'latest', + String $repository = 'uitdatabank-websocket-server', + Enum['running', 'stopped'] $service_status = 'running', + Stdlib::IP::Address::V4 $service_address = '127.0.0.1', + Integer $service_port = 3000, + Optional[String] $puppetdb_url = lookup('data::puppet::puppetdb::url', Optional[String], 'first', undef) ) inherits ::profiles { $basedir = '/var/www/udb3-websocket-server' - realize Apt::Source['uitdatabank-websocket-server'] + realize Apt::Source[$repository] + realize Group['www-data'] + realize User['www-data'] package { 'uitdatabank-websocket-server': ensure => $version, - notify => Profiles::Deployment::Versions[$title], - require => Apt::Source['uitdatabank-websocket-server'] + require => [Apt::Source[$repository], Group['www-data'], User['www-data']], + notify => [Service['uitdatabank-websocket-server'], Profiles::Deployment::Versions[$title]] } file { 'uitdatabank-websocket-server-config': @@ -24,23 +26,25 @@ owner => 'www-data', group => 'www-data', source => $config_source, - require => Package['uitdatabank-websocket-server'] + require => [Package['uitdatabank-websocket-server'], Group['www-data'], User['www-data']], + notify => Service['uitdatabank-websocket-server'] } - if $service_manage { - file { 'uitdatabank-websocket-server-service-defaults': - ensure => 'file', - path => '/etc/default/uitdatabank-websocket-server', - content => "PORT=${listen_port}", - require => Package['uitdatabank-websocket-server'] - } + file { 'uitdatabank-websocket-server-service-defaults': + ensure => 'file', + path => '/etc/default/uitdatabank-websocket-server', + content => "HOST=${service_address}\nPORT=${service_port}", + require => Package['uitdatabank-websocket-server'], + notify => Service['uitdatabank-websocket-server'] + } - service { 'uitdatabank-websocket-server': - ensure => $service_ensure, - enable => $service_enable, - subscribe => [Package['uitdatabank-websocket-server'], File['uitdatabank-websocket-server-config'], File['uitdatabank-websocket-server-service-defaults']], - hasstatus => true - } + service { 'uitdatabank-websocket-server': + ensure => $service_status, + enable => $service_status ? { + 'running' => true, + 'stopped' => false + }, + hasstatus => true } profiles::deployment::versions { $title: diff --git a/spec/classes/uitdatabank/websocket_server/deployment_spec.rb b/spec/classes/uitdatabank/websocket_server/deployment_spec.rb index d463085a..75e251a4 100644 --- a/spec/classes/uitdatabank/websocket_server/deployment_spec.rb +++ b/spec/classes/uitdatabank/websocket_server/deployment_spec.rb @@ -1,25 +1,25 @@ describe 'profiles::uitdatabank::websocket_server::deployment' do - context "with config_source => /foo.json" do - let(:params) { { - 'config_source' => '/foo.json' - } } + include_examples 'operating system support' - include_examples 'operating system support' + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) { facts } - on_supported_os.each do |os, facts| - context "on #{os}" do - let(:facts) { facts } + context 'with config_source => /foo.json' do + let(:params) { { + 'config_source' => '/foo.json' + } } it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('profiles::uitdatabank::websocket_server::deployment').with( - 'config_source' => '/foo.json', - 'version' => 'latest', - 'service_manage' => true, - 'service_ensure' => 'running', - 'service_enable' => true, - 'listen_port' => 3000, - 'puppetdb_url' => nil + 'config_source' => '/foo.json', + 'version' => 'latest', + 'repository' => 'uitdatabank-websocket-server', + 'service_status' => 'running', + 'service_address' => '127.0.0.1', + 'service_port' => 3000, + 'puppetdb_url' => nil ) } it { is_expected.to contain_apt__source('uitdatabank-websocket-server') } @@ -39,7 +39,7 @@ it { is_expected.to contain_file('uitdatabank-websocket-server-service-defaults').with( 'ensure' => 'file', 'path' => '/etc/default/uitdatabank-websocket-server', - 'content' => 'PORT=3000' + 'content' => "HOST=127.0.0.1\nPORT=3000" ) } it { is_expected.to contain_file('uitdatabank-websocket-server-config').that_requires('Package[uitdatabank-websocket-server]') } @@ -51,6 +51,8 @@ 'hasstatus' => true ) } + it { is_expected.to contain_package('uitdatabank-websocket-server').that_comes_before('File[uitdatabank-websocket-server-config]') } + it { is_expected.to contain_package('uitdatabank-websocket-server').that_comes_before('File[uitdatabank-websocket-server-service-defaults]') } it { is_expected.to contain_service('uitdatabank-websocket-server').that_subscribes_to('Package[uitdatabank-websocket-server]') } it { is_expected.to contain_service('uitdatabank-websocket-server').that_subscribes_to('File[uitdatabank-websocket-server-config]') } it { is_expected.to contain_service('uitdatabank-websocket-server').that_subscribes_to('File[uitdatabank-websocket-server-service-defaults]') } @@ -63,65 +65,56 @@ ) } end - context "with hieradata" do + context 'with hieradata' do let(:hiera_config) { 'spec/support/hiera/common.yaml' } it { is_expected.to contain_profiles__deployment__versions('profiles::uitdatabank::websocket_server::deployment').with( 'puppetdb_url' => 'http://localhost:8081' ) } end + end - context "with service_manage => false" do - let(:params) { - super().merge({ - 'service_manage' => false - } ) - } + context 'with repository uitdatabank-websocket-server-alternative defined' do + let(:pre_condition) { '@apt::source { "uitdatabank-websocket-server-alternative": location => "http://localhost", release => "focal", repos => "main" }' } - it { is_expected.not_to contain_file('uitdatabank-websocket-server-service-defaults') } - it { is_expected.not_to contain_service('uitdatabank-websocket-server') } - end - end - end - end + context 'with config_source => /bar.json, version => 1.2.3, repository => uitdatabank-websocket-server-alternative, service_address => 0.0.0.0, service_port => 5000, service_status => stopped and puppetdb_url => http://example.com:8000' do + let(:params) { { + 'config_source' => '/bar.json', + 'version' => '1.2.3', + 'repository' => 'uitdatabank-websocket-server-alternative', + 'service_status' => 'stopped', + 'service_address' => '0.0.0.0', + 'service_port' => 5000, + 'puppetdb_url' => 'http://example.com:8000' + } } - context "with config_source => /bar.json, version => 1.2.3, service_ensure => stopped, service_enable = false and puppetdb_url => http://example.com:8000" do - let(:params) { { - 'config_source' => '/bar.json', - 'version' => '1.2.3', - 'service_ensure' => 'stopped', - 'service_enable' => false, - 'puppetdb_url' => 'http://example.com:8000' - } } + it { is_expected.to contain_apt__source('uitdatabank-websocket-server-alternative') } - on_supported_os.each do |os, facts| - context "on #{os}" do - let(:facts) { facts } + it { is_expected.to contain_package('uitdatabank-websocket-server').with('ensure' => '1.2.3') } - it { is_expected.to contain_file('uitdatabank-websocket-server-config').with( - 'source' => '/bar.json', - ) } + it { is_expected.to contain_file('uitdatabank-websocket-server-config').with( + 'source' => '/bar.json', + ) } - it { is_expected.to contain_package('uitdatabank-websocket-server').with( 'ensure' => '1.2.3') } + it { is_expected.to contain_file('uitdatabank-websocket-server-service-defaults').with( + 'ensure' => 'file', + 'path' => '/etc/default/uitdatabank-websocket-server', + 'content' => "HOST=0.0.0.0\nPORT=5000" + ) } - it { is_expected.to contain_service('uitdatabank-websocket-server').with( - 'ensure' => 'stopped', - 'enable' => false - ) } + it { is_expected.to contain_service('uitdatabank-websocket-server').with( + 'ensure' => 'stopped', + 'enable' => false + ) } - it { is_expected.to contain_profiles__deployment__versions('profiles::uitdatabank::websocket_server::deployment').with( - 'puppetdb_url' => 'http://example.com:8000' - ) } + it { is_expected.to contain_profiles__deployment__versions('profiles::uitdatabank::websocket_server::deployment').with( + 'puppetdb_url' => 'http://example.com:8000' + ) } + end end - end - end - - context "without parameters" do - let(:params) { {} } - on_supported_os.each do |os, facts| - context "on #{os}" do - let(:facts) { facts } + context 'without parameters' do + let(:params) { {} } it { expect { catalogue }.to raise_error(Puppet::ParseError, /expects a value for parameter 'config_source'/) } end diff --git a/spec/classes/uitdatabank/websocket_server_spec.rb b/spec/classes/uitdatabank/websocket_server_spec.rb index cc27af3c..49f9ecbe 100644 --- a/spec/classes/uitdatabank/websocket_server_spec.rb +++ b/spec/classes/uitdatabank/websocket_server_spec.rb @@ -5,41 +5,103 @@ context "on #{os}" do let(:facts) { facts } - context "with hieradata" do - let(:hiera_config) { 'spec/support/hiera/common.yaml' } + context 'with servername => sockets.example.com' do + let(:params) { { + 'servername' => 'sockets.example.com' + } } - context "without parameters" do - let(:params) { {} } + context 'with hieradata' do + let(:hiera_config) { 'spec/support/hiera/common.yaml' } - it { is_expected.to compile.with_all_deps } + context 'without extra parameters' do + let(:params) { super().merge({}) } - it { is_expected.to contain_class('profiles::uitdatabank::websocket_server').with( - 'deployment' => true, - 'listen_port' => 3000 - ) } + it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_class('profiles::nodejs') } - it { is_expected.to contain_class('profiles::uitdatabank::websocket_server::deployment') } + it { is_expected.to contain_class('profiles::uitdatabank::websocket_server').with( + 'servername' => 'sockets.example.com', + 'serveraliases' => [], + 'deployment' => true, + 'service_address' => '127.0.0.1', + 'service_port' => 3000 + ) } - it { is_expected.to contain_class('profiles::uitdatabank::websocket_server::deployment').that_requires('Class[profiles::nodejs]') } - end + it { is_expected.to contain_group('www-data') } + it { is_expected.to contain_user('www-data') } + + it { is_expected.to contain_file('/var/www/udb3-websocket-server').with( + 'ensure' => 'directory', + 'owner' => 'www-data', + 'group' => 'www-data' + ) } + + it { is_expected.to contain_class('profiles::nodejs') } + it { is_expected.to contain_class('profiles::redis') } + + it { is_expected.to contain_class('profiles::uitdatabank::websocket_server::deployment').with( + 'service_address' => '127.0.0.1', + 'service_port' => 3000 + ) } + + it { is_expected.to contain_profiles__apache__vhost__reverse_proxy('http://sockets.example.com').with( + 'aliases' => [], + 'destination' => 'http://127.0.0.1:3000/', + 'support_websockets' => true + ) } + + it { is_expected.to contain_file('/var/www/udb3-websocket-server').that_requires('Group[www-data]') } + it { is_expected.to contain_file('/var/www/udb3-websocket-server').that_requires('User[www-data]') } + it { is_expected.to contain_class('profiles::uitdatabank::websocket_server::deployment').that_requires('Class[profiles::nodejs]') } + it { is_expected.to contain_class('profiles::uitdatabank::websocket_server::deployment').that_requires('Class[profiles::redis]') } + it { is_expected.to contain_class('profiles::uitdatabank::websocket_server::deployment').that_comes_before('Profiles::Apache::Vhost::Reverse_proxy[http://sockets.example.com]') } + end + + context 'with serveraliases => [foo.example.com, bar.example.com], service_address => 0.0.0.0 and service_port => 4000' do + let(:params) { super().merge({ + 'serveraliases' => ['foo.example.com', 'bar.example.com'], + 'service_address' => '0.0.0.0', + 'service_port' => 4000 + }) } - context "with deployment => false" do - let(:params) { { - 'deployment' => false - } } + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_class('profiles::uitdatabank::websocket_server::deployment').with( + 'service_address' => '0.0.0.0', + 'service_port' => 4000 + ) } + + it { is_expected.to contain_profiles__apache__vhost__reverse_proxy('http://sockets.example.com').with( + 'aliases' => ['foo.example.com', 'bar.example.com'], + 'destination' => 'http://0.0.0.0:4000/', + 'support_websockets' => true + ) } + end + + context 'with deployment => false' do + let(:params) { super().merge({ + 'deployment' => false + }) } + + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_class('profiles::nodejs') } + it { is_expected.to contain_class('profiles::redis') } + + it { is_expected.to_not contain_class('profiles::uitdatabank::websocket_server::deployment') } + end + end - it { is_expected.to compile.with_all_deps } + context 'without hieradata' do + let(:hiera_config) { 'spec/support/hiera/empty.yaml' } - it { is_expected.to contain_class('profiles::nodejs') } - it { is_expected.to_not contain_class('profiles::uitdatabank::websocket_server::deployment') } + it { expect { catalogue }.to raise_error(Puppet::ParseError, /expects a value for parameter 'config_source'/) } end end - context "without hieradata" do - let(:hiera_config) { 'spec/support/hiera/empty.yaml' } + context 'without parameters' do + let(:params) { {} } - it { expect { catalogue }.to raise_error(Puppet::ParseError, /expects a value for parameter 'config_source'/) } + it { expect { catalogue }.to raise_error(Puppet::ParseError, /expects a value for parameter 'servername'/) } end end end