dlss-capistrano 3.5.0 → 3.10.0

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
  SHA256:
3
- metadata.gz: 9cccccc5b5eaf3803ab7126c36e158c7261e39e6008a5b0d41779c9b1899efdc
4
- data.tar.gz: 0d047c34a9dd98823e0d4febf90324f4f0bd677885c28a2532cbe4bfdc2d4c9a
3
+ metadata.gz: e70dce4334fb19dd733691feeb6767a15ad60ec0b23cdd798db3b95eac0cbb3c
4
+ data.tar.gz: 2ec578117cf92d26845b752285b7f4f469978873584d8f2abfbc18dd66c49aaf
5
5
  SHA512:
6
- metadata.gz: 4ef5f0bb20fad9adfa66175b7cbbbedf9113b346f2e321ef8514659fe868f3c77aa304c9f4c1cbd73ce686d5c7dde0ca7c0908681c3246df77c5022bfc2b71e6
7
- data.tar.gz: 909936827f0f18dd5d864b16ca865db074ce16cc1b264abdb2e4495195f32c19ee0b2cc04dd6511db26d2e95743f92caf537e65c5dd0ab39e147b7f6562b383a
6
+ metadata.gz: 5aaf6ce12fd37b5586d8302116e2db5d94fb83076c8860ca203573ae93b414fc304892e45a4e5b2368bf68be260dc5c01b61d02319b63c7127c313cdb07821e6
7
+ data.tar.gz: c5f48c6365a083f290814c3063d3c65cd7ae49a48d3b303c4615758cd7df69dd7a6acc858ba6e47922f7a3caf8d81d046e2a6be7ecd09dfcff97b2eb97fa44a2
@@ -0,0 +1,12 @@
1
+ ## Why was this change made?
2
+
3
+
4
+
5
+ ## How was this change tested?
6
+
7
+
8
+
9
+ ## Which documentation and/or configurations were updated?
10
+
11
+
12
+
data/README.md CHANGED
@@ -1,20 +1,106 @@
1
1
  # dlss-capistrano
2
2
 
3
- This gem contains classes that deal with the Capistrano deployment of SUL DLSS Ruby projects.
3
+ [![Gem Version](https://badge.fury.io/rb/dlss-capistrano.svg)](https://badge.fury.io/rb/dlss-capistrano)
4
4
 
5
- ## Capfile assumptions
5
+ This gem provides Capistrano deployment tasks used by Stanford Libraries' Digital Library Systems and Services group.
6
6
 
7
- This gem makes the following assumptions about your Ruby project
7
+ ## Included Tasks
8
+
9
+ ### Bundle 2-style Configuration
10
+
11
+ To override the capistrano-bundler gem and use Bundler 2-style configuration without using deprecated arguments, you can set the following settings in `config/deploy.rb`:
12
+
13
+ ```ruby
14
+ set :bundler2_config_use_hook, true # this is how to opt-in to bundler 2-style config. it's false by default
15
+ set :bundler2_config_roles, [:app] # feel free to add roles to this array if you need them
16
+ set :bundler2_config_deployment, true # this is true by default
17
+ set :bundler2_config_without, 'production' # exclude development, and test bundle groups by default
18
+ set :bundler2_config_path, '/tmp' # set to '#{shared_path}/bundle' by default
19
+ ```
20
+
21
+ Note that only `bundler2_config_use_hook` **must** be set in order to use this functionality.
22
+
23
+ ### Sidekiq symlink
24
+
25
+ Every time the version of Sidekiq or Ruby changes, a corresponding Puppet PR must be made in order to update the XSendFilePath that allows Apache to access the bundled Sidekiq gem's assets. dlss-capistrano provides a hook to create a symlink to the bundled Sidekiq to avoid having to do this:
26
+
27
+ ```ruby
28
+ set :bundled_sidekiq_symlink, true # false is the default value
29
+ set :bundled_sidekiq_roles, [:app] # this is the default value
30
+ ```
31
+
32
+ Set this in `config/deploy.rb` to automate the symlink creation, and then use `XSendFilePath /path/to/my/app/shared/bundled_sidekiq/web/assets` in Apache configuration (in Puppet).
33
+
34
+ ### SSH
35
+
36
+ `cap ENV ssh` establishes an SSH connection to the host running in `ENV` environment, and changes into the current deployment directory
37
+
38
+ ### SSH Connection Checking
39
+
40
+ `cap ENV ssh_check` establishes an SSH connection to all app servers running in `ENV` environment and prints environment information to confirm the connection was made. This is used by [sdr-deploy](https://github.com/sul-dlss-labs/sdr-deploy/) to check SSH connections can be made in bulk before proceeding with a mass deploy.
41
+
42
+ ### Display Revision (and branches)
43
+
44
+ `cap ENV deployed_branch` displays the currently deployed revision (commit ID) and any branches containing the revision for each server in `ENV`.
45
+
46
+ ### Resque-Pool hot swap (OPTIONAL)
47
+
48
+ The `dlss-capistrano` gem provides a set of tasks for managing `resque-pool` workers when deployed in `hot_swap` mode. (If you are using `resque-pool` without `hot_swap`, we recommend continuing to use the `capistrano-resque-pool` gem instead of what `dlss-capistrano` provides.) The tasks are:
49
+
50
+ ```shell
51
+ $ cap ENV resque:pool:hot_swap # this gracefully replaces the current pool with a new pool
52
+ $ cap ENV resque:pool:stop # this gracefully stops the current pool
53
+ ```
54
+
55
+ By default, these tasks are not provided; instead, they must be explicitly enabled via adding a new `require` statement to the application's `Capfile`:
56
+
57
+ ```ruby
58
+ require 'dlss/capistrano/resque_pool'
59
+ ```
60
+
61
+ ### Sidekiq via systemd
62
+
63
+ `cap ENV sidekiq_systemd:{quiet,stop,start,restart}`: quiets, stops, starts, restarts Sidekiq via systemd.
64
+
65
+ These tasks are intended to replace those provided by `capistrano-sidekiq` gem, which has assumptions about systemd that do not apply to our deployed environments.
66
+
67
+ #### Capistrano role
68
+
69
+ The sidekiq_systemd tasks assume a Capistrano role of `:app`. If your application uses a different Capistrano role for hosts that run Sidekiq workers, you can configure this in `config/deploy.rb`, *e.g.*:
70
+
71
+ ```ruby
72
+ set :sidekiq_systemd_role, :worker
73
+ ```
74
+
75
+ #### Deployment hooks
76
+
77
+ The sidekiq_systemd tasks assume you want to hook them into Capistrano deployment on your own. If you want to use the hooks provided by `dlss-capistrano`, you can opt in via `config/deploy.rb`:
78
+
79
+ ```ruby
80
+ set :sidekiq_systemd_use_hooks, true
81
+ ```
82
+
83
+ These are the hooks provided if you opt in:
84
+
85
+ ```ruby
86
+ after 'deploy:failed', 'sidekiq_systemd:restart'
87
+ after 'deploy:published', 'sidekiq_systemd:start'
88
+ after 'deploy:starting', 'sidekiq_systemd:quiet'
89
+ after 'deploy:updated', 'sidekiq_systemd:stop'
90
+ ```
91
+
92
+ ## Assumptions
93
+
94
+ dlss-capistrano makes the following assumptions about your Ruby project
8
95
 
9
96
  - You are using Capistrano 3+
10
97
  - You use git for source control
11
- - The server you deploy to uses rvm, it is installed systemwide, and is the default system ruby
98
+ - The server you deploy to uses rvm, it is installed system-wide, and is the default system ruby
12
99
  - You do not have an .rvmrc checked into git (should be in your .gitignore)
13
100
  - You will not use rvm gemsets on the server you deploy to
14
101
  - Bundler will install specified gems into {your_project_home}/shared/bundle directory
15
102
  - Will deploy from the master branch, unless you set :branch to another branch or tag
16
103
 
104
+ ## Copyright
17
105
 
18
- == Copyright
19
-
20
- Copyright (c) 2015 Stanford University Library. See LICENSE for details.
106
+ Copyright (c) 2020 Stanford University. See LICENSE for details.
@@ -4,13 +4,13 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "dlss-capistrano"
7
- s.version = "3.5.0"
7
+ s.version = "3.10.0"
8
8
 
9
9
  s.platform = Gem::Platform::RUBY
10
- s.authors = ["Chris Beer","Willy Mene"]
11
- s.email = ["cabeer@stanford.edu"]
12
- s.summary = "Capistrano recipies for use in SUL/DLSS projects"
13
- s.description = "Capistrano recipies to assist with the development, testing, and release of SUL/DLSS Ruby project"
10
+ s.authors = ["Chris Beer", 'Mike Giarlo']
11
+ s.email = ["cabeer@stanford.edu", 'mjgiarlo@stanford.edu']
12
+ s.summary = "Capistrano recipes for use in SUL/DLSS projects"
13
+ s.description = "Capistrano recipes to assist with development, testing, & deployment of SUL/DLSS Ruby projects"
14
14
  s.license = "Apache-2.0"
15
15
 
16
16
  s.required_rubygems_version = ">= 1.3.6"
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  # All dependencies are runtime dependencies, since this gem's "runtime" is
20
20
  # the dependent gem's development-time.
21
21
  s.add_dependency "capistrano", "~> 3.0"
22
- s.add_dependency "capistrano-bundle_audit", ">= 0.1.0"
22
+ s.add_dependency "capistrano-bundle_audit", ">= 0.3.0"
23
23
  s.add_dependency "capistrano-one_time_key"
24
24
  s.add_dependency "capistrano-shared_configs"
25
25
 
@@ -2,4 +2,4 @@ require 'capistrano/one_time_key'
2
2
  require 'capistrano/bundle_audit'
3
3
  require 'capistrano/shared_configs'
4
4
 
5
- load File.expand_path('../capistrano/tasks/ssh.rake', __FILE__)
5
+ Dir.glob("#{__dir__}/capistrano/tasks/*.rake").each { |r| import r }
@@ -0,0 +1 @@
1
+ import "#{__dir__}/resque_pool/tasks/resque_pool.rake"
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # These tasks are a drop-in replacement for capistrano-resque-pool when using
4
+ # hot-swappable pools. We replace these tasks because the upstream ones assume a
5
+ # pidfile is present, which is not the case with hot-swappable pools.
6
+
7
+ namespace :load do
8
+ task :defaults do
9
+ # Same capistrano variable used by capistrano-resque-pool for compatibility
10
+ set :resque_server_roles, fetch(:resque_server_roles, [:app])
11
+ end
12
+ end
13
+
14
+ # Integrate hook into Capistrano
15
+ namespace :deploy do
16
+ before :starting, :add_resque_pool_hotswap_hook do
17
+ invoke 'resque:pool:add_hook'
18
+ end
19
+ end
20
+
21
+ namespace :resque do
22
+ namespace :pool do
23
+ # Lifted from capistrano-resque-pool
24
+ def rails_env
25
+ fetch(:resque_rails_env) ||
26
+ fetch(:rails_env) || # capistrano-rails doesn't automatically set this (yet),
27
+ fetch(:stage) # so we need to fall back to the stage.
28
+ end
29
+
30
+ # NOTE: no `desc` here to avoid publishing this task in the `cap -T` list
31
+ task :add_hook do
32
+ after 'deploy:restart', 'resque:pool:hot_swap'
33
+ end
34
+
35
+ desc 'Swap in a new pool, then shut down the old pool'
36
+ task :hot_swap do
37
+ on roles(fetch(:resque_server_roles)) do
38
+ within current_path do
39
+ execute :bundle, :exec, 'resque-pool', "--daemon --hot-swap --environment #{rails_env}"
40
+ end
41
+ end
42
+ end
43
+
44
+ desc 'Gracefully shut down current pool'
45
+ task :stop do
46
+ on roles(fetch(:resque_server_roles)) do
47
+ # This will usually return a single pid, but if you do multiple quick
48
+ # deployments, you may pick up multiple pids here, in which case we only
49
+ # kill the oldest one
50
+ pid = capture(:pgrep, '-f resque-pool-master').split.first
51
+
52
+ if test "kill -0 #{pid} > /dev/null 2>&1"
53
+ execute :kill, "-s QUIT #{pid}"
54
+ else
55
+ warn "Process #{pid} is not running"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # These tasks exist because capistrano-bundler does not yet have a built-in
4
+ # mechanism for configuring bundler 2 without deprecation warnings. We can dump
5
+ # this if/when https://github.com/capistrano/bundler/issues/115 is resolved.
6
+
7
+ def default_bundle_path
8
+ Pathname.new("#{shared_path}/bundle")
9
+ end
10
+
11
+ namespace :load do
12
+ task :defaults do
13
+ # This provides opt-in behavior. Do nothing if not requested.
14
+ set :bundler2_config_use_hook, fetch(:bundler2_config_use_hook, false)
15
+ set :bundler2_config_roles, fetch(:bundler2_config_roles, [:app])
16
+ set :bundler2_config_deployment, fetch(:bundler2_config_deployment, true)
17
+ set :bundler2_config_without, fetch(:bundler2_config_without, 'development:test')
18
+ # NOTE: `shared_path` is not defined at this point, so we can't set the default value to `default_bundle_path`
19
+ set :bundler2_config_path, fetch(:bundler2_config_path, nil)
20
+ end
21
+ end
22
+
23
+ # Integrate bundle config hook into Capistrano
24
+ namespace :deploy do
25
+ before :starting, :add_bundler2_config_hook do
26
+ invoke 'bundler2:add_hook' if fetch(:bundler2_config_use_hook)
27
+ end
28
+ end
29
+
30
+ namespace :bundler2 do
31
+ # NOTE: no `desc` here to avoid publishing this task in the `cap -T` list
32
+ task :add_hook do
33
+ # Override capistrano-bundler settings
34
+ # HT: https://github.com/capistrano/bundler/issues/115#issuecomment-616570236
35
+ set :bundle_flags, '--quiet' # this unsets --deployment, see details in config_bundler task details
36
+ set :bundle_path, nil
37
+ set :bundle_without, nil
38
+
39
+ before 'bundler:install', 'bundler2:config'
40
+ end
41
+
42
+ # NOTE: This task lacks a `desc` to avoid publishing it, since we do not
43
+ # foresee needing to run this task manually. It should run via hook.
44
+ #
45
+ # Configure bundler 2 without using deprecated arguments (overrides capistrano-bundler
46
+ task :config do
47
+ on roles fetch(:bundler2_config_roles) do
48
+ execute "bundle config --local deployment #{fetch(:bundler2_config_deployment)}"
49
+ execute "bundle config --local without '#{fetch(:bundler2_config_without)}'"
50
+ execute "bundle config --local path #{fetch(:bundler2_config_path) || default_bundle_path}"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,31 @@
1
+ # Capistrano plugin hook to set default values
2
+ namespace :load do
3
+ task :defaults do
4
+ set :bundled_sidekiq_symlink, fetch(:bundled_sidekiq_symlink, false)
5
+ set :bundled_sidekiq_roles, fetch(:bundled_sidekiq_roles, [:app])
6
+ end
7
+ end
8
+
9
+ # Integrate sidekiq-bundle hook into Capistrano
10
+ namespace :deploy do
11
+ before :starting, :add_bundled_sidekiq_hook do
12
+ invoke 'bundled_sidekiq:add_hook' if fetch(:bundled_sidekiq_symlink)
13
+ end
14
+ end
15
+
16
+ namespace :bundled_sidekiq do
17
+ # NOTE: no `desc` here to avoid publishing this task in the `cap -T` list
18
+ task :add_hook do
19
+ after 'bundler:install', 'bundled_sidekiq:symlink'
20
+ end
21
+
22
+ # NOTE: no `desc` here to avoid publishing this task in the `cap -T` list
23
+ task :symlink do
24
+ on roles fetch(:bundled_sidekiq_roles) do
25
+ within release_path do
26
+ bundled_sidekiq_path = capture(:bundle, :info, '--path', :sidekiq)
27
+ execute(:ln, '-sf', bundled_sidekiq_path, "#{shared_path}/bundled_sidekiq")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ desc 'display the deployed branch and commit'
2
+ task :deployed_branch do
3
+ on roles(:app) do |host|
4
+ within current_path do
5
+ revision = capture :cat, 'REVISION'
6
+ branches = `git branch -r --contains #{revision}`.strip
7
+ info "#{host}: #{revision} (#{branches})"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,52 @@
1
+ # Capistrano plugin hook to set default values
2
+ namespace :load do
3
+ task :defaults do
4
+ set :sidekiq_systemd_role, fetch(:sidekiq_systemd_role, :app)
5
+ set :sidekiq_systemd_use_hooks, fetch(:sidekiq_systemd_use_hooks, false)
6
+ end
7
+ end
8
+
9
+ # Integrate sidekiq hooks into Capistrano
10
+ namespace :deploy do
11
+ before :starting, :add_sidekiq_systemd_hooks do
12
+ invoke 'sidekiq_systemd:add_hooks' if fetch(:sidekiq_systemd_use_hooks)
13
+ end
14
+ end
15
+
16
+ namespace :sidekiq_systemd do
17
+ # NOTE: no `desc` here to avoid publishing this task in the `cap -T` list
18
+ task :add_hooks do
19
+ after 'deploy:failed', 'sidekiq_systemd:restart'
20
+ after 'deploy:published', 'sidekiq_systemd:start'
21
+ after 'deploy:starting', 'sidekiq_systemd:quiet'
22
+ after 'deploy:updated', 'sidekiq_systemd:stop'
23
+ end
24
+
25
+ desc 'Stop workers from picking up new jobs'
26
+ task :quiet do
27
+ on roles fetch(:sidekiq_systemd_role) do
28
+ sudo :systemctl, 'reload', 'sidekiq-*', raise_on_non_zero_exit: false
29
+ end
30
+ end
31
+
32
+ desc 'Stop running workers gracefully'
33
+ task :stop do
34
+ on roles fetch(:sidekiq_systemd_role) do
35
+ sudo :systemctl, 'stop', 'sidekiq-*'
36
+ end
37
+ end
38
+
39
+ desc 'Start workers'
40
+ task :start do
41
+ on roles fetch(:sidekiq_systemd_role) do
42
+ sudo :systemctl, 'start', 'sidekiq-*', '--all'
43
+ end
44
+ end
45
+
46
+ desc 'Restart workers'
47
+ task :restart do
48
+ on roles fetch(:sidekiq_systemd_role) do
49
+ sudo :systemctl, 'restart', 'sidekiq-*', raise_on_non_zero_exit: false
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,6 @@
1
+ desc "check ssh connections to all app servers"
2
+ task :ssh_check do
3
+ on roles(:app), in: :sequence do
4
+ execute
5
+ end
6
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dlss-capistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
- - Willy Mene
8
+ - Mike Giarlo
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-04-01 00:00:00.000000000 Z
12
+ date: 2020-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.1.0
34
+ version: 0.3.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 0.1.0
41
+ version: 0.3.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: capistrano-one_time_key
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -67,14 +67,16 @@ dependencies:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
- description: Capistrano recipies to assist with the development, testing, and release
71
- of SUL/DLSS Ruby project
70
+ description: Capistrano recipes to assist with development, testing, & deployment
71
+ of SUL/DLSS Ruby projects
72
72
  email:
73
73
  - cabeer@stanford.edu
74
+ - mjgiarlo@stanford.edu
74
75
  executables: []
75
76
  extensions: []
76
77
  extra_rdoc_files: []
77
78
  files:
79
+ - ".github/pull_request_template.md"
78
80
  - ".gitignore"
79
81
  - Gemfile
80
82
  - LICENSE
@@ -83,7 +85,14 @@ files:
83
85
  - dlss-capistrano.gemspec
84
86
  - lib/dlss.rb
85
87
  - lib/dlss/capistrano.rb
88
+ - lib/dlss/capistrano/resque_pool.rb
89
+ - lib/dlss/capistrano/resque_pool/tasks/resque_pool.rake
90
+ - lib/dlss/capistrano/tasks/bundle_config.rake
91
+ - lib/dlss/capistrano/tasks/bundled_sidekiq.rake
92
+ - lib/dlss/capistrano/tasks/deployed_branch.rake
93
+ - lib/dlss/capistrano/tasks/sidekiq_systemd.rake
86
94
  - lib/dlss/capistrano/tasks/ssh.rake
95
+ - lib/dlss/capistrano/tasks/ssh_check.rake
87
96
  - lib/lyberteam-capistrano-devel.rb
88
97
  homepage:
89
98
  licenses:
@@ -104,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
113
  - !ruby/object:Gem::Version
105
114
  version: 1.3.6
106
115
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.7.6
116
+ rubygems_version: 3.1.2
109
117
  signing_key:
110
118
  specification_version: 4
111
- summary: Capistrano recipies for use in SUL/DLSS projects
119
+ summary: Capistrano recipes for use in SUL/DLSS projects
112
120
  test_files: []