diff --git a/.gitignore b/.gitignore index 82d1b5c..e88341f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .kitchen/ -.kitchen.local.yml +.bundle diff --git a/.kitchen.yml b/.kitchen.yml index b81ec15..e542992 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -12,4 +12,6 @@ platforms: suites: - name: default run_list: ["recipe[nginx_passenger]"] - attributes: {} + attributes: + nginx_passenger: + sites_dir: "/etc/nginx/sites" diff --git a/Berksfile.lock b/Berksfile.lock index b027e67..d7ff433 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -4,7 +4,7 @@ "path": "." }, "apt": { - "locked_version": "2.1.0" + "locked_version": "2.1.1" } } } diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..87d3126 --- /dev/null +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..26c7086 --- /dev/null +++ b/Gemfile.lock @@ -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) diff --git a/attributes/default.rb b/attributes/default.rb index 2e94958..0567f3a 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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" diff --git a/metadata.rb b/metadata.rb index 7372904..38ac061 100644 --- a/metadata.rb +++ b/metadata.rb @@ -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" \ No newline at end of file diff --git a/providers/site.rb b/providers/site.rb index e5006a7..aba44fa 100644 --- a/providers/site.rb +++ b/providers/site.rb @@ -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 @@ -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 diff --git a/recipes/default.rb b/recipes/default.rb index c034666..f634314 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -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 \ No newline at end of file diff --git a/templates/default/nginx.conf.erb b/templates/default/nginx.conf.erb new file mode 100644 index 0000000..ac3cadf --- /dev/null +++ b/templates/default/nginx.conf.erb @@ -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 %>/*; +} \ No newline at end of file diff --git a/test/integration/default/serverspec/localhost/nginx_spec.rb b/test/integration/default/serverspec/localhost/nginx_spec.rb new file mode 100644 index 0000000..d954385 --- /dev/null +++ b/test/integration/default/serverspec/localhost/nginx_spec.rb @@ -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 + diff --git a/test/integration/default/serverspec/spec_helper.rb b/test/integration/default/serverspec/spec_helper.rb new file mode 100644 index 0000000..65a599a --- /dev/null +++ b/test/integration/default/serverspec/spec_helper.rb @@ -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