Skip to content

Commit

Permalink
0.2.0: Add support for changing the directory we look at for sites files
Browse files Browse the repository at this point in the history
* Write nginx configuration instead of using nginx.conf from the deb
* Allow sites directory to be set via `node.nginx_passenger.sites_dir`
* Add initial serverspec tests
  • Loading branch information
Eric Richardson committed Jan 24, 2014
1 parent 66be8b7 commit 8536968
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.kitchen/
.kitchen.local.yml
.bundle
4 changes: 3 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ platforms:
suites:
- name: default
run_list: ["recipe[nginx_passenger]"]
attributes: {}
attributes:
nginx_passenger:
sites_dir: "/etc/nginx/sites"
2 changes: 1 addition & 1 deletion Berksfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"path": "."
},
"apt": {
"locked_version": "2.1.0"
"locked_version": "2.1.1"
}
}
}
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

gem 'berkshelf'
gem 'test-kitchen', '>= 1.1.1', :group => :integration
gem 'kitchen-vagrant', :group => :integration
gem 'serverspec'
gem 'busser-serverspec'
166 changes: 166 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.16)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
addressable (2.3.5)
akami (1.2.0)
gyoku (>= 0.4.0)
nokogiri (>= 1.4.0)
berkshelf (2.0.13)
activesupport (~> 3.2.0)
addressable (~> 2.3.4)
buff-shell_out (~> 0.1)
chozo (>= 0.6.1)
faraday (~> 0.8.0)
faraday (~> 0.8.5)
hashie (>= 2.0.2)
minitar (~> 0.5.4)
rbzip2 (~> 0.2.0)
retryable (~> 1.3.3)
ridley (~> 1.5.0)
solve (>= 0.5.0)
thor (~> 0.18.0)
buff-config (0.4.0)
buff-extensions (~> 0.3)
varia_model (~> 0.1)
buff-extensions (0.5.0)
buff-ignore (1.1.1)
buff-ruby_engine (0.1.0)
buff-shell_out (0.1.1)
buff-ruby_engine (~> 0.1.0)
builder (3.2.2)
busser (0.6.0)
thor
busser-serverspec (0.2.5)
busser
celluloid (0.14.1)
timers (>= 1.0.0)
celluloid-io (0.14.1)
celluloid (>= 0.14.1)
nio4r (>= 0.4.5)
chozo (0.6.1)
activesupport (>= 3.2.0)
hashie (>= 2.0.2)
multi_json (>= 1.3.0)
diff-lcs (1.2.5)
erubis (2.7.0)
faraday (0.8.9)
multipart-post (~> 1.2.0)
ffi (1.9.3)
gssapi (1.0.3)
ffi (>= 1.0.1)
gyoku (1.1.1)
builder (>= 2.1.2)
hashie (2.0.5)
highline (1.6.20)
hitimes (1.2.1)
httpclient (2.3.4.1)
httpi (0.9.7)
rack
i18n (0.6.9)
json (1.8.1)
kitchen-vagrant (0.14.0)
test-kitchen (~> 1.0)
little-plugger (1.1.3)
logging (1.8.1)
little-plugger (>= 1.1.3)
multi_json (>= 1.3.6)
mini_portile (0.5.2)
minitar (0.5.4)
mixlib-authentication (1.3.0)
mixlib-log
mixlib-log (1.6.0)
mixlib-shellout (1.3.0)
multi_json (1.8.4)
multipart-post (1.2.0)
net-http-persistent (2.9.1)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.7.0)
nio4r (1.0.0)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
nori (1.1.5)
rack (1.5.2)
rbzip2 (0.2.0)
retryable (1.3.4)
ridley (1.5.3)
addressable
buff-config (~> 0.2)
buff-extensions (~> 0.3)
buff-ignore (~> 1.1)
buff-shell_out (~> 0.1)
celluloid (~> 0.14.0)
celluloid-io (~> 0.14.0)
erubis
faraday (>= 0.8.4)
hashie (>= 2.0.2)
json (>= 1.7.7)
mixlib-authentication (>= 1.3.0)
net-http-persistent (>= 2.8)
net-ssh
nio4r (>= 0.5.0)
retryable
solve (>= 0.4.4)
varia_model (~> 0.1)
winrm (~> 1.1.0)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.7)
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
rubyntlm (0.1.1)
safe_yaml (0.9.7)
savon (0.9.5)
akami (~> 1.0)
builder (>= 2.1.2)
gyoku (>= 0.4.0)
httpi (~> 0.9)
nokogiri (>= 1.4.0)
nori (~> 1.0)
wasabi (~> 1.0)
serverspec (0.14.4)
highline
net-ssh
rspec (>= 2.13.0)
specinfra (>= 0.1.0)
solve (0.8.2)
specinfra (0.4.1)
test-kitchen (1.1.1)
mixlib-shellout (~> 1.2)
net-scp (~> 1.1)
net-ssh (~> 2.7)
safe_yaml (~> 0.9)
thor (~> 0.18)
thor (0.18.1)
timers (2.0.0)
hitimes
uuidtools (2.1.4)
varia_model (0.3.2)
buff-extensions (~> 0.2)
hashie (>= 2.0.2)
wasabi (1.0.0)
nokogiri (>= 1.4.0)
winrm (1.1.3)
gssapi (~> 1.0.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (~> 1.6, >= 1.6.1)
nokogiri (~> 1.5)
rubyntlm (~> 0.1.1)
savon (= 0.9.5)
uuidtools (~> 2.1.2)

PLATFORMS
ruby

DEPENDENCIES
berkshelf
busser-serverspec
kitchen-vagrant
serverspec
test-kitchen (>= 1.1.1)
3 changes: 3 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
default.nginx_passenger.sites_dir = "/etc/nginx/sites-enabled"
default.nginx_passenger.nginx_workers = 4

default.nginx_passenger.log_dir = "/var/log/nginx"
default.nginx_passenger.cert_dir = "/etc/nginx/certs"
default.nginx_passenger.ruby = "/usr/bin/ruby"
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
license "BSD"
description "Installs/Configures nginx and Passenger"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.0"
version "0.2.0"

depends "apt"
6 changes: 3 additions & 3 deletions providers/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
end

# -- Create nginx site file -- #

template "/etc/nginx/sites-enabled/#{new_resource.name}" do
template "#{node.nginx_passenger.sites_dir}/#{new_resource.name}" do
if new_resource.template
source new_resource.template
else
Expand Down Expand Up @@ -61,7 +61,7 @@

# -- Delete nginx site file -- #

file "/etc/nginx/sites-enabled/#{new_resource.name}" do
file "#{node.nginx_passenger.sites_dir}/#{new_resource.name}" do
action :delete
notifies :reload, "service[nginx]", :immediately
end
Expand Down
11 changes: 10 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@

# -- Install our config for Passenger -- #

template "/etc/nginx/conf.d/passenger.conf" do
template "/etc/nginx/nginx.conf" do
action :create
notifies :restart, "service[nginx]"
end

# -- Make sure sites directory exists -- #

directory node.nginx_passenger.sites_dir do
action :create
recursive true
owner "nginx"
mode 0755
end
66 changes: 66 additions & 0 deletions templates/default/nginx.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# THIS FILE IS MANAGED BY CHEF's nginx_passenger COOKBOOK.

user www-data;
worker_processes <%= node.nginx_passenger.nginx_workers %>;
pid /var/run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

# include /etc/nginx/naxsi_core.rules;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include <%= node.nginx_passenger.sites_dir %>/*;
}
13 changes: 13 additions & 0 deletions test/integration/default/serverspec/localhost/nginx_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "spec_helper"

# nginx should be running
describe service("nginx") do
it { should be_running }
end

# nginx config should point to the sites dir
describe file("/etc/nginx/nginx.conf") do
it { should be_file }
its(:content) { should include("include /etc/nginx/sites/*;") }
end

13 changes: 13 additions & 0 deletions test/integration/default/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'serverspec'

include SpecInfra::Helper::Exec
include SpecInfra::Helper::DetectOS

RSpec.configure do |c|
if ENV['ASK_SUDO_PASSWORD']
require 'highline/import'
c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
else
c.sudo_password = ENV['SUDO_PASSWORD']
end
end

0 comments on commit 8536968

Please sign in to comment.