capistrano3-nginx 2.1.6 → 3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +34 -0
- data/README.md +20 -25
- data/capistrano3-nginx.gemspec +6 -6
- data/lib/capistrano/nginx.rb +56 -1
- data/lib/capistrano/nginx/version.rb +3 -0
- data/lib/capistrano/tasks/nginx.rake +16 -49
- data/templates/nginx.conf.erb +2 -1
- metadata +14 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0d880cf04051698b7c32f78b7ec8d5337f816d0
|
4
|
+
data.tar.gz: 5f9b93d7b67b921316bb62f89939d4da293ab0e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61bdfff4b8698afc094168a0b48fa661f7632fa8d2510d4f38f37d8306e5a28ffd11b43ef55b4c61014fd711c42e4ab67f404fb358ffd69fe68d8fbcca47993d
|
7
|
+
data.tar.gz: 4db79ae2fcbcf70730f4959f92e4fc48f7e25d449418cc89209be2d69f8cf3483b6334b35f4df5d6e37cc114efa2af75950302b9d6a61a588744398be1bdd009
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
capistrano3-nginx (2.2)
|
5
|
+
capistrano (>= 3.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
airbrussh (1.1.2)
|
11
|
+
sshkit (>= 1.6.1, != 1.7.0)
|
12
|
+
capistrano (3.8.0)
|
13
|
+
airbrussh (>= 1.0.0)
|
14
|
+
i18n
|
15
|
+
rake (>= 10.0.0)
|
16
|
+
sshkit (>= 1.9.0)
|
17
|
+
i18n (0.8.6)
|
18
|
+
net-scp (1.2.1)
|
19
|
+
net-ssh (>= 2.6.5)
|
20
|
+
net-ssh (4.1.0)
|
21
|
+
rake (12.3.0)
|
22
|
+
sshkit (1.12.0)
|
23
|
+
net-scp (>= 1.1.2)
|
24
|
+
net-ssh (>= 2.8.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
capistrano3-nginx!
|
31
|
+
rake
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
1.16.1
|
data/README.md
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
# Capistrano::Nginx [![Gem Version](https://badge.fury.io/rb/capistrano3-nginx.svg)](http://badge.fury.io/rb/capistrano3-nginx)
|
2
1
|
|
3
|
-
Nginx support for Capistrano 3.x
|
2
|
+
Nginx support for Capistrano 3.x, with sudo password prompt
|
4
3
|
|
5
4
|
## Installation
|
6
5
|
|
7
6
|
Add this line to your application's Gemfile:
|
8
7
|
|
9
|
-
gem 'capistrano3-nginx', '~>
|
10
|
-
|
8
|
+
gem 'capistrano3-nginx', '~> 3.0'
|
9
|
+
|
11
10
|
|
12
11
|
And then execute:
|
13
12
|
|
@@ -23,8 +22,23 @@ Require in `Capfile` to use the default task:
|
|
23
22
|
|
24
23
|
```ruby
|
25
24
|
require 'capistrano/nginx'
|
25
|
+
install_plugin Capistrano::Nginx
|
26
|
+
```
|
27
|
+
|
28
|
+
Make sure pty is enabled in deploy.rb
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
set :pty, true
|
26
32
|
```
|
27
33
|
|
34
|
+
Make sure server has sudo role
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
server 'example.com',
|
38
|
+
user: 'with_sudo_access',
|
39
|
+
roles: %w{sudo}
|
40
|
+
```
|
41
|
+
|
28
42
|
You will get the following tasks
|
29
43
|
|
30
44
|
```ruby
|
@@ -68,8 +82,8 @@ set :nginx_redirected_domains, "bar.com other.com"
|
|
68
82
|
set :nginx_service_path, "/etc/init.d/nginx"
|
69
83
|
|
70
84
|
# Roles the deploy nginx site on,
|
71
|
-
# default value: :
|
72
|
-
set :nginx_roles, :
|
85
|
+
# default value: :sudo
|
86
|
+
set :nginx_roles, :sudo
|
73
87
|
|
74
88
|
# Path, where nginx log file will be stored
|
75
89
|
# default value: "#{shared_path}/log"
|
@@ -142,22 +156,3 @@ set :app_server_port, 8080
|
|
142
156
|
## Thanks
|
143
157
|
Thansk for the inspiration on several nginx recipes out there
|
144
158
|
|
145
|
-
## Contributing
|
146
|
-
|
147
|
-
1. Fork it
|
148
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
149
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
150
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
151
|
-
5. Create new Pull Request
|
152
|
-
|
153
|
-
## Credits
|
154
|
-
|
155
|
-
Thank you [contributors](https://github.com/platanus/guides/graphs/contributors)!
|
156
|
-
|
157
|
-
<img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
|
158
|
-
|
159
|
-
capistrano3-nginx is maintained by [platanus](http://platan.us).
|
160
|
-
|
161
|
-
## License
|
162
|
-
|
163
|
-
Guides is © 2014 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
|
data/capistrano3-nginx.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/nginx/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |spec|
|
6
7
|
spec.name = 'capistrano3-nginx'
|
7
|
-
spec.version =
|
8
|
-
spec.authors = ['Juan Ignacio Donoso']
|
9
|
-
spec.email = ['jidonoso@gmail.com']
|
8
|
+
spec.version = Capistrano::NGINX_VERSION
|
9
|
+
spec.authors = ['Juan Ignacio Donoso', 'treenewbee']
|
10
10
|
spec.description = %q{Adds suuport to nginx for Capistrano 3.x}
|
11
11
|
spec.summary = %q{Adds suuport to nginx for Capistrano 3.x}
|
12
|
-
spec.homepage = 'https://github.com/
|
12
|
+
spec.homepage = 'https://github.com/treenewbee/capistrano3-nginx'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
15
|
spec.files = `git ls-files`.split($/)
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_dependency 'capistrano', '
|
20
|
+
spec.add_dependency 'capistrano', '~> 3.0'
|
21
21
|
|
22
|
-
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rake', '~> 0'
|
23
23
|
end
|
data/lib/capistrano/nginx.rb
CHANGED
@@ -1 +1,56 @@
|
|
1
|
-
|
1
|
+
require "capistrano/plugin"
|
2
|
+
module Capistrano
|
3
|
+
class Nginx < Capistrano::Plugin
|
4
|
+
|
5
|
+
def set_defaults
|
6
|
+
set :nginx_sudo_paths, -> { [:nginx_log_path, :nginx_sites_enabled_dir, :nginx_sites_available_dir] }
|
7
|
+
set :nginx_sudo_tasks, -> { ['nginx:start', 'nginx:stop', 'nginx:restart', 'nginx:reload', 'nginx:configtest', 'nginx:site:add', 'nginx:site:disable', 'nginx:site:enable', 'nginx:site:remove' ] }
|
8
|
+
set :nginx_log_path, -> { "#{shared_path}/log" }
|
9
|
+
set :nginx_service_path, -> { 'service nginx' }
|
10
|
+
set :nginx_static_dir, -> { "#{shared_path}/public/assets" }
|
11
|
+
set :nginx_application_name, -> { fetch(:application) }
|
12
|
+
set :nginx_sites_enabled_dir, -> { "/etc/nginx/sites-enabled" }
|
13
|
+
set :nginx_sites_available_dir, -> { "/etc/nginx/sites-available" }
|
14
|
+
set :nginx_roles, -> { :sudo }
|
15
|
+
set :nginx_template, -> { :default }
|
16
|
+
set :nginx_use_ssl, -> { false }
|
17
|
+
set :nginx_ssl_certificate, -> { "#{fetch(:application)}.crt" }
|
18
|
+
set :nginx_ssl_certificate_path, -> { '/etc/ssl/certs' }
|
19
|
+
set :nginx_ssl_certificate_key, -> { "#{fetch(:application)}.key" }
|
20
|
+
set :nginx_ssl_certificate_key_path, -> { '/etc/ssl/private' }
|
21
|
+
set :app_server, -> { true }
|
22
|
+
end
|
23
|
+
|
24
|
+
def define_tasks
|
25
|
+
eval_rakefile File.expand_path('../tasks/nginx.rake', __FILE__)
|
26
|
+
end
|
27
|
+
|
28
|
+
# prepend :sudo to list if arguments if :key is in :nginx_use_sudo_for list
|
29
|
+
def add_sudo_if_required argument_list, *keys
|
30
|
+
keys.each do | key |
|
31
|
+
if nginx_use_sudo? key
|
32
|
+
argument_list.unshift(:sudo)
|
33
|
+
break
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def nginx_use_sudo? key
|
39
|
+
(fetch(:nginx_sudo_tasks).include?(key) || fetch(:nginx_sudo_paths).include?(key))
|
40
|
+
end
|
41
|
+
|
42
|
+
class PasswdInteractionHandler
|
43
|
+
def on_data(command, stream_name, data, channel)
|
44
|
+
if data.include?("[sudo]")
|
45
|
+
ask(:password, 'sudo', echo: false)
|
46
|
+
channel.send_data("#{fetch(:password)}\n")
|
47
|
+
elsif data.include?("UNIX password")
|
48
|
+
ask(:password, 'UNIX', echo: false)
|
49
|
+
channel.send_data("#{fetch(:password)}\n")
|
50
|
+
else
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -1,46 +1,6 @@
|
|
1
|
-
|
2
|
-
task :defaults do
|
3
|
-
set :nginx_sudo_paths, -> { [:nginx_log_path, :nginx_sites_enabled_dir, :nginx_sites_available_dir] }
|
4
|
-
set :nginx_sudo_tasks, -> { ['nginx:start', 'nginx:stop', 'nginx:restart', 'nginx:reload', 'nginx:configtest', 'nginx:site:add', 'nginx:site:disable', 'nginx:site:enable', 'nginx:site:remove' ] }
|
5
|
-
set :nginx_log_path, -> { "#{shared_path}/log" }
|
6
|
-
set :nginx_service_path, -> { 'service nginx' }
|
7
|
-
set :nginx_static_dir, -> { "public" }
|
8
|
-
set :nginx_application_name, -> { fetch(:application) }
|
9
|
-
set :nginx_sites_enabled_dir, -> { "/etc/nginx/sites-enabled" }
|
10
|
-
set :nginx_sites_available_dir, -> { "/etc/nginx/sites-available" }
|
11
|
-
set :nginx_roles, -> { :web }
|
12
|
-
set :nginx_template, -> { :default }
|
13
|
-
set :nginx_use_ssl, -> { false }
|
14
|
-
set :nginx_ssl_certificate, -> { "#{fetch(:application)}.crt" }
|
15
|
-
set :nginx_ssl_certificate_path, -> { '/etc/ssl/certs' }
|
16
|
-
set :nginx_ssl_certificate_key, -> { "#{fetch(:application)}.key" }
|
17
|
-
set :nginx_ssl_certificate_key_path, -> { '/etc/ssl/private' }
|
18
|
-
set :app_server, -> { true }
|
19
|
-
end
|
20
|
-
end
|
1
|
+
git_plugin = self
|
21
2
|
|
22
3
|
namespace :nginx do
|
23
|
-
|
24
|
-
# prepend :sudo to list if arguments if :key is in :nginx_use_sudo_for list
|
25
|
-
def add_sudo_if_required argument_list, *keys
|
26
|
-
keys.each do | key |
|
27
|
-
if use_sudo? key
|
28
|
-
argument_list.unshift(:sudo)
|
29
|
-
break
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def use_sudo? key
|
35
|
-
return (fetch(:nginx_sudo_tasks).include?(key) || fetch(:nginx_sudo_paths).include?(key))
|
36
|
-
end
|
37
|
-
|
38
|
-
def valid_nginx_config?
|
39
|
-
test_sudo = use_sudo?('nginx:configtest') ? 'sudo ' : ''
|
40
|
-
nginx_service = fetch(:nginx_service_path)
|
41
|
-
test "[ $(#{test_sudo}#{nginx_service} configtest | grep -c 'fail') -eq 0 ]"
|
42
|
-
end
|
43
|
-
|
44
4
|
task :load_vars do
|
45
5
|
set :sites_available, -> { fetch(:nginx_sites_available_dir) }
|
46
6
|
set :sites_enabled, -> { fetch(:nginx_sites_enabled_dir) }
|
@@ -48,6 +8,8 @@ namespace :nginx do
|
|
48
8
|
set :available_application, -> { File.join(fetch(:sites_available), fetch(:nginx_application_name)) }
|
49
9
|
end
|
50
10
|
|
11
|
+
|
12
|
+
|
51
13
|
# validate_sudo_settings
|
52
14
|
task :validate_user_settings do
|
53
15
|
path_and_dir_keys = [:nginx_log_path, :nginx_sites_enabled_dir, :nginx_sites_available_dir]
|
@@ -64,7 +26,11 @@ namespace :nginx do
|
|
64
26
|
desc "Configtest nginx service"
|
65
27
|
task :configtest do
|
66
28
|
on release_roles fetch(:nginx_roles) do
|
67
|
-
|
29
|
+
nginx_service = fetch(:nginx_service_path)
|
30
|
+
execute(
|
31
|
+
"sudo #{nginx_service} configtest",
|
32
|
+
interaction_handler: PasswdInteractionHandler.new
|
33
|
+
)
|
68
34
|
end
|
69
35
|
end
|
70
36
|
|
@@ -73,8 +39,8 @@ namespace :nginx do
|
|
73
39
|
task command => ['nginx:validate_user_settings'] do
|
74
40
|
on release_roles fetch(:nginx_roles) do
|
75
41
|
arguments = fetch(:nginx_service_path), command
|
76
|
-
add_sudo_if_required arguments, "nginx:#{command}"
|
77
|
-
execute *arguments
|
42
|
+
git_plugin.add_sudo_if_required arguments, "nginx:#{command}"
|
43
|
+
execute *arguments, interaction_handler: PasswdInteractionHandler.new
|
78
44
|
end
|
79
45
|
end
|
80
46
|
before "nginx:#{command}", 'nginx:configtest' unless command == 'stop'
|
@@ -84,7 +50,7 @@ namespace :nginx do
|
|
84
50
|
on release_roles fetch(:nginx_roles) do
|
85
51
|
arguments = :mkdir, '-pv', fetch(:nginx_log_path)
|
86
52
|
add_sudo_if_required arguments, :nginx_log_path
|
87
|
-
execute *arguments
|
53
|
+
execute *arguments, interaction_handler: PasswdInteractionHandler.new
|
88
54
|
end
|
89
55
|
end
|
90
56
|
after 'deploy:check', 'nginx:create_log_paths'
|
@@ -110,7 +76,7 @@ namespace :nginx do
|
|
110
76
|
config = ERB.new(File.read(config_file)).result(binding)
|
111
77
|
upload! StringIO.new(config), '/tmp/nginx.conf'
|
112
78
|
arguments = :mv, '/tmp/nginx.conf', fetch(:nginx_application_name)
|
113
|
-
add_sudo_if_required arguments, 'nginx:sites:add', :nginx_sites_available_dir
|
79
|
+
git_plugin.add_sudo_if_required arguments, 'nginx:sites:add', :nginx_sites_available_dir
|
114
80
|
execute *arguments
|
115
81
|
end
|
116
82
|
end
|
@@ -122,7 +88,7 @@ namespace :nginx do
|
|
122
88
|
if test "! [ -h #{fetch(:enabled_application)} ]"
|
123
89
|
within fetch(:sites_enabled) do
|
124
90
|
arguments = :ln, '-nfs', fetch(:available_application), fetch(:enabled_application)
|
125
|
-
add_sudo_if_required arguments, 'nginx:sites:enable', :nginx_sites_enabled_dir
|
91
|
+
git_plugin.add_sudo_if_required arguments, 'nginx:sites:enable', :nginx_sites_enabled_dir
|
126
92
|
execute *arguments
|
127
93
|
end
|
128
94
|
end
|
@@ -135,7 +101,7 @@ namespace :nginx do
|
|
135
101
|
if test "[ -f #{fetch(:enabled_application)} ]"
|
136
102
|
within fetch(:sites_enabled) do
|
137
103
|
arguments = :rm, '-f', fetch(:nginx_application_name)
|
138
|
-
add_sudo_if_required arguments, 'nginx:sites:disable', :nginx_sites_enabled_dir
|
104
|
+
git_plugin.add_sudo_if_required arguments, 'nginx:sites:disable', :nginx_sites_enabled_dir
|
139
105
|
execute *arguments
|
140
106
|
end
|
141
107
|
end
|
@@ -148,11 +114,12 @@ namespace :nginx do
|
|
148
114
|
if test "[ -f #{fetch(:available_application)} ]"
|
149
115
|
within fetch(:sites_available) do
|
150
116
|
arguments = :rm, fetch(:nginx_application_name)
|
151
|
-
add_sudo_if_required arguments, 'nginx:sites:remove', :nginx_sites_available_dir
|
117
|
+
git_plugin.add_sudo_if_required arguments, 'nginx:sites:remove', :nginx_sites_available_dir
|
152
118
|
execute *arguments
|
153
119
|
end
|
154
120
|
end
|
155
121
|
end
|
156
122
|
end
|
157
123
|
end
|
124
|
+
|
158
125
|
end
|
data/templates/nginx.conf.erb
CHANGED
@@ -66,11 +66,12 @@ server {
|
|
66
66
|
location @<%= fetch(:application) %>-app-server {
|
67
67
|
proxy_set_header X-Real-IP $remote_addr;
|
68
68
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
69
|
-
proxy_set_header X-FORWARDED_PROTO http;
|
70
69
|
proxy_set_header Host $http_host;
|
71
70
|
<% if fetch(:nginx_use_ssl) %>
|
72
71
|
proxy_set_header X-Forwarded-Proto https;
|
73
72
|
proxy_set_header X-Forwarded-Ssl on;
|
73
|
+
<% else %>
|
74
|
+
proxy_set_header X-Forwarded-Proto http;
|
74
75
|
<% end %>
|
75
76
|
<% if fetch(:nginx_read_timeout) %>
|
76
77
|
proxy_read_timeout <%= fetch(:nginx_read_timeout) %>;
|
metadata
CHANGED
@@ -1,62 +1,64 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano3-nginx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '3.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Ignacio Donoso
|
8
|
+
- treenewbee
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2018-09-14 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: capistrano
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- - "
|
18
|
+
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.0
|
20
|
+
version: '3.0'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- - "
|
25
|
+
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.0
|
27
|
+
version: '3.0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: rake
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- - "
|
32
|
+
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: '0'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- - "
|
39
|
+
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '0'
|
41
42
|
description: Adds suuport to nginx for Capistrano 3.x
|
42
|
-
email:
|
43
|
-
- jidonoso@gmail.com
|
43
|
+
email:
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- Gemfile
|
50
|
+
- Gemfile.lock
|
50
51
|
- LICENSE
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|
53
54
|
- Rakefile
|
54
55
|
- capistrano3-nginx.gemspec
|
55
56
|
- lib/capistrano/nginx.rb
|
57
|
+
- lib/capistrano/nginx/version.rb
|
56
58
|
- lib/capistrano/tasks/nginx.rake
|
57
59
|
- lib/capistrano3-nginx.rb
|
58
60
|
- templates/nginx.conf.erb
|
59
|
-
homepage: https://github.com/
|
61
|
+
homepage: https://github.com/treenewbee/capistrano3-nginx
|
60
62
|
licenses:
|
61
63
|
- MIT
|
62
64
|
metadata: {}
|
@@ -76,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
78
|
version: '0'
|
77
79
|
requirements: []
|
78
80
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.6.
|
81
|
+
rubygems_version: 2.6.14
|
80
82
|
signing_key:
|
81
83
|
specification_version: 4
|
82
84
|
summary: Adds suuport to nginx for Capistrano 3.x
|