capistrano-psw 1.0.0.pre14 → 1.0.0.pre15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/capistrano/psw/server_utils.rb +18 -0
- data/lib/capistrano/psw/task_loader.rb +4 -0
- data/lib/capistrano/psw/version.rb +1 -1
- data/resources/lib/capistrano/tasks/psw-nginx.cap +141 -0
- data/spec/psw-nginx_spec.rb +35 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 704228fd3987825ab8d61fe40f62f7bd0f7d8ef0
|
4
|
+
data.tar.gz: b32d6a88e85d4a6da517bdb519fb10fb40e491ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 083954d1a8517db6321cf2352d5c81e4d981b3b8a31d1bd19e10380356a292f87d9cd28d02788df54224a616b8378f6f2f1c58247a63de84c2c70704d8e9678f
|
7
|
+
data.tar.gz: 5cf746e7e9f9cbb0f050bd2e8eeca6110fefff44aa90b982f8cc8348c06b01369795649f06537e33dcec40b37df00254cf521950548859ee731301cd93ad3a17
|
data/README.md
CHANGED
@@ -185,6 +185,34 @@ namespace :deploy do
|
|
185
185
|
before :starting, 'psw_peppr:clear_shared_files'
|
186
186
|
end
|
187
187
|
```
|
188
|
+
## Nginx-related Tasks
|
189
|
+
These tasks are used to interact with the Nginx web server.
|
190
|
+
|
191
|
+
### psw_nginx:deploy_ssl_certs
|
192
|
+
This task will copy SSL certificates defined in the application's shared directory
|
193
|
+
to /etc/ssl/certs and /etc/ssl/private.
|
194
|
+
|
195
|
+
### psw_nginx:configure_nginx
|
196
|
+
This task task will override the site definition for a specific nginx virtual site
|
197
|
+
and enable it via a symlink in sites-enabled. This method allows consumers to define an
|
198
|
+
ERB template as well as pass in a ruby binding to populate it.
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
before :'psw_nginx:configure_nginx', :set_nginx_options do
|
202
|
+
set :psw_nginx_site_template, File.expand_path("../../lib/capistrano/templates/nginx/my-site.erb", __FILE__)
|
203
|
+
set :psw_nginx_site_name, "my-site"
|
204
|
+
end
|
205
|
+
|
206
|
+
before :'psw_nginx:deploy_ssl_certs', :set_nginx_ssl_options do
|
207
|
+
set :psw_nginx_ssl_cert_file, "#{shared_path}/nginx/ssl/my-cert.crt"
|
208
|
+
set :psw_nginx_ssl_key_file, "#{shared_path}/nginx/ssl/my-cert.key"
|
209
|
+
end
|
210
|
+
|
211
|
+
after :depoy_and_configure_ssl do
|
212
|
+
Rake::Task['psw_nginx:deploy_ssl_certs'].invoke
|
213
|
+
Rake::Task['psw_nginx:configure_nginx'].invoke(binding)
|
214
|
+
end
|
215
|
+
```
|
188
216
|
|
189
217
|
## License
|
190
218
|
|
@@ -1,9 +1,27 @@
|
|
1
|
+
# == server_utils.rb
|
2
|
+
#
|
3
|
+
# This module provides methods for reading in a JSON file containing Capistrano server
|
4
|
+
# definitions.
|
5
|
+
#
|
6
|
+
# == Contact
|
7
|
+
#
|
8
|
+
# Author:: Lexmark International Technology S.A.
|
9
|
+
# Copyright:: 2014 Lexmark International Technology S.A. All rights reserved.
|
10
|
+
# License:: 3-Clause BSD
|
11
|
+
|
1
12
|
require 'capistrano'
|
2
13
|
require 'json'
|
3
14
|
|
4
15
|
module Capistrano
|
5
16
|
module Psw
|
6
17
|
class ServerUtils
|
18
|
+
|
19
|
+
# Static method that reads in a JSON file and parses it into a map of Capistrano server
|
20
|
+
# definitions.
|
21
|
+
#
|
22
|
+
# @param [String] filename - JSON file path
|
23
|
+
# @param [String] stage_name - Capistrano stage name
|
24
|
+
# @return [Enumerator] collection of Capistrano server definitions
|
7
25
|
def self.get_servers_from_json (filename, stage_name)
|
8
26
|
raise ArgumentError, 'missing filename' if filename.nil? || filename.strip == ''
|
9
27
|
raise ArgumentError, 'missing stage_name' if stage_name.nil? || stage_name.strip == ''
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# == psw-nginx.cap
|
2
|
+
#
|
3
|
+
# Contains the capistrano tasks needed to interact with the Nginx web server
|
4
|
+
#
|
5
|
+
# == Configuration
|
6
|
+
#
|
7
|
+
# To use the defined tasks, hook into other tasks.
|
8
|
+
#
|
9
|
+
# Examples:
|
10
|
+
#
|
11
|
+
# after :depoy_and_configure_ssl do
|
12
|
+
# Rake::Task['psw_nginx:deploy_ssl_certs'].invoke
|
13
|
+
# Rake::Task['psw_nginx:configure_nginx'].invoke(binding)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# == Tasks
|
17
|
+
#
|
18
|
+
# === psw_nginx:deploy_ssl_certs
|
19
|
+
# This task will copy SSL certificates defined in the application's shared directory
|
20
|
+
# to /etc/ssl/certs and /etc/ssl/private.
|
21
|
+
#
|
22
|
+
# === psw_nginx:configure_nginx
|
23
|
+
# This task task will override the site definition for a specific nginx virtual site
|
24
|
+
# and enable it via a symlink in sites-enabled. This method allows consumers to define an
|
25
|
+
# ERB template as well as pass in a ruby binding to populate it.
|
26
|
+
#
|
27
|
+
# == Configuration
|
28
|
+
# The following configuration options may be set (should be set before the 'stop' task is executed):
|
29
|
+
#
|
30
|
+
# before :'psw_nginx:configure_nginx', :set_nginx_options do
|
31
|
+
# set :psw_nginx_site_template, File.expand_path("../../lib/capistrano/templates/nginx/my-site.erb", __FILE__)
|
32
|
+
# set :psw_nginx_site_name, "my-site"
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# before :'psw_nginx:deploy_ssl_certs', :set_nginx_ssl_options do
|
36
|
+
# set :psw_nginx_ssl_cert_file, "#{shared_path}/nginx/ssl/my-cert.crt"
|
37
|
+
# set :psw_nginx_ssl_key_file, "#{shared_path}/nginx/ssl/my-cert.key"
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# before :'psw_nginx:deploy_ssl_certs', :set_nginx_options do
|
41
|
+
# set :psw_nginx_shared_cert_dir, ""
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# == Contact
|
45
|
+
#
|
46
|
+
# Author:: Lexmark International Technology S.A.
|
47
|
+
# Copyright:: 2013 Lexmark International Technology S.A. All rights reserved.
|
48
|
+
# License:: 3-Clause BSD
|
49
|
+
#
|
50
|
+
require 'tempfile'
|
51
|
+
require 'pathname'
|
52
|
+
|
53
|
+
namespace :psw_nginx do
|
54
|
+
|
55
|
+
#ssl cert properties
|
56
|
+
def get_ssl_cert_file
|
57
|
+
fetch(:psw_nginx_ssl_cert_file, "")
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_ssl_key_file
|
61
|
+
fetch(:psw_nginx_ssl_key_file, "")
|
62
|
+
end
|
63
|
+
|
64
|
+
#config properties
|
65
|
+
def get_nginx_config_dir
|
66
|
+
fetch(:psw_nginx_config_dir, "/config/nginx")
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_nginx_site_template
|
70
|
+
fetch(:psw_nginx_site_template, "")
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_nginx_site_name
|
74
|
+
fetch(:psw_nginx_site_name, "")
|
75
|
+
end
|
76
|
+
|
77
|
+
task :deploy_ssl_certs do
|
78
|
+
on roles(:app) do |host|
|
79
|
+
info "Creating cert directory..."
|
80
|
+
ssl_cert_dir = "/etc/ssl/certs"
|
81
|
+
sudo :mkdir, '-p', ssl_cert_dir
|
82
|
+
|
83
|
+
ssl_private_dir = "/etc/ssl/private"
|
84
|
+
info "Creating cert key directory..."
|
85
|
+
sudo :mkdir, '-p', ssl_private_dir
|
86
|
+
|
87
|
+
ssl_cert_file = "#{get_ssl_cert_file}"
|
88
|
+
ssl_cert_filename = Pathname.new(ssl_cert_file).basename
|
89
|
+
info "Copying certificate (#{ssl_cert_file}) to key directory..."
|
90
|
+
sudo :rm, "-rf", "#{ssl_cert_dir}/#{ssl_cert_filename}"
|
91
|
+
sudo :cp, ssl_cert_file, ssl_cert_dir
|
92
|
+
sudo :chmod, '600', "#{ssl_cert_dir}/#{ssl_cert_filename}"
|
93
|
+
|
94
|
+
ssl_key_file = "#{get_ssl_key_file}"
|
95
|
+
ssl_key_filename = Pathname.new(ssl_key_file).basename
|
96
|
+
info "Copying certificate key (#{ssl_key_file}) to key directory..."
|
97
|
+
sudo :rm, '-rf', "#{ssl_private_dir}/#{ssl_key_filename}"
|
98
|
+
sudo :cp, ssl_key_file, ssl_private_dir
|
99
|
+
sudo :chmod, '600', "#{ssl_private_dir}/#{ssl_key_filename}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
task :configure_nginx, :template_binding do |t, args|
|
104
|
+
on roles(:app) do |host|
|
105
|
+
info "Configuring Nginx..."
|
106
|
+
|
107
|
+
site_template_path = get_nginx_site_template
|
108
|
+
unless site_template_path.nil? || site_template_path.length == 0
|
109
|
+
info "Adding site template #{site_template_path} to Nginx..."
|
110
|
+
|
111
|
+
site_template = ERB.new File.new(site_template_path).read, nil, "%"
|
112
|
+
template_binding = (!args[:template_binding].nil? && args[:template_binding]) || binding
|
113
|
+
site = site_template.result(template_binding)
|
114
|
+
|
115
|
+
tmp_site_file = Tempfile.new("#{get_nginx_site_name}-")
|
116
|
+
tmp_site_file.write(site)
|
117
|
+
tmp_site_file.flush
|
118
|
+
|
119
|
+
shared_nginx_config_dir = "#{shared_path}#{get_nginx_config_dir}"
|
120
|
+
info "Creating shared Nginx configuration directory #{shared_nginx_config_dir}..."
|
121
|
+
execute :mkdir, '-p', shared_nginx_config_dir
|
122
|
+
|
123
|
+
info "Uploading Nginx site configuration for site #{get_nginx_site_name}..."
|
124
|
+
shared_nginx_config_file = "#{shared_nginx_config_dir}/#{get_nginx_site_name}"
|
125
|
+
upload! "#{tmp_site_file.path}", "#{shared_nginx_config_file}"
|
126
|
+
|
127
|
+
#symlink to site-enabled
|
128
|
+
info "Creating a symlink for site #{get_nginx_site_name}..."
|
129
|
+
sudo :rm, '-rf', "/etc/nginx/sites-enabled/#{get_nginx_site_name}"
|
130
|
+
sudo :rm, '-rf', "/etc/nginx/sites-available/#{get_nginx_site_name}"
|
131
|
+
|
132
|
+
#can't use 'set :linked_files' because this only allows linking within the Rails app
|
133
|
+
#https://github.com/capistrano/capistrano/blob/dfe25c9436461c395cb7425f8c452ab87ca6b5e0/lib/capistrano/tasks/deploy.rake
|
134
|
+
sudo :ln, '-s', "#{shared_nginx_config_file}", "/etc/nginx/sites-available/#{get_nginx_site_name}"
|
135
|
+
sudo :ln, '-s', "/etc/nginx/sites-available/#{get_nginx_site_name}", "/etc/nginx/sites-enabled/#{get_nginx_site_name}"
|
136
|
+
else
|
137
|
+
info "A site template has not been defined for Nginx"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "rake"
|
2
|
+
require File.expand_path('../spec_helper.rb', __FILE__)
|
3
|
+
|
4
|
+
|
5
|
+
describe "psw_nginx:" do
|
6
|
+
describe "deploy_ssl_certs" do
|
7
|
+
let(:rake) { Rake::Application.new }
|
8
|
+
subject { rake["psw_nginx:deploy_ssl_certs"] }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Rake.application = rake
|
12
|
+
Rake.application.add_import("./resources/lib/capistrano/tasks/psw-nginx.cap")
|
13
|
+
Rake.application.load_imports()
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has 'no prerequisites" do
|
17
|
+
subject.prerequisites.should be_empty
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "configure_nginx" do
|
22
|
+
let(:rake) { Rake::Application.new }
|
23
|
+
subject { rake["psw_nginx:configure_nginx"] }
|
24
|
+
|
25
|
+
before do
|
26
|
+
Rake.application = rake
|
27
|
+
Rake.application.add_import("./resources/lib/capistrano/tasks/psw-nginx.cap")
|
28
|
+
Rake.application.load_imports()
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has 'no prerequisites" do
|
32
|
+
subject.prerequisites.should be_empty
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-psw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.pre15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lexmark International Technology S.A
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,10 +87,12 @@ files:
|
|
87
87
|
- lib/capistrano/psw/task_loader.rb
|
88
88
|
- lib/capistrano/psw/version.rb
|
89
89
|
- resources/lib/capistrano/tasks/psw-clockwork.cap
|
90
|
+
- resources/lib/capistrano/tasks/psw-nginx.cap
|
90
91
|
- resources/lib/capistrano/tasks/psw-peppr.cap
|
91
92
|
- resources/lib/capistrano/tasks/psw-repo.cap
|
92
93
|
- resources/lib/capistrano/tasks/psw-sidekiq.cap
|
93
94
|
- spec/psw-clockwork_spec.rb
|
95
|
+
- spec/psw-nginx_spec.rb
|
94
96
|
- spec/psw-peppr_spec.rb
|
95
97
|
- spec/psw-repo_spec.rb
|
96
98
|
- spec/psw-sidekiq_spec.rb
|
@@ -124,6 +126,7 @@ specification_version: 4
|
|
124
126
|
summary: Contains Capistrano v3 Deployment Tasks
|
125
127
|
test_files:
|
126
128
|
- spec/psw-clockwork_spec.rb
|
129
|
+
- spec/psw-nginx_spec.rb
|
127
130
|
- spec/psw-peppr_spec.rb
|
128
131
|
- spec/psw-repo_spec.rb
|
129
132
|
- spec/psw-sidekiq_spec.rb
|