capistrano-psw 1.0.0.pre19 → 1.0.0.pre20

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bcad68fd6f61bdd7ccc802f0685331649698595
4
- data.tar.gz: e4fac297e8c3f57ad0c9746ce0f14acbfacc5594
3
+ metadata.gz: fac3821682e68f811796d48840f4745551939f17
4
+ data.tar.gz: e7655a4df532093aa1b0473753b64542d4c21917
5
5
  SHA512:
6
- metadata.gz: d1ab45f7e01ac05a071e615075c569c33c465b9c8716bde444edb7f95c92af20eeb59620037c329aaa9160505e6da171fffb81eed34e6f162b9ae494dcaa3ed6
7
- data.tar.gz: aea76262b7bf000a000e2cb024ea73cb22a97ff8789d3def110625002a6f705928216ec2e24b755581ed84f29805f370d60eec56082e6dc18bd50d179d03ab1c
6
+ metadata.gz: e663383874c35092d3607508334189aa6cd5daec2bf932863ed36fdcb2147706622b83e627394800a13d68096eee05492be74d61730149eef73db81e43f7c170
7
+ data.tar.gz: ced44af859b0983624f96cb001c9434c91b06b27020bc2d60f451425ce3f6bfe69ffbf319304f24a30ba583abde7367ab1346a29bff08458711957b439e66d16
data/README.md CHANGED
@@ -241,6 +241,48 @@ end
241
241
  before :starting, 'psw_peppr_app_deploy:default'
242
242
  ```
243
243
 
244
+ ## apache2-related Tasks
245
+ These tasks are used to interact with the apache2 web server.
246
+
247
+
248
+ ### psw_apache2:deploy_ssl_certs
249
+ This task will copy SSL certificates defined in the application's shared directory
250
+ to /etc/ssl/certs and /etc/ssl/private.
251
+
252
+ ### psw_apache2:configure_apache2
253
+ This task task will override the site definition for a specific apache2 virtual site
254
+ and enable it via a symlink in sites-enabled. This method allows consumers to define an
255
+ ERB template as well as pass in a ruby binding to populate it.
256
+
257
+ ### psw_apache2:upload_symlink_script
258
+ Once the code is on the remote server, we'll need to provide apache a symlink
259
+ to access the current version. Because the apache configuration is varies from
260
+ OS to OS, a bash script is needed to determine the apache DocumentRoot and
261
+ generate the appropriate symlink. This task will copy a script to the remote
262
+ server to generate the symlink.
263
+
264
+ ### psw_apache2:upload_apache_ctrl_script
265
+ After code deployment, the apache2 server will need to be manipulated.
266
+ Because the apache configuration is varies from OS to OS, a bash script is needed
267
+ to execute commands. This task will copy a script to the remote server to execute
268
+ apache2 server commands.
269
+
270
+ ```ruby
271
+ before :'psw_apache2:configure_apache2', :set_apache2_options do
272
+ set :psw_apache2_site_template, File.expand_path("../../lib/capistrano/templates/apache2/my-site.erb", __FILE__)
273
+ set :psw_apache2_site_name, "my-site"
274
+ end
275
+
276
+ before :'psw_apache2:deploy_ssl_certs', :set_apache2_ssl_options do
277
+ set :psw_apache2_ssl_cert_file, "#{shared_path}/apache2/ssl/my-cert.crt"
278
+ set :psw_apache2_ssl_key_file, "#{shared_path}/apache2/ssl/my-cert.key"
279
+ end
280
+
281
+ before :'psw_apache2:deploy_ssl_certs', :set_apache2_options do
282
+ set :psw_apache2_shared_cert_dir, ""
283
+ end
284
+ ```
285
+
244
286
  ## License
245
287
 
246
288
  2014 Lexmark International Technology S.A. All rights reserved.
@@ -10,6 +10,6 @@
10
10
 
11
11
  module Capistrano
12
12
  module Psw
13
- VERSION = "1.0.0.pre19"
13
+ VERSION = "1.0.0.pre20"
14
14
  end
15
15
  end
@@ -0,0 +1,289 @@
1
+ # == psw-apache2.cap
2
+ #
3
+ # Contains the capistrano tasks needed to interact with the apache2 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_apache2:deploy_ssl_certs'].invoke
13
+ # Rake::Task['psw_apache2:configure_apache2'].invoke(binding)
14
+ # end
15
+ #
16
+ # == Tasks
17
+ #
18
+ # === psw_apache2: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_apache2:configure_apache2
23
+ # This task task will override the site definition for a specific apache2 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
+ # === psw_apache2:upload_symlink_script
28
+ # Once the code is on the remote server, we'll need to provide apache a symlink
29
+ # to access the current version. Because the apache configuration is varies from
30
+ # OS to OS, a bash script is needed to determine the apache DocumentRoot and
31
+ # generate the appropriate symlink. This task will copy a script to the remote
32
+ # server to generate the symlink.
33
+ #
34
+ # === psw_apache2:upload_apache_ctrl_script
35
+ # After code deployment, the apache2 server will need to be manipulated.
36
+ # Because the apache configuration is varies from OS to OS, a bash script is needed
37
+ # to execute commands. This task will copy a script to the remote server to execute
38
+ # apache2 server commands.
39
+ #
40
+ # == Configuration
41
+ # The following configuration options may be set (should be set before the 'stop' task is executed):
42
+ #
43
+ # before :'psw_apache2:configure_apache2', :set_apache2_options do
44
+ # set :psw_apache2_site_template, File.expand_path("../../lib/capistrano/templates/apache2/my-site.erb", __FILE__)
45
+ # set :psw_apache2_site_name, "my-site"
46
+ # end
47
+ #
48
+ # before :'psw_apache2:deploy_ssl_certs', :set_apache2_ssl_options do
49
+ # set :psw_apache2_ssl_cert_file, "#{shared_path}/apache2/ssl/my-cert.crt"
50
+ # set :psw_apache2_ssl_key_file, "#{shared_path}/apache2/ssl/my-cert.key"
51
+ # end
52
+ #
53
+ # before :'psw_apache2:deploy_ssl_certs', :set_apache2_options do
54
+ # set :psw_apache2_shared_cert_dir, ""
55
+ # end
56
+ #
57
+ # == Contact
58
+ #
59
+ # Author:: Lexmark International Technology S.A.
60
+ # Copyright:: 2014 Lexmark International Technology S.A. All rights reserved.
61
+ # License:: 3-Clause BSD
62
+ #
63
+ require 'tempfile'
64
+ require 'pathname'
65
+ require 'capistrano/psw/peppr_app_deploy_file_utils'
66
+
67
+ namespace :psw_apache2 do
68
+
69
+ #ssl cert properties
70
+ def get_ssl_cert_file
71
+ fetch(:psw_apache2_ssl_cert_file, "")
72
+ end
73
+
74
+ def get_ssl_key_file
75
+ fetch(:psw_apache2_ssl_key_file, "")
76
+ end
77
+
78
+ def get_ssl_chain_file
79
+ fetch(:psw_apache2_ssl_chain_file, "")
80
+ end
81
+
82
+ #config properties
83
+ def get_apache2_config_dir
84
+ fetch(:psw_apache2_config_dir, "/config/apache2")
85
+ end
86
+
87
+ def get_apache2_site_template
88
+ fetch(:psw_apache2_site_template, "")
89
+ end
90
+
91
+ def get_apache2_site_name
92
+ fetch(:psw_apache2x_site_name, "")
93
+ end
94
+
95
+ task :deploy_ssl_certs do
96
+ on roles(:app) do |host|
97
+ info "Creating cert directory..."
98
+ ssl_cert_dir = "/etc/ssl/certs"
99
+ sudo :mkdir, '-p', ssl_cert_dir
100
+
101
+ ssl_private_dir = "/etc/ssl/private"
102
+ info "Creating cert key directory..."
103
+ sudo :mkdir, '-p', ssl_private_dir
104
+
105
+ ssl_cert_file = "#{get_ssl_cert_file}"
106
+ ssl_cert_filename = Pathname.new(ssl_cert_file).basename
107
+ info "Copying certificate (#{ssl_cert_file}) to cert directory..."
108
+ sudo :rm, "-rf", "#{ssl_cert_dir}/#{ssl_cert_filename}"
109
+ sudo :cp, ssl_cert_file, ssl_cert_dir
110
+ sudo :chmod, '600', "#{ssl_cert_dir}/#{ssl_cert_filename}"
111
+
112
+ ssl_key_file = "#{get_ssl_key_file}"
113
+ ssl_key_filename = Pathname.new(ssl_key_file).basename
114
+ info "Copying certificate key (#{ssl_key_file}) to key directory..."
115
+ sudo :rm, '-rf', "#{ssl_private_dir}/#{ssl_key_filename}"
116
+ sudo :cp, ssl_key_file, ssl_private_dir
117
+ sudo :chmod, '600', "#{ssl_private_dir}/#{ssl_key_filename}"
118
+
119
+ ssl_chain_file = "#{get_ssl_chain_file}"
120
+ ssl_chain_filename = Pathname.new(ssl_chain_file).basename
121
+ info "Copying certificate key (#{ssl_chain_file}) to cert directory..."
122
+ sudo :rm, '-rf', "#{ssl_cert_dir}/#{ssl_chain_filename}"
123
+ sudo :cp, ssl_chain_file, ssl_cert_dir
124
+ sudo :chmod, '600', "#{ssl_cert_dir}/#{ssl_chain_filename}"
125
+ end
126
+ end
127
+
128
+ task :configure_apache2, :template_binding do |t, args|
129
+ on roles(:app) do |host|
130
+ info "Configuring apache2..."
131
+
132
+ site_template_path = get_apache2_site_template
133
+ unless site_template_path.nil? || site_template_path.length == 0
134
+ info "Adding site template #{site_template_path} to apache2..."
135
+
136
+ site_template = ERB.new File.new(site_template_path).read, nil, "%"
137
+ template_binding = (!args[:template_binding].nil? && args[:template_binding]) || binding
138
+ site = site_template.result(template_binding)
139
+
140
+ tmp_site_file = Tempfile.new("#{get_apache2_site_name}-")
141
+ tmp_site_file.write(site)
142
+ tmp_site_file.flush
143
+
144
+ shared_apache2_config_dir = "#{shared_path}#{get_apache2_config_dir}"
145
+ info "Creating shared apache2 configuration directory #{shared_apache2_config_dir}..."
146
+ execute :mkdir, '-p', shared_apache2_config_dir
147
+
148
+ info "Uploading apache2 site configuration for site #{get_apache2_site_name}..."
149
+ shared_apache2_config_file = "#{shared_apache2_config_dir}/#{get_apache2_site_name}"
150
+ upload! "#{tmp_site_file.path}", "#{shared_apache2_config_file}"
151
+
152
+ #symlink to site-enabled
153
+ #note that /etc/apache2 is ubuntu specific
154
+ info "Creating a symlink for site #{get_apache2_site_name}..."
155
+ sudo :rm, '-rf', "/etc/apache2/sites-enabled/#{get_apache2_site_name}"
156
+ sudo :rm, '-rf', "/etc/apache2/sites-available/#{get_apache2_site_name}"
157
+
158
+ sudo :mkdir, '-p', "/etc/apache2/sites-available/"
159
+ sudo :ln, '-s', "#{shared_apache2_config_file}", "/etc/apache2/sites-available/#{get_apache2_site_name}"
160
+
161
+ sudo :mkdir, '-p', "/etc/apache2/sites-enabled/"
162
+ sudo :ln, '-s', "/etc/apache2/sites-available/#{get_apache2_site_name}", "/etc/apache2/sites-enabled/#{get_apache2_site_name}"
163
+ else
164
+ info "A site template has not been defined for apache2"
165
+ end
166
+ end
167
+ end
168
+
169
+ desc 'Upload a bash script that can create the appropriate apache document symlink...'
170
+ task :upload_symlink_script do
171
+ bash_script = <<-eos
172
+ #!/bin/bash
173
+ # Create link in apache2's DocumentRoot to current peppr deployment
174
+
175
+ peppr_current_location=$1
176
+ if [ -z "$peppr_current_location" ]; then
177
+ echo "Peppr current location not specified!"
178
+ exit 0
179
+ fi
180
+ echo "Current peppr location: $peppr_current_location"
181
+
182
+ echo "Determining the Apache service name..."
183
+ os_version=$(lsb_release -r)
184
+ if [[ "$os_version" == *Release:* ]]; then
185
+ echo "Running on a debian system. Using service name apache2"
186
+ apache_service_name="apache2"
187
+ else
188
+ echo "Running on a non-debian system. Using service name httpd"
189
+ apache_service_name="httpd"
190
+ fi
191
+
192
+ apache_config_location=$($apache_service_name -V | grep -i " -D HTTPD_ROOT=")
193
+ if [ -z "$apache_config_location" ]; then
194
+ echo "No apache configuration location has been defined!"
195
+ exit 0
196
+ fi
197
+ apache_config_location=${apache_config_location:16}
198
+ apache_config_location=${apache_config_location%?}
199
+ echo "Apache2 Config Location: $apache_config_location"
200
+
201
+ apache_config_file==$($apache_service_name -V | grep -i " -D SERVER_CONFIG_FILE=")
202
+ if [ -z "$apache_config_location" ]; then
203
+ echo "No apache configuration file has been defined!"
204
+ exit 0
205
+ fi
206
+ apache_config_file=${apache_config_file:25}
207
+ apache_config_file=${apache_config_file%?}
208
+ apache_config_file_location="$apache_config_location/$apache_config_file"
209
+ echo "Apache2 Config File Location: $apache_config_file_location"
210
+
211
+ apache_docroot_dir=$(grep -i 'DocumentRoot ' $apache_config_file_location)
212
+ if [ -z "$apache_docroot_dir" ]; then
213
+ echo "Unable to find apache's DocumentRoot!"
214
+ exit 0
215
+ fi
216
+ apache_docroot_dir=${apache_docroot_dir:14}
217
+ apache_docroot_dir=${apache_docroot_dir%?}
218
+ echo "Apache2 DocRoot: $apache_docroot_dir"
219
+ result=$(sudo rm -rf $apache_docroot_dir)
220
+
221
+ peppr_docroot="$apache_docroot_dir"
222
+ echo "Peppr DocRoot: $peppr_docroot"
223
+ echo "Creating link $peppr_docroot to directory $peppr_current_location..."
224
+ echo "Executing: sudo ln -nsf $peppr_current_location $peppr_docroot"
225
+ result=$(sudo rm -rf $peppr_docroot)
226
+ result=$(sudo ln -nsf $peppr_current_location $peppr_docroot)
227
+
228
+ link_listing=$(ls -la $peppr_docroot)
229
+ echo "Resulting Link: $link_listing"
230
+ echo "Script completed!"
231
+ eos
232
+
233
+ local_script_dir= PepprAppDeployFileUtils::Local::get_deployment_scripts_dir
234
+ symlink_script_name = "apache-symlink.sh"
235
+ local_symlink_file = "#{local_script_dir}/#{symlink_script_name}"
236
+ File.open(local_symlink_file, 'w') {|f| f.write(bash_script) }
237
+
238
+ remote_ctrl_dir = PepprAppDeployFileUtils::Remote::get_deployment_scripts_dir
239
+ remote_symlink_file = "#{remote_ctrl_dir}/#{symlink_script_name}"
240
+ on roles(:all) do |host|
241
+ info "Uploading #{local_symlink_file} to #{remote_symlink_file} on remote server #{host}..."
242
+ execute :rm, '-rf', "#{remote_symlink_file}"
243
+ execute :mkdir, '-p', "#{remote_ctrl_dir}"
244
+ upload! "#{local_symlink_file}", "#{remote_symlink_file}"
245
+ end
246
+ end
247
+
248
+ desc 'Upload a bash script that can execute OS-agnostic apache server commands...'
249
+ task :upload_apache_ctrl_script do
250
+ bash_script = <<-eos
251
+ #!/bin/bash
252
+ # Script to execute OS-agnostic apache server commands
253
+
254
+ server_command=$1
255
+ if [ -z "$server_command" ]; then
256
+ echo "No server command specified!"
257
+ exit 0
258
+ fi
259
+
260
+ echo "Determining the Apache service name..."
261
+ os_version=$(lsb_release -r)
262
+ if [[ "$os_version" == *Release:* ]]; then
263
+ echo "Running on a debian system. Using service name apache2"
264
+ apache_service_name="apache2"
265
+ else
266
+ echo "Running on a non-debian system. Using service name httpd"
267
+ apache_service_name="httpd"
268
+ fi
269
+
270
+ echo "Executing command: sudo /etc/init.d/$apache_service_name $server_command"
271
+ result=$(sudo /etc/init.d/$apache_service_name $server_command)
272
+ echo "Script completed!"
273
+ eos
274
+
275
+ local_script_dir= PepprAppDeployFileUtils::Local::get_deployment_scripts_dir
276
+ apache_ctrl_script_name = "apache-ctrl.sh"
277
+ local_ctrl_file = "#{local_script_dir}/#{apache_ctrl_script_name}"
278
+ File.open(local_ctrl_file, 'w') {|f| f.write(bash_script) }
279
+
280
+ remote_ctrl_dir = PepprAppDeployFileUtils::Remote::get_deployment_scripts_dir
281
+ remote_ctrl_file = "#{remote_ctrl_dir}/#{apache_ctrl_script_name}"
282
+ on roles(:all) do |host|
283
+ info "Uploading #{local_ctrl_file} to #{remote_ctrl_file} on remote server #{host}..."
284
+ execute :rm, '-rf', "#{remote_ctrl_file}"
285
+ execute :mkdir, '-p', "#{remote_ctrl_dir}"
286
+ upload! "#{local_ctrl_file}", "#{remote_ctrl_file}"
287
+ end
288
+ end
289
+ end
@@ -0,0 +1,65 @@
1
+ require "rake"
2
+ require File.expand_path('../spec_helper.rb', __FILE__)
3
+
4
+
5
+ describe "psw_apache2:" do
6
+ describe "deploy_ssl_certs" do
7
+ let(:rake) { Rake::Application.new }
8
+ subject { rake["psw_apache2:deploy_ssl_certs"] }
9
+
10
+ before do
11
+ Rake.application = rake
12
+ Rake.application.add_import("./resources/lib/capistrano/tasks/psw-apache2.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_apache2" do
22
+ let(:rake) { Rake::Application.new }
23
+ subject { rake["psw_apache2:configure_apache2"] }
24
+
25
+ before do
26
+ Rake.application = rake
27
+ Rake.application.add_import("./resources/lib/capistrano/tasks/psw-apache2.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
+
36
+ describe "upload_symlink_script" do
37
+ let(:rake) { Rake::Application.new }
38
+ subject { rake["psw_apache2:upload_symlink_script"] }
39
+
40
+ before do
41
+ Rake.application = rake
42
+ Rake.application.add_import("./resources/lib/capistrano/tasks/psw-apache2.cap")
43
+ Rake.application.load_imports()
44
+ end
45
+
46
+ it "has 'no prerequisites" do
47
+ subject.prerequisites.should be_empty
48
+ end
49
+ end
50
+
51
+ describe "upload_apache_ctrl_script" do
52
+ let(:rake) { Rake::Application.new }
53
+ subject { rake["psw_apache2:upload_apache_ctrl_script"] }
54
+
55
+ before do
56
+ Rake.application = rake
57
+ Rake.application.add_import("./resources/lib/capistrano/tasks/psw-apache2.cap")
58
+ Rake.application.load_imports()
59
+ end
60
+
61
+ it "has 'no prerequisites" do
62
+ subject.prerequisites.should be_empty
63
+ end
64
+ end
65
+ 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.pre19
4
+ version: 1.0.0.pre20
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-03-06 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,12 +87,14 @@ files:
87
87
  - lib/capistrano/psw/server_utils.rb
88
88
  - lib/capistrano/psw/task_loader.rb
89
89
  - lib/capistrano/psw/version.rb
90
+ - resources/lib/capistrano/tasks/psw-apache2.cap
90
91
  - resources/lib/capistrano/tasks/psw-clockwork.cap
91
92
  - resources/lib/capistrano/tasks/psw-nginx.cap
92
93
  - resources/lib/capistrano/tasks/psw-peppr-app-deploy.cap
93
94
  - resources/lib/capistrano/tasks/psw-peppr.cap
94
95
  - resources/lib/capistrano/tasks/psw-repo.cap
95
96
  - resources/lib/capistrano/tasks/psw-sidekiq.cap
97
+ - spec/psw-apache2_spec.rb
96
98
  - spec/psw-clockwork_spec.rb
97
99
  - spec/psw-nginx_spec.rb
98
100
  - spec/psw-peppr-app-deploy_spec.rb
@@ -128,6 +130,7 @@ signing_key:
128
130
  specification_version: 4
129
131
  summary: Contains Capistrano v3 Deployment Tasks
130
132
  test_files:
133
+ - spec/psw-apache2_spec.rb
131
134
  - spec/psw-clockwork_spec.rb
132
135
  - spec/psw-nginx_spec.rb
133
136
  - spec/psw-peppr-app-deploy_spec.rb