capistrano3-nginx 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e858774c17cb8f1436362e15a348d7366e5bf4e4
4
+ data.tar.gz: a6e62a7b762d34b1ca9e87106e3d6fdfeb179b25
5
+ SHA512:
6
+ metadata.gz: f4c5331b8f735a1ae182f4d626ff95bff6b184c04001e38eedceeb9e5da677ea17c7f5450745ef3d059200a9a064796b15e1d2ed40b9d0bcd72106f6667ca984
7
+ data.tar.gz: 39e28e58d0e906acbf81c2fcac00e054f5ad2d578751121d273c41a30c7a2d9579dbbfbb5a45cb8276092fe86980bf459bcffa0aebf694696e583155dfc0deb3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-bundler.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Capistrano, your one stop deployment shop.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 platanus
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # Capistrano::Nginx [![Gem Version](https://badge.fury.io/rb/capistrano3-nginx.png)](http://badge.fury.io/rb/capistrano3-nginx)
2
+
3
+ Nginx support for Capistrano 3.x
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano3-nginx'
10
+ gem 'capistrano'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install capistrano-nginx
19
+
20
+ ## Usage
21
+
22
+ Require in `Capfile` to use the default task:
23
+
24
+ ```ruby
25
+ require 'capistrano/nginx'
26
+ ```
27
+
28
+ You will get the following tasks
29
+
30
+ ```ruby
31
+ cap nginx:start # Start nginx service
32
+ cap nginx:stop # Stop nginx service
33
+ cap nginx:reload # Reload nginx service
34
+ cap nginx:restart # Restart nginx service
35
+ cap nginx:site:add # Creates the site configuration and upload it to the available folder
36
+ cap nginx:site:disable # Disables the site removing the symbolic link located in the enabled folder
37
+ cap nginx:site:enable # Enables the site creating a symbolic link into the enabled folder
38
+ cap nginx:site:remove # Removes the site removing the configuration file from the available folder
39
+ ```
40
+
41
+ Configurable options, shown here with examples:
42
+
43
+ ```ruby
44
+ # Server name for nginx
45
+ # No default vaue
46
+ set :nginx_domains, "foo.bar.com"
47
+
48
+ # Roles the deploy nginx site on,
49
+ # default value: :web
50
+ set :nginx_roles, :web
51
+
52
+ # Path, where nginx log file will be stored
53
+ # default value: "#{shared_path}/log"
54
+ set :nginx_log_path, "#{shared_path}/log"
55
+
56
+ # Path where nginx is installed
57
+ # default value: "/etc/nginx"
58
+ set :nginx_root_path, "/etc/nginx"
59
+
60
+ # Path where nginx available site are stored
61
+ # default value: "sites-available"
62
+ set :nginx_sites_available, "sites-available"
63
+
64
+ # Path where nginx available site are stored
65
+ # default value: "sites-enabled"
66
+ set :nginx_sites_enabled, "sites-enabled"
67
+
68
+ # Path to look for custom config template
69
+ # default value: "config/deploy/#{stage}/nginx.conf.erb"
70
+ set :nginx_template, "config/deploy/#{stage}/nginx.conf.erb"
71
+
72
+ # Use ssl on port 443 to serve on https. Every request to por 80
73
+ # will be rewritten to 443
74
+ # default value: false
75
+ set :nginx_use_ssl, false
76
+
77
+ # Whether you want to server an application through a proxy pass
78
+ # default value: true
79
+ set :app_server, true
80
+
81
+ # Socket file that nginx will use as upstream to serve the application
82
+ # Note: Socket upstream has priority over host:port upstreams
83
+ # no default value
84
+ set :app_server_socket, "#{shared_path}/sockets/#{application}.sock"
85
+
86
+ # The host that nginx will use as upstream to server the application
87
+ # default value: 127.0.0.1
88
+ set :app_server_port,
89
+
90
+ # The port the application server is running on
91
+ # no default value
92
+ set :app_server_host,
93
+ ```
94
+
95
+ ## Thanks
96
+ Thansk for the inspiration on several nginx recipes out there
97
+
98
+ ## Contributing
99
+
100
+ 1. Fork it
101
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
102
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
103
+ 4. Push to the branch (`git push origin my-new-feature`)
104
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'capistrano3-nginx'
7
+ spec.version = '1.0.0'
8
+ spec.authors = ['Juan Ignacio Donoso']
9
+ spec.email = ['jidonoso@gmail.com']
10
+ spec.description = %q{Adds suuport to nginx for Capistrano 3.x}
11
+ spec.summary = %q{Adds suuport to nginx for Capistrano 3.x}
12
+ spec.homepage = 'https://github.com/platanus/capistrano3-nginx'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'capistrano', '>= 3.0.0'
21
+
22
+ spec.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/nginx.rake', __FILE__)
@@ -0,0 +1,89 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :nginx_roles, -> { :web }
4
+ set :nginx_log_path, -> { "#{shared_path}/log" }
5
+ set :nginx_root_path, -> { "/etc/nginx" }
6
+ set :nginx_sites_enabled, -> { "sites-enabled" }
7
+ set :nginx_sites_available, -> { "sites-available" }
8
+ set :nginx_template, -> { "config/deploy/#{fetch(:stage)}/nginx.conf.erb" }
9
+ set :nginx_use_ssl, -> { false }
10
+ set :app_server, -> { true }
11
+ end
12
+ end
13
+
14
+ namespace :nginx do
15
+ task :load_vars do
16
+ set :sites_available, -> { File.join(fetch(:nginx_root_path), fetch(:nginx_sites_available)) }
17
+ set :sites_enabled, -> { File.join(fetch(:nginx_root_path), fetch(:nginx_sites_enabled)) }
18
+ set :enabled_application, -> { File.join(fetch(:sites_enabled), fetch(:application)) }
19
+ set :available_application, -> { File.join(fetch(:sites_available), fetch(:application)) }
20
+ end
21
+
22
+ %w[start stop restart reload].each do |command|
23
+ desc "#{command.capitalize} nginx service"
24
+ task command do
25
+ on release_roles fetch(:nginx_roles) do
26
+ if command === 'stop' || (test "sudo nginx -t")
27
+ execute :sudo, "service nginx #{command}"
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ after 'deploy:check', nil do
34
+ on release_roles fetch(:nginx_roles) do
35
+ execute :mkdir, '-pv', fetch(:nginx_log_path)
36
+ end
37
+ end
38
+
39
+ namespace :site do
40
+ desc 'Creates the site configuration and upload it to the available folder'
41
+ task :add => ['nginx:load_vars'] do
42
+ on release_roles fetch(:nginx_roles) do
43
+ within fetch(:sites_available) do
44
+ config_file = fetch(:nginx_template)
45
+ unless File.exists?(config_file)
46
+ config_file = File.expand_path('../../../../templates/nginx.conf.erb', __FILE__)
47
+ end
48
+ config = ERB.new(File.read(config_file)).result(binding)
49
+ upload! StringIO.new(config), '/tmp/nginx.conf'
50
+
51
+ execute :mv, '/tmp/nginx.conf', fetch(:application)
52
+ end
53
+ end
54
+ end
55
+
56
+ desc 'Enables the site creating a symbolic link into the enabled folder'
57
+ task :enable => ['nginx:load_vars'] do
58
+ on release_roles fetch(:nginx_roles) do
59
+ if test "! [ -h #{fetch(:enabled_application)} ]"
60
+ within fetch(:sites_enabled) do
61
+ execute :ln, '-nfs', fetch(:available_application), fetch(:enabled_application)
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ desc 'Disables the site removing the symbolic link located in the enabled folder'
68
+ task :disable => ['nginx:load_vars'] do
69
+ on release_roles fetch(:nginx_roles) do
70
+ if test "[ -f #{fetch(:enabled_application)} ]"
71
+ within fetch(:sites_enabled) do
72
+ execute :rm, '-f', fetch(:application)
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ desc 'Removes the site removing the configuration file from the available folder'
79
+ task :remove => ['nginx:load_vars'] do
80
+ on release_roles fetch(:nginx_roles) do
81
+ if test "[ -f #{fetch(:available_application)} ]"
82
+ within fetch(:sites_available) do
83
+ execute :rm, fetch(:application)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
File without changes
@@ -0,0 +1,68 @@
1
+ <% if fetch(:app_server) && (fetch(:app_server_socket) || fetch(:app_server_port))%>
2
+ # Define App Server Upstream
3
+ upstream <%= fetch(:application) %>-app-server {
4
+ <% if fetch(:app_server_socket) %>
5
+ server unix:<%= fetch(:app_server_socket) %> fail_timeout=0;
6
+ <% elsif fetch(:app_server_port) %>
7
+ server <%= fetch(:app_server_host, '127.0.0.1') %>:<%= fetch(:app_server_port) %> fail_timeout=0;
8
+ <% end %>
9
+ }
10
+ <% end %>
11
+
12
+ # HTTP Server
13
+
14
+ <% if fetch(:nginx_use_ssl) %>
15
+ server {
16
+ listen 80;
17
+ rewrite ^(.*) https://$host$1 permanent;
18
+ }
19
+ <% end %>
20
+
21
+ server {
22
+
23
+ <% if fetch(:nginx_use_ssl) %>
24
+ listen 443;
25
+ ssl on;
26
+ ssl_certificate /etc/ssl/certs/<%= nginx_ssl_certificate %>;
27
+ ssl_certificate_key /etc/ssl/private/<%= nginx_ssl_certificate_key %>;
28
+ <% else %>
29
+ listen 80;
30
+ <% end %>
31
+
32
+ server_name <%= fetch(:nginx_domains) %>;
33
+ root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>;
34
+
35
+ access_log <%= fetch(:nginx_log_path) %>/nginx-access.log;
36
+ error_log <%= fetch(:nginx_log_path) %>/nginx-error.log;
37
+
38
+ error_page 404 /404.html;
39
+ location /404.html { root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; }
40
+
41
+ error_page 500 /500.html;
42
+ location /500.html { root <%= fetch (:deploy_to) %>/current/<%= fetch(:static_dir) %>; }
43
+
44
+ client_max_body_size 4G;
45
+ keepalive_timeout 10;
46
+
47
+ <% if fetch(:app_server) && (fetch(:app_server_socket) || fetch(:app_server_port))%>
48
+ location ^~ /assets/ {
49
+ gzip_static on;
50
+ expires max;
51
+ add_header Cache-Control public;
52
+ }
53
+
54
+ try_files $uri/index.html $uri @<%= fetch(:application) %>-app-server;
55
+
56
+ location @<%= fetch(:application) %>-app-server {
57
+ proxy_set_header X-Real-IP $remote_addr;
58
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
59
+ proxy_set_header X-FORWARDED_PROTO http;
60
+ proxy_set_header Host $http_host;
61
+ <% if fetch(:nginx_use_ssl) %>
62
+ proxy_set_header X-Forwarded-Proto https;
63
+ <% end %>
64
+ proxy_redirect off;
65
+ proxy_pass http://<%= fetch(:application) %>-app-server;
66
+ }
67
+ <% end %>
68
+ }
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano3-nginx
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Ignacio Donoso
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Adds suuport to nginx for Capistrano 3.x
42
+ email:
43
+ - jidonoso@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - LICENSE
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - capistrano3-nginx.gemspec
54
+ - lib/capistrano/nginx.rb
55
+ - lib/capistrano/tasks/nginx.rake
56
+ - lib/capistrano3-nginx.rb
57
+ - templates/nginx.conf.erb
58
+ homepage: https://github.com/platanus/capistrano3-nginx
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.14
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Adds suuport to nginx for Capistrano 3.x
82
+ test_files: []