dlss-capistrano 3.4.1 → 3.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/pull_request_template.md +12 -0
- data/README.md +78 -7
- data/dlss-capistrano.gemspec +6 -6
- data/lib/dlss/capistrano.rb +2 -0
- data/lib/dlss/capistrano/tasks/bundle_config.rake +53 -0
- data/lib/dlss/capistrano/tasks/bundled_sidekiq.rake +31 -0
- data/lib/dlss/capistrano/tasks/deployed_branch.rake +10 -0
- data/lib/dlss/capistrano/tasks/sidekiq_systemd.rake +52 -0
- data/lib/dlss/capistrano/tasks/ssh.rake +8 -0
- data/lib/dlss/capistrano/tasks/ssh_check.rake +6 -0
- metadata +17 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4b7211b899ad56e248f23fc755708985d824d75c5f5be60f9df209e7aa530889
|
4
|
+
data.tar.gz: de4c047a15d8388a9b03a291db95923384f6a3e63468302af117b3a96013ffd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75f59b62a79644b31a359530daabae1cf65b8d5d87542c7612081f8866f01df16c3ec67751dac1e8bcd8484f871c921a8a0c4f8845d355dbb934896e61701e23
|
7
|
+
data.tar.gz: '05957df37d899b68b350a776bf2fc70baf1a70492d35145577857e67fd0c02769b938b8a91773dc2d0846f8e30c6d01526e6b3372c1b4d52939b6238922700dc'
|
data/README.md
CHANGED
@@ -1,20 +1,91 @@
|
|
1
1
|
# dlss-capistrano
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/dlss-capistrano.svg)](https://badge.fury.io/rb/dlss-capistrano)
|
4
4
|
|
5
|
-
|
5
|
+
This gem provides Capistrano deployment tasks used by Stanford Libraries' Digital Library Systems and Services group.
|
6
6
|
|
7
|
-
|
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
|
+
### Sidekiq via systemd
|
47
|
+
|
48
|
+
`cap ENV sidekiq_systemd:{quiet,stop,start,restart}`: quiets, stops, starts, restarts Sidekiq via systemd.
|
49
|
+
|
50
|
+
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.
|
51
|
+
|
52
|
+
#### Capistrano role
|
53
|
+
|
54
|
+
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.*:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
set :sidekiq_systemd_role, :worker
|
58
|
+
```
|
59
|
+
|
60
|
+
#### Deployment hooks
|
61
|
+
|
62
|
+
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`:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
set :sidekiq_systemd_use_hooks, true
|
66
|
+
```
|
67
|
+
|
68
|
+
These are the hooks provided if you opt in:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
after 'deploy:failed', 'sidekiq_systemd:restart'
|
72
|
+
after 'deploy:published', 'sidekiq_systemd:start'
|
73
|
+
after 'deploy:starting', 'sidekiq_systemd:quiet'
|
74
|
+
after 'deploy:updated', 'sidekiq_systemd:stop'
|
75
|
+
```
|
76
|
+
|
77
|
+
## Assumptions
|
78
|
+
|
79
|
+
dlss-capistrano makes the following assumptions about your Ruby project
|
8
80
|
|
9
81
|
- You are using Capistrano 3+
|
10
82
|
- You use git for source control
|
11
|
-
- The server you deploy to uses rvm, it is installed
|
83
|
+
- The server you deploy to uses rvm, it is installed system-wide, and is the default system ruby
|
12
84
|
- You do not have an .rvmrc checked into git (should be in your .gitignore)
|
13
85
|
- You will not use rvm gemsets on the server you deploy to
|
14
86
|
- Bundler will install specified gems into {your_project_home}/shared/bundle directory
|
15
87
|
- Will deploy from the master branch, unless you set :branch to another branch or tag
|
16
88
|
|
89
|
+
## Copyright
|
17
90
|
|
18
|
-
|
19
|
-
|
20
|
-
Copyright (c) 2015 Stanford University Library. See LICENSE for details.
|
91
|
+
Copyright (c) 2020 Stanford University. See LICENSE for details.
|
data/dlss-capistrano.gemspec
CHANGED
@@ -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.
|
7
|
+
s.version = "3.9.0"
|
8
8
|
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
|
-
s.authors = ["Chris Beer",
|
11
|
-
s.email = ["cabeer@stanford.edu"]
|
12
|
-
s.summary = "Capistrano
|
13
|
-
s.description = "Capistrano
|
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.
|
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
|
|
data/lib/dlss/capistrano.rb
CHANGED
@@ -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,8 @@
|
|
1
|
+
desc "ssh to the current directory on the server"
|
2
|
+
task :ssh do
|
3
|
+
on roles(:app), :primary => true do |host|
|
4
|
+
command = "cd #{fetch(:deploy_to)}/current && exec $SHELL -l"
|
5
|
+
puts command if fetch(:log_level) == :debug
|
6
|
+
exec "ssh -l #{host.user} #{host.hostname} -p #{host.port || 22} -t '#{command}'"
|
7
|
+
end
|
8
|
+
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.
|
4
|
+
version: 3.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
|
-
-
|
8
|
+
- Mike Giarlo
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-06-22 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.
|
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.
|
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
|
71
|
-
of SUL/DLSS Ruby
|
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,6 +85,12 @@ files:
|
|
83
85
|
- dlss-capistrano.gemspec
|
84
86
|
- lib/dlss.rb
|
85
87
|
- lib/dlss/capistrano.rb
|
88
|
+
- lib/dlss/capistrano/tasks/bundle_config.rake
|
89
|
+
- lib/dlss/capistrano/tasks/bundled_sidekiq.rake
|
90
|
+
- lib/dlss/capistrano/tasks/deployed_branch.rake
|
91
|
+
- lib/dlss/capistrano/tasks/sidekiq_systemd.rake
|
92
|
+
- lib/dlss/capistrano/tasks/ssh.rake
|
93
|
+
- lib/dlss/capistrano/tasks/ssh_check.rake
|
86
94
|
- lib/lyberteam-capistrano-devel.rb
|
87
95
|
homepage:
|
88
96
|
licenses:
|
@@ -103,9 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
111
|
- !ruby/object:Gem::Version
|
104
112
|
version: 1.3.6
|
105
113
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.5.2
|
114
|
+
rubygems_version: 3.0.3
|
108
115
|
signing_key:
|
109
116
|
specification_version: 4
|
110
|
-
summary: Capistrano
|
117
|
+
summary: Capistrano recipes for use in SUL/DLSS projects
|
111
118
|
test_files: []
|