Skip to content

Commit 7271c9d

Browse files
committed
fix(passenger): various fixes
* correctly set dependencies in configuration * update RPM repo key * add tests for passenger installation as nginx module * update test matrix
1 parent b396b24 commit 7271c9d

File tree

14 files changed

+270
-11
lines changed

14 files changed

+270
-11
lines changed

.yamllint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ignore: |
1414
.cache/
1515
.git/
1616
node_modules/
17-
test/**/states/**/*.sls
17+
test/salt/**/*.sls
1818
.kitchen/
1919
2020
yaml-files:

nginx/map.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'Debian': {
1010
'package': 'nginx',
1111
'passenger_package': 'passenger',
12-
'passenger_config_file': '/etc/nginx/conf.d/passenger.conf',
12+
'passenger_config_file': '/etc/nginx/conf.d/mod-http-passenger.conf',
1313
'service': 'nginx',
1414
'webuser': 'www-data',
1515
'conf_file': '/etc/nginx/nginx.conf',

nginx/passenger.sls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ passenger_install:
2525
- pkg: nginx_install
2626
- require_in:
2727
- service: nginx_service
28+
- file: nginx_config
2829
2930
/etc/nginx/passenger.conf:
3031
file.absent:
@@ -46,6 +47,7 @@ passenger_config:
4647
- service: nginx_service
4748
- require_in:
4849
- service: nginx_service
50+
- file: nginx_config
4951
- require:
5052
- file: /etc/nginx/passenger.conf
5153
- pkg: passenger_install

nginx/pkg.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ nginx_phusionpassenger_yum_repo:
163163
- baseurl: 'https://oss-binaries.phusionpassenger.com/yum/passenger/el/$releasever/$basearch'
164164
- repo_gpgcheck: 1
165165
- gpgcheck: 0
166-
- gpgkey: 'https://packagecloud.io/gpg.key'
166+
- gpgkey: 'https://oss-binaries.phusionpassenger.com/yum/definitions/RPM-GPG-KEY.asc'
167167
- enabled: True
168168
- sslverify: 1
169169
- sslcacert: /etc/pki/tls/certs/ca-bundle.crt

nginx/snippets.sls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ nginx_snippet_{{ snippet }}:
2828
- context:
2929
config: {{ config|json() }}
3030
nginx: {{ _nginx|json() }}
31+
- require:
32+
- file: nginx_snippets_dir
33+
- require_in:
34+
- file: nginx_config
35+
- service: nginx_service
3136
{% endfor %}

test/integration/default/controls/config.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# frozen_string_literal: true
2+
13
# Set defaults, use debian as base
24

35
server_available = '/etc/nginx/sites-available'
4-
server_enabled = '/etc/nginx/sites-enabled'
6+
server_enabled = '/etc/nginx/sites-enabled'
57

68
# Override by platform family
79
case platform[:family]
@@ -22,9 +24,13 @@
2224
it { should be_owned_by 'root' }
2325
it { should be_grouped_into 'root' }
2426
its('mode') { should cmp '0644' }
25-
its('content') { should include %Q[ log_format main '$remote_addr - $remote_user [$time_local] $status '
27+
its('content') do
28+
# rubocop:disable Metrics/LineLength
29+
should include %( log_format main '$remote_addr - $remote_user [$time_local] $status '
2630
'"$request" $body_bytes_sent "$http_referer" '
27-
'"$http_user_agent" "$http_x_forwarded_for"';] }
31+
'"$http_user_agent" "$http_x_forwarded_for"';)
32+
# rubocop:enable Metrics/LineLength
33+
end
2834
end
2935

3036
# snippets configuration
@@ -40,12 +46,11 @@
4046

4147
# sites configuration
4248
[server_available, server_enabled].each do |dir|
43-
44-
describe file ("#{dir}/default") do
45-
it { should_not exist }
49+
describe file "#{dir}/default" do
50+
it { should_not exist }
4651
end
4752

48-
describe file ("#{dir}/mysite") do
53+
describe file "#{dir}/mysite" do
4954
it { should be_file }
5055
it { should be_owned_by 'root' }
5156
it { should be_grouped_into 'root' }
@@ -57,6 +62,5 @@
5762
its('content') { should include 'try_files $uri $uri/ =404;' }
5863
its('content') { should include 'include snippets/letsencrypt.conf;' }
5964
end
60-
6165
end
6266
end

test/integration/default/controls/install.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
control 'Nginx package' do
24
title 'should be installed'
35

test/integration/default/controls/service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
control 'Nginx service' do
24
title 'should be running and enabled'
35

test/integration/passenger/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# InSpec Profile: `passenger`
2+
3+
This shows the implementation of the `passenger` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md).
4+
5+
## Verify a profile
6+
7+
InSpec ships with built-in features to verify a profile structure.
8+
9+
```bash
10+
$ inspec check passenger
11+
Summary
12+
-------
13+
Location: passenger
14+
Profile: profile
15+
Controls: 4
16+
Timestamp: 2019-06-24T23:09:01+00:00
17+
Valid: true
18+
19+
Errors
20+
------
21+
22+
Warnings
23+
--------
24+
```
25+
26+
## Execute a profile
27+
28+
To run all **supported** controls on a local machine use `inspec exec /path/to/profile`.
29+
30+
```bash
31+
$ inspec exec passenger
32+
..
33+
34+
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
35+
8 examples, 0 failures
36+
```
37+
38+
## Execute a specific control from a profile
39+
40+
To run one control from the profile use `inspec exec /path/to/profile --controls name`.
41+
42+
```bash
43+
$ inspec exec passenger --controls package
44+
.
45+
46+
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
47+
1 examples, 0 failures
48+
```
49+
50+
See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb).
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# frozen_string_literal: true
2+
3+
# Set defaults, use debian as base
4+
5+
# Override by OS Family
6+
case platform[:family]
7+
when 'redhat', 'centos', 'fedora'
8+
server_available = '/etc/nginx/conf.d'
9+
server_enabled = '/etc/nginx/conf.d'
10+
passenger_mod = '/usr/lib64/nginx/modules/ngx_http_passenger_module.so'
11+
passenger_root = '/usr/share/ruby/vendor_ruby/phusion_passenger/locations.ini'
12+
passenger_config_file = '/etc/nginx/conf.d/passenger.conf'
13+
should_not_exist_file = '/etc/nginx/conf.d/mod-http-passenger.conf'
14+
when 'debian', 'ubuntu'
15+
server_available = '/etc/nginx/sites-available'
16+
server_enabled = '/etc/nginx/sites-enabled'
17+
passenger_mod = '/usr/lib/nginx/modules/ngx_http_passenger_module.so'
18+
passenger_root = '/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini'
19+
passenger_config_file = '/etc/nginx/conf.d/mod-http-passenger.conf'
20+
should_not_exist_file = '/etc/nginx/conf.d/passenger.conf'
21+
end
22+
23+
control 'Passenger configuration' do
24+
title 'should match desired lines'
25+
26+
# main configuration
27+
describe file('/etc/nginx/nginx.conf') do
28+
its('content') { should include "load_module #{passenger_mod}" }
29+
end
30+
31+
describe file(passenger_config_file) do
32+
it { should be_file }
33+
it { should be_owned_by 'root' }
34+
it { should be_grouped_into 'root' }
35+
its('mode') { should cmp '0644' }
36+
its('content') { should include "passenger_root #{passenger_root};" }
37+
its('content') { should include 'passenger_ruby /usr/bin/ruby;' }
38+
end
39+
40+
describe file(should_not_exist_file) do
41+
it { should_not exist }
42+
end
43+
44+
# sites configuration
45+
[server_available, server_enabled].each do |dir|
46+
describe file "#{dir}/default" do
47+
it { should_not exist }
48+
end
49+
50+
describe file "#{dir}/mysite" do
51+
it { should be_file }
52+
it { should be_owned_by 'root' }
53+
it { should be_grouped_into 'root' }
54+
its('mode') { should cmp '0644' }
55+
its('content') { should include 'passenger_enabled on;' }
56+
end
57+
end
58+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
control 'Nginx package' do
4+
title 'should be installed'
5+
6+
describe package('nginx') do
7+
it { should be_installed }
8+
end
9+
end
10+
11+
control 'Passenger packages' do
12+
title 'should be installed'
13+
14+
# Override by OS Family
15+
passenger_mod_pkg = case platform[:family]
16+
when 'redhat', 'centos', 'fedora'
17+
'nginx-mod-http-passenger'
18+
when 'debian', 'ubuntu'
19+
'libnginx-mod-http-passenger'
20+
end
21+
22+
describe package('passenger') do
23+
it { should be_installed }
24+
end
25+
describe package(passenger_mod_pkg) do
26+
it { should be_installed }
27+
end
28+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
control 'Nginx service' do
4+
title 'should be running and enabled'
5+
6+
describe service('nginx') do
7+
it { should be_enabled }
8+
it { should be_running }
9+
end
10+
end
11+
12+
control 'Passenger module' do
13+
title 'should be running and enabled'
14+
15+
describe 'Passenger engine' do
16+
it 'passenger-config should say configuration "looks good"' do
17+
expect(command(
18+
'/usr/bin/passenger-config validate-install --auto'
19+
).stdout).to match(/looks good/)
20+
end
21+
22+
it 'passenger-memory-stats should return Passenger stats' do
23+
expect(command('/usr/sbin/passenger-memory-stats').stdout).to match(
24+
%r{nginx: master process /usr/sbin/nginx.*Passenger watchdog.*Passenger core.*}m
25+
)
26+
end
27+
end
28+
end

test/integration/passenger/inspec.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: default
5+
title: nginx formula
6+
maintainer: SaltStack Formulas
7+
license: Apache-2.0
8+
summary: Verify that the nginx formula is setup and configured correctly
9+
supports:
10+
- platform-name: debian
11+
- platform-name: ubuntu
12+
- platform-name: centos

test/salt/passenger/pillar/nginx.sls

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
# Simple pillar setup
5+
# - snippet letsencrypt
6+
# - remove 'default' site
7+
# - create 'mysite' site
8+
9+
{%- if grains.os_family in ('RedHat',) %}
10+
{%- set passenger_pkg = 'nginx-mod-http-passenger' %}
11+
{%- set passenger_mod = '/usr/lib64/nginx/modules/ngx_http_passenger_module.so' %}
12+
{%- else %}
13+
{%- set passenger_pkg = 'libnginx-mod-http-passenger' %}
14+
{%- set passenger_mod = '/usr/lib/nginx/modules/ngx_http_passenger_module.so' %}
15+
{%- endif %}
16+
17+
nginx:
18+
check_config_before_apply: true
19+
20+
install_from_phusionpassenger: true
21+
lookup:
22+
passenger_package: {{ passenger_pkg }}
23+
24+
snippets:
25+
letsencrypt.conf:
26+
- location ^~ /.well-known/acme-challenge/:
27+
- proxy_pass: http://localhost:9999
28+
server:
29+
30+
config:
31+
# This is required to get the passenger module loaded
32+
# In Debian it can be done with this
33+
# include: 'modules-enabled/*.conf'
34+
load_module: {{ passenger_mod }}
35+
36+
worker_processes: 4
37+
http:
38+
### module ngx_http_log_module example
39+
log_format: |-
40+
main '$remote_addr - $remote_user [$time_local] $status '
41+
'"$request" $body_bytes_sent "$http_referer" '
42+
'"$http_user_agent" "$http_x_forwarded_for"'
43+
include:
44+
- /etc/nginx/mime.types
45+
- /etc/nginx/conf.d/*.conf
46+
- /etc/nginx/sites-enabled/*
47+
48+
servers:
49+
managed:
50+
default:
51+
deleted: true
52+
enabled: false
53+
config: {}
54+
55+
mysite:
56+
enabled: true
57+
config:
58+
- server:
59+
- passenger_enabled: 'on'
60+
61+
- server_name: localhost
62+
- listen:
63+
- '80 default_server'
64+
- index: 'index.html index.htm'
65+
- location ~ .htm:
66+
- try_files: '$uri $uri/ =404'
67+
# - include: '/etc/nginx/snippets/letsencrypt.conf'
68+
- include: 'snippets/letsencrypt.conf'

0 commit comments

Comments
 (0)