capistrano-psw 1.0.0.pre16 → 1.0.0.pre17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62f251fcd42ad327b38073d97e92d287b13eae9c
4
- data.tar.gz: 5fcc70c1c08e94f41b4863cd19597e2661edfc85
3
+ metadata.gz: 3f3a1a48b849ee4b1ec7e83e1b23dcbd132f88a9
4
+ data.tar.gz: 3ee950684c97c014ce7660b6e073416a3b731d23
5
5
  SHA512:
6
- metadata.gz: 37bedeca93357a000f7cf7e491bcedcae18e3f356ddfce71d78f835d087287ee8e680436598b9dd90145feb44c9d78b980a3afbb92c7faf9dc63b72fa029c5ac
7
- data.tar.gz: 20204eb5075ed68b824465678ef25e62ece901f5312197ffa7ae7320a9c1ae04cd9fa16734600b34339aa1ac054dce885c7dab85746e0f23f9711828b9e06e79
6
+ metadata.gz: 53522940a4d83dccaf8f0b18a3ec8c765d16687334d45502273acb9919f88861e5cff7d9b588aac0671a6b96d666b652781f1eff2ab502c883fa982fbf91c7f1
7
+ data.tar.gz: c55b21be245f5bf7dbe371db20a406c8104b944f707e7916f14fa8a18bbb0ab8ce0b2ac1e9e61b3a82cdb5259d67febfea8a57c92bbf530aded39361ce621a3a
data/README.md CHANGED
@@ -214,6 +214,33 @@ after :depoy_and_configure_ssl do
214
214
  end
215
215
  ```
216
216
 
217
+ ## Peppr Application Deployment-related Tasks
218
+ These tasks are needed to deploy an application using peppr. It's recommended to execute these
219
+ tasks before any project-specific tasks are executed.
220
+
221
+ ### psw_peppr_app_deploy:create_deployment_directories
222
+ This task will ensure that the proper local and remote directories exist
223
+ for an application to be deployed via peppr.
224
+
225
+ ### psw_peppr_app_deploy:upload_app_source_repo
226
+ This task will upload your application source code to the correct folder
227
+ on the remote machine.
228
+
229
+ ### psw_peppr_app_deploy:upload_environment_files
230
+ This task will upload environment files that were downloaded locally
231
+ by peppr. Note: This should only be used if peppr is deploying the
232
+ application. However, if the environment files do not exist, they
233
+ will not be uploaded.
234
+
235
+ ```ruby
236
+ #set psw app deploy prefs
237
+ before 'psw_peppr_app_deploy:default', :set_app_deploy_options do
238
+ set :psw_peppr_app_deploy_debug, true
239
+ end
240
+
241
+ before :starting, 'psw_peppr_app_deploy:default'
242
+ ```
243
+
217
244
  ## License
218
245
 
219
- 2013 Lexmark International Technology S.A. All rights reserved.
246
+ 2014 Lexmark International Technology S.A. All rights reserved.
@@ -0,0 +1,204 @@
1
+ # == peppr_app_deploy_file_utils.rb
2
+ #
3
+ # This module contains helper methods for accessing Peppr's application deployment file structure
4
+ #
5
+ # == Contact
6
+ #
7
+ # Author:: Matt Sawka (matt.sawka@perceptivesoftware.com)
8
+ # Copyright:: 2014 Lexmark International Technology S.A. All rights reserved.
9
+ # License:: n/a
10
+
11
+ module PepprAppDeployFileUtils
12
+ PEPPR_RELATIVE_LOG_DIR = "/log"
13
+ PEPPR_RELATIVE_SRC_DIR = "/source"
14
+ PEPPR_RELATIVE_SCRIPTS_DIR = "/scripts"
15
+ PEPPR_RELATIVE_TMP_DIR = "/tmp"
16
+ PEPPR_RELATIVE_ENVIRONMENTS_DIR = "/environments"
17
+ PEPPR_RELATIVE_SHARED_FILE_DIR = "/shared_files"
18
+
19
+ module Local
20
+ # Method for verifying that Peppr's application deployment file structure exists on the
21
+ # local machine.
22
+ #
23
+ # @return n/a
24
+ def self.create_deployment_directories
25
+ run_locally do
26
+ info "Creating deployment directories on locally..."
27
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Local::get_deployment_log_dir
28
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Local::get_deployment_src_dir
29
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Local::get_deployment_scripts_dir
30
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Local::get_deployment_tmp_dir
31
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Local::get_deployment_environments_dir
32
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Local::get_deployment_shared_files_dir
33
+ end
34
+ end
35
+
36
+ # Method for retrieving the base or relative Peppr application deployment directory
37
+ #
38
+ # @param [String] relative_dir - relative deployment sub-directory
39
+ # @return [String] the fully-qualified local directory
40
+ def self.get_deployment_dir(relative_dir="")
41
+ application_id = ENV['peppr_application_id'].to_i
42
+ application_deployment = ENV['peppr_application_deployment_id'].to_i
43
+
44
+ raise ArgumentError.new("peppr_application_id and peppr_application_deployment_id must be defined as part of the Capistrano deployment!") unless application_id > 0 && application_deployment > 0
45
+ "/tmp/peppr_deployments/applications/#{application_id}/deployments/#{application_deployment}#{relative_dir}"
46
+ end
47
+
48
+ # Method for retrieving the Peppr application deployment source directory
49
+ #
50
+ # @return [String] the fully-qualified local source directory
51
+ def self.get_deployment_src_dir
52
+ PepprAppDeployFileUtils::Local::get_deployment_dir(PEPPR_RELATIVE_SRC_DIR)
53
+ end
54
+
55
+ # Method for retrieving the Peppr application deployment temp directory
56
+ #
57
+ # @return [String] the fully-qualified local temp directory
58
+ def self.get_deployment_tmp_dir
59
+ PepprAppDeployFileUtils::Local::get_deployment_dir(PEPPR_RELATIVE_TMP_DIR)
60
+ end
61
+
62
+ # Method for retrieving the Peppr application deployment log directory
63
+ #
64
+ # @return [String] the fully-qualified local log directory
65
+ def self.get_deployment_log_dir
66
+ PepprAppDeployFileUtils::Local::get_deployment_dir(PEPPR_RELATIVE_LOG_DIR)
67
+ end
68
+
69
+ # Method for retrieving the Peppr application deployment scripts directory
70
+ #
71
+ # @return [String] the fully-qualified local scripts directory
72
+ def self.get_deployment_scripts_dir
73
+ PepprAppDeployFileUtils::Local::get_deployment_dir(PEPPR_RELATIVE_SCRIPTS_DIR)
74
+ end
75
+
76
+ # Method for retrieving the Peppr application deployment environments directory
77
+ #
78
+ # @return [String] the fully-qualified local environments directory
79
+ def self.get_deployment_environments_dir
80
+ PepprAppDeployFileUtils::Local::get_deployment_dir(PEPPR_RELATIVE_ENVIRONMENTS_DIR)
81
+ end
82
+
83
+ def self.get_deployment_shared_files_dir
84
+ PepprAppDeployFileUtils::Local::get_deployment_dir(PEPPR_RELATIVE_SHARED_FILE_DIR)
85
+ end
86
+ end
87
+
88
+ module Remote
89
+ # Method for verifying that Peppr's application deployment file structure exists on the
90
+ # local machine.
91
+ #
92
+ # @return n/a
93
+ def self.create_deployment_directories
94
+ on roles(:all) do |host|
95
+ info "Creating deployment directories on host #{host}..."
96
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Remote::get_deployment_dir
97
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Remote::get_deployment_log_dir
98
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Remote::get_deployment_src_dir
99
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Remote::get_deployment_scripts_dir
100
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Remote::get_deployment_tmp_dir
101
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Remote::get_deployment_environments_dir
102
+ execute :mkdir, '-p', PepprAppDeployFileUtils::Remote::get_deployment_shared_files_dir
103
+ end
104
+ end
105
+
106
+ # Method for retrieving the base or relative Peppr application deployment directory
107
+ #
108
+ # @param [String] relative_dir - relative deployment sub-directory
109
+ # @return [String] the fully-qualified local directory
110
+ def self.get_deployment_dir(relative_dir="")
111
+ application_id = ENV['peppr_application_id'].to_i
112
+ application_deployment = ENV['peppr_application_deployment_id'].to_i
113
+
114
+ raise ArgumentError.new("peppr_application_id and peppr_application_deployment_id must be defined as part of the Capistrano deployment!") unless application_id > 0 && application_deployment > 0
115
+ "/tmp/peppr_deployments_remote/applications/#{application_id}/deployments/#{application_deployment}#{relative_dir}"
116
+ end
117
+
118
+ # Method for retrieving the Peppr application deployment source directory
119
+ #
120
+ # @return [String] the fully-qualified remote source directory
121
+ def self.get_deployment_src_dir
122
+ PepprAppDeployFileUtils::Remote::get_deployment_dir(PEPPR_RELATIVE_SRC_DIR)
123
+ end
124
+
125
+ # Method for retrieving the Peppr application deployment source directory
126
+ #
127
+ # @return [String] the fully-qualified remote source directory
128
+ def self.get_deployment_src_dir_as_file
129
+ "file://#{PepprAppDeployFileUtils::Remote::get_deployment_dir(PEPPR_RELATIVE_SRC_DIR)}"
130
+ end
131
+
132
+ # Method for retrieving the Peppr application deployment temp directory
133
+ #
134
+ # @return [String] the fully-qualified remote temp directory
135
+ def self.get_deployment_tmp_dir
136
+ PepprAppDeployFileUtils::Remote::get_deployment_dir(PEPPR_RELATIVE_TMP_DIR)
137
+ end
138
+
139
+ # Method for retrieving the Peppr application deployment log directory
140
+ #
141
+ # @return [String] the fully-qualified remote log directory
142
+ def self.get_deployment_log_dir
143
+ PepprAppDeployFileUtils::Remote::get_deployment_dir(PEPPR_RELATIVE_LOG_DIR)
144
+ end
145
+
146
+ # Method for retrieving the Peppr application deployment scripts directory
147
+ #
148
+ # @return [String] the fully-qualified remote scripts directory
149
+ def self.get_deployment_scripts_dir
150
+ PepprAppDeployFileUtils::Remote::get_deployment_dir(PEPPR_RELATIVE_SCRIPTS_DIR)
151
+ end
152
+
153
+ # Method for retrieving the Peppr application deployment environments directory
154
+ #
155
+ # @return [String] the fully-qualified remote environments directory
156
+ def self.get_deployment_environments_dir
157
+ PepprAppDeployFileUtils::Remote::get_deployment_dir(PEPPR_RELATIVE_ENVIRONMENTS_DIR)
158
+ end
159
+
160
+ # Method for retrieving the Peppr application deployment environments directory
161
+ #
162
+ # @return [String] the fully-qualified remote shared files directory
163
+ def self.get_deployment_shared_files_dir
164
+ PepprAppDeployFileUtils::Remote::get_deployment_dir(PEPPR_RELATIVE_SHARED_FILE_DIR)
165
+ end
166
+ end
167
+
168
+ # Method to compress, upload, and extract a local directory using the following procedure:
169
+ # *create a tarball of the local directory
170
+ # *upload the tarball
171
+ # *extract the tarball
172
+ # *copy the extracted contents to the correct location
173
+ #
174
+ # @param [String] local_dir - local directory to copy from
175
+ # @param [String] remote_target_dir - remote directory to copy to
176
+ # @return n/a
177
+ def self.upload_compressed_local_dir(local_dir, remote_target_dir)
178
+ #create a local tarball
179
+ local_tmp_dir = PepprAppDeployFileUtils::Local::get_deployment_tmp_dir
180
+ remote_tmp_dir = PepprAppDeployFileUtils::Remote::get_deployment_tmp_dir
181
+ tar_name = "#{SecureRandom.hex}.tar.gz"
182
+ run_locally do
183
+ info "Compressing local directory #{local_dir}..."
184
+ execute :rm, '-rf', "#{local_tmp_dir}/#{tar_name}"
185
+
186
+ tar_cmd = "tar -czf"
187
+ tar_cmd = tar_cmd + "v" if fetch(:psw_peppr_app_deploy_debug)
188
+ execute("cd #{local_dir} && #{tar_cmd} #{local_tmp_dir}/#{tar_name} .")
189
+ end
190
+
191
+ on roles(:all) do |host|
192
+ #upload tarball to remote host
193
+ upload! "#{local_tmp_dir}/#{tar_name}", "#{remote_tmp_dir}/#{tar_name}"
194
+
195
+ #extract tarball to end location
196
+ execute :rm, '-rf', "#{remote_target_dir}"
197
+ execute :mkdir, '-p', "#{remote_target_dir}"
198
+
199
+ tar_cmd = "tar -xzf"
200
+ tar_cmd = tar_cmd + "v" if fetch(:psw_peppr_app_deploy_debug)
201
+ execute("cd #{remote_tmp_dir} && #{tar_cmd} #{remote_tmp_dir}/#{tar_name} -C #{remote_target_dir}")
202
+ end
203
+ end
204
+ end
@@ -10,6 +10,6 @@
10
10
 
11
11
  module Capistrano
12
12
  module Psw
13
- VERSION = "1.0.0.pre16"
13
+ VERSION = "1.0.0.pre17"
14
14
  end
15
15
  end
@@ -1,5 +1,6 @@
1
1
  require "capistrano/psw/version"
2
2
  require "capistrano/psw/task_loader"
3
+ require "capistrano/psw/peppr_app_deploy_file_utils"
3
4
 
4
5
  module Capistrano
5
6
  module Psw
@@ -0,0 +1,115 @@
1
+ # == psw-peppr-app-deploy.cap
2
+ #
3
+ # Contains the capistrano tasks needed to deploy an application using peppr
4
+ #
5
+ # == Configuration
6
+ #
7
+ # To use the defined tasks, hook into other tasks.
8
+ #
9
+ # Examples:
10
+ #
11
+ # #set psw app deploy prefs
12
+ # before 'psw_peppr_app_deploy:default', :set_app_deploy_options do
13
+ # set :psw_peppr_app_deploy_debug, true
14
+ # end
15
+ #
16
+ # == Tasks
17
+ #
18
+ # === psw_peppr_app_deploy:create_deployment_directories
19
+ # This task will ensure that the proper local and remote directories exist
20
+ # for an application to be deployed via peppr.
21
+ #
22
+ # === psw_peppr_app_deploy:upload_app_source_repo
23
+ # This task will upload your application source code to the correct folder
24
+ # on the remote machine.
25
+ #
26
+ # === psw_peppr_app_deploy:upload_environment_files
27
+ # This task will upload environment files that were downloaded locally
28
+ # by peppr. Note: This should only be used if peppr is deploying the
29
+ # application. However, if the environment files do not exist, they
30
+ # will not be uploaded.
31
+ #
32
+ # == Contact
33
+ #
34
+ # Author:: Lexmark International Technology S.A.
35
+ # Copyright:: 2013 Lexmark International Technology S.A. All rights reserved.
36
+ # License:: 3-Clause BSD
37
+ require 'capistrano/psw/peppr_app_deploy_file_utils'
38
+
39
+ namespace :psw_peppr_app_deploy do
40
+
41
+ desc 'Create deployment directories on local and remote host.'
42
+ task :create_deployment_directories do
43
+ #the Peppr application deployment worker should have created these already, but this
44
+ #will ensure that at least the directories will exist
45
+ PepprAppDeployFileUtils::Local::create_deployment_directories
46
+
47
+ #On the remote machines, make sure that this directory is fresh
48
+ on roles(:all) do |host|
49
+ execute :rm, '-rf', PepprAppDeployFileUtils::Remote::get_deployment_dir
50
+ end
51
+ PepprAppDeployFileUtils::Remote::create_deployment_directories
52
+ end
53
+
54
+ desc 'Upload application source repository to remote server'
55
+ task :upload_app_source_repo do
56
+ on roles(:all) do |host|
57
+ local_src_dir = PepprAppDeployFileUtils::Local::get_deployment_src_dir
58
+ remote_src_dir = PepprAppDeployFileUtils::Remote::get_deployment_src_dir
59
+
60
+ info "Uploading #{local_src_dir} (local) to #{remote_src_dir} on remote server #{host}..."
61
+ PepprAppDeployFileUtils::upload_compressed_local_dir(local_src_dir, remote_src_dir)
62
+
63
+ #sets the Capistrano github task's URL
64
+ set :repo_url, "file://#{remote_src_dir}"
65
+ end
66
+ end
67
+
68
+ desc 'Copy application enviroment files to remote machine'
69
+ task :upload_environment_files do
70
+ on roles(:app) do |host|
71
+ info 'Preparing to upload environment files (if applicable)...'
72
+ local_shared_files_path = PepprAppDeployFileUtils::Local::get_deployment_shared_files_dir
73
+
74
+ if File.exist? local_shared_files_path
75
+ info "Uploading environment files..."
76
+ files = Find.find(local_shared_files_path)
77
+
78
+ absolute_path_files, shared_files = files.partition { |f| f.start_with? "#{local_shared_files_path}/.absolute_paths" }
79
+
80
+ shared_files.each do |file|
81
+ relative_path = file.gsub("#{local_shared_files_path}/", '')
82
+
83
+ debug "Inspecting: #{relative_path}" if fetch(:psw_peppr_app_deploy_debug)
84
+
85
+ if File.directory?(file) && relative_path.strip != ''
86
+ execute :mkdir, '-p', "#{shared_path}/#{relative_path}"
87
+ elsif relative_path.gsub(/\s+/, '') != '' and relative_path != '.' and relative_path != '..'
88
+ debug "Uploading environment file #{relative_path}..." if fetch(:psw_peppr_app_deploy_debug)
89
+ upload! file, "#{shared_path}/#{relative_path}"
90
+ end
91
+ end
92
+
93
+ info 'Uploading absolute path environment files...'
94
+ absolute_path_files.each do |file|
95
+ relative_path = file.gsub("#{local_shared_files_path}/.absolute_paths", '')
96
+
97
+ debug "Inspecting: #{relative_path}" if fetch(:psw_peppr_app_deploy_debug)
98
+
99
+ if File.directory?(file) && relative_path.strip != ''
100
+ execute :mkdir, '-p', relative_path
101
+ elsif relative_path.gsub(/\s+/, '') != '' and relative_path != '.' and relative_path != '..'
102
+ debug "Uploading environment file #{relative_path}..." if fetch(:psw_peppr_app_deploy_debug)
103
+ upload! file, relative_path
104
+ end
105
+ end
106
+ else
107
+ info "The shared files path, #{local_shared_files_path} does not exist."
108
+ end
109
+ end
110
+ end
111
+
112
+ desc "Deploy private repository to remote server(s)"
113
+ task default: [:'create_deployment_directories', :'upload_app_source_repo', :'upload_environment_files'] do
114
+ end
115
+ end
@@ -0,0 +1,50 @@
1
+ require "rake"
2
+ require File.expand_path('../spec_helper.rb', __FILE__)
3
+
4
+
5
+ describe "psw_peppr_app_deploy:" do
6
+ describe "create_deployment_directories" do
7
+ let(:rake) { Rake::Application.new }
8
+ subject { rake["psw_peppr_app_deploy:create_deployment_directories"] }
9
+
10
+ before do
11
+ Rake.application = rake
12
+ Rake.application.add_import("./resources/lib/capistrano/tasks/psw-peppr-app-deploy.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 "upload_app_source_repo" do
22
+ let(:rake) { Rake::Application.new }
23
+ subject { rake["psw_peppr_app_deploy:upload_app_source_repo"] }
24
+
25
+ before do
26
+ Rake.application = rake
27
+ Rake.application.add_import("./resources/lib/capistrano/tasks/psw-peppr-app-deploy.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_environment_files" do
37
+ let(:rake) { Rake::Application.new }
38
+ subject { rake["psw_peppr_app_deploy:upload_environment_files"] }
39
+
40
+ before do
41
+ Rake.application = rake
42
+ Rake.application.add_import("./resources/lib/capistrano/tasks/psw-peppr-app-deploy.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
+ 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.pre16
4
+ version: 1.0.0.pre17
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-25 00:00:00.000000000 Z
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,16 +83,19 @@ files:
83
83
  - capistrano-psw.gemspec
84
84
  - ci/pipeline-config.json
85
85
  - lib/capistrano/psw.rb
86
+ - lib/capistrano/psw/peppr_app_deploy_file_utils.rb
86
87
  - lib/capistrano/psw/server_utils.rb
87
88
  - lib/capistrano/psw/task_loader.rb
88
89
  - lib/capistrano/psw/version.rb
89
90
  - resources/lib/capistrano/tasks/psw-clockwork.cap
90
91
  - resources/lib/capistrano/tasks/psw-nginx.cap
92
+ - resources/lib/capistrano/tasks/psw-peppr-app-deploy.cap
91
93
  - resources/lib/capistrano/tasks/psw-peppr.cap
92
94
  - resources/lib/capistrano/tasks/psw-repo.cap
93
95
  - resources/lib/capistrano/tasks/psw-sidekiq.cap
94
96
  - spec/psw-clockwork_spec.rb
95
97
  - spec/psw-nginx_spec.rb
98
+ - spec/psw-peppr-app-deploy_spec.rb
96
99
  - spec/psw-peppr_spec.rb
97
100
  - spec/psw-repo_spec.rb
98
101
  - spec/psw-sidekiq_spec.rb
@@ -127,6 +130,7 @@ summary: Contains Capistrano v3 Deployment Tasks
127
130
  test_files:
128
131
  - spec/psw-clockwork_spec.rb
129
132
  - spec/psw-nginx_spec.rb
133
+ - spec/psw-peppr-app-deploy_spec.rb
130
134
  - spec/psw-peppr_spec.rb
131
135
  - spec/psw-repo_spec.rb
132
136
  - spec/psw-sidekiq_spec.rb