Skip to content
This repository has been archived by the owner on Apr 23, 2019. It is now read-only.

Feature/gzip support #158

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ GEM
mixlib-config (2.1.0)
mixlib-log (1.6.0)
mixlib-shellout (1.4.0)
multi_json (1.10.1)
multipart-post (2.0.0)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
net-ssh (2.9.2)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
net-ssh-multi (1.2.0)
Expand Down Expand Up @@ -120,28 +121,29 @@ GEM
faraday
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-core (3.0.4)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.4)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-its (1.0.1)
rspec-core (>= 2.99.0.beta1)
rspec-expectations (>= 2.99.0.beta1)
rspec-mocks (3.0.4)
rspec-support (~> 3.0.0)
rspec-support (3.0.4)
rspec-support (~> 3.1.0)
rspec-its (1.1.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
safe_yaml (1.0.4)
serverspec (2.0.1)
rspec (~> 3.0.0)
serverspec (2.7.1)
multi_json
rspec (~> 3.0)
rspec-its
specinfra (~> 2.0)
specinfra (~> 2.10)
slop (3.6.0)
specinfra (2.0.2)
specinfra (2.11.3)
net-scp
net-ssh
systemu (2.6.4)
Expand Down
3 changes: 2 additions & 1 deletion nodes/sample_host.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"username": "<db username, max 10 characters>",
"password": "<enter a random password>",
"database": "<appname>_<stage>"
}
},
"gzip_enabled": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to have the sample default to false? Since people do have to perform some task on their rails apps to make this work

}
}
}
8 changes: 8 additions & 0 deletions test/integration/full-stack/serverspec/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@
end

end

describe file("/etc/nginx/sites-available/intercity_sample_app.conf") do
it { should be_file }

its(:content) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you but a context block around this? so it tells a bit more about what you're testing. So you get something like:

describe file("/etc/nginx/sites-available/intercity_sample_app.conf") do
  it { should be_file }

  context "GZip support enabled" do
    its(:content) do
      should match /location ~ \^\/\(assets\)\/.*gzip_static on;/m
    end
  end
end

should match /location ~ \^\/\(assets\)\/.*gzip_static on;/m
end
end
4 changes: 3 additions & 1 deletion vendor/cookbooks/rails/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@
domain_names: app_info["domain_names"],
redirect_domain_names: app_info["redirect_domain_names"],
enable_ssl: File.exists?("#{applications_root}/#{app}/shared/config/certificate.crt"),
custom_configuration: nginx_custom_configuration(app_info))
custom_configuration: nginx_custom_configuration(app_info),
gzip_enabled: app_info["gzip_enabled"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make sure that app_info["gzip_enabled"] has a default value in vendor/cookbooks/rails/attributed/default.rb?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess not, since app_info is an application config read from rails cookbook config. There could be more then one application per node config:

35   "active_applications": {
36     "<appname>_<stage>": {
...
57       "gzip_enabled": false
58     }
59  }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, good point. What about .fetch? and give false as default?

)
notifies :reload, resources(service: "nginx")
end

Expand Down
4 changes: 3 additions & 1 deletion vendor/cookbooks/rails/recipes/passenger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@
rails_env: rails_env,
domain_names: app_info["domain_names"],
enable_ssl: File.exists?("#{applications_root}/#{app}/shared/config/certificate.crt"),
custom_configuration: nginx_custom_configuration(app_info))
custom_configuration: nginx_custom_configuration(app_info),
gzip_enabled: app_info["gzip_enabled"]
)
notifies :reload, resources(:service => "nginx")
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
location ~ ^/(assets)/ {
root <%= @server_root_public_path %>;
gzip_static on;
expires max;
add_header Cache-Control public;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking here, but the } is not placed correctly yet ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I've got some issues with rendering partials, the first line is always shifted 2 spaces right

Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<% server_root_public_path = "#{node['rails']['applications_root']}/#{@name}/current/public" %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to set this from the recipe instead of in the template? Somehow this feels a little hacky


<%= @custom_configuration["before_server"] %>

server {
listen <%= node['nginx']['port'] || '80' %>;
server_name <%= @domain_names.join(' ') %>;
root <%= node['rails']['applications_root'] %>/<%= @name %>/current/public;
root <%= server_root_public_path %>;

passenger_enabled on;
passenger_app_env <%= @rails_env %>;

<%= render '_app_nginx_location_assets.erb', variables: { server_root_public_path: server_root_public_path } if @gzip_enabled %>

<%= @custom_configuration["server_main"] %>
}

Expand All @@ -23,7 +28,10 @@ server {

server_name <%= @domain_names.join(' ') %>;

root <%= node['rails']['applications_root'] %>/<%= @name %>/current/public;
root <%= server_root_public_path %>;

<%= render '_app_nginx_location_assets.erb', variables: { server_root_public_path: server_root_public_path } if @gzip_enabled %>

<%= @custom_configuration["ssl_main"] %>
}

Expand Down