capistrano-opscomplete 0.6.0 → 0.6.5

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: 2c5c6ec21950e64171120fc314ea2b909ceb7262fd1175732a93f5897b9a6933
4
- data.tar.gz: daa695ea2c44e828cd82ee95c37cecc8ab6257421d1c8e7b05b5876cf5912a46
3
+ metadata.gz: 4338dafea7ab6110c0e31e90aedce65d26ae913cb34e637336e367fcf847ad65
4
+ data.tar.gz: 98a5dbee6e6b063e0354473e37eba77c0a29ed6c3234f7dc26e39a6862597614
5
5
  SHA512:
6
- metadata.gz: 93c67f0e7960afb7b4c691cdd170b43215cc119b236beebe9b4bfb492dca3ca9d55d7e819d56bd034415c833669b0196291a6ff904c9df16c2dcb251d8e04243
7
- data.tar.gz: 558e16c5063b40ff09ca57c0c4312454622cb3ca91a1b4817a1465ef8a424a65513162378792c97a5bf433b9ac130c411e7ac0ce8c367b75e34d5e859387408e
6
+ metadata.gz: 4d8ab6821a98cb0de4f94fde3e91925cf8e02d4427add9f7055c8b4cf08eb825d0f074b0cc4c80abec33a10c8f031e12d8b1e583355fad26e1d73cb9bfe8f920
7
+ data.tar.gz: ba7615f7868f66f31ee84050ffc2de14a450c91265b38d74774f3849c17cd737332889fb32dff1e9742656ab3c6a80858265ca81895b923b4e80b44974a478f8
@@ -0,0 +1 @@
1
+ 2.6.6
@@ -1,4 +1,36 @@
1
- ## Unreleased
1
+ ## [0.6.5] - 2020-11-20
2
+
3
+ ### Fixed
4
+ - Correct warning message for `opscomplete:ruby:broken_gems_warning`
5
+
6
+ ## [0.6.4] - 2020-11-19
7
+
8
+ ### Added
9
+ - You can now manage the Node.js version which needs to be installed
10
+ - Add two new capistrano tasks (`opscomplete:ruby:broken_gems_warning`, `opscomplete:ruby:reset`) which help to mitigate problems when a deployment fails (described in: [#19](https://github.com/makandra/capistrano-opscomplete/issues/19))
11
+
12
+ ### Fixed
13
+ - Added missing namespace for code example
14
+
15
+ ## [0.6.3] - 2020-07-23
16
+
17
+ ### Fixed
18
+ - regression after ([#18](https://github.com/makandra/capistrano-opscomplete/issues/18)) was merged
19
+
20
+ ## [0.6.2] - 2020-07-23
21
+
22
+ ### Fixed
23
+ - rbenv-build changed behaviour of `--list` ([#20](https://github.com/makandra/capistrano-opscomplete/issues/20))
24
+
25
+ ### Changed
26
+ - Bumped rack dependency from 2.1.1 to 2.2.3
27
+
28
+ ## [0.6.1] - 2020-04-16
29
+ ### Added
30
+ - Use Ruby 2.6 for development
31
+
32
+ ### Changed
33
+ - Add rake as a runtime dependency
2
34
 
3
35
  ## [0.6.0] - 2020-01-13
4
36
  ### Added
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano-opscomplete (0.6.0)
4
+ capistrano-opscomplete (0.6.5)
5
5
  capistrano (>= 3.0, < 4.0.0)
6
+ rake
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -15,8 +16,8 @@ GEM
15
16
  i18n
16
17
  rake (>= 10.0.0)
17
18
  sshkit (>= 1.9.0)
18
- concurrent-ruby (1.1.5)
19
- i18n (1.8.2)
19
+ concurrent-ruby (1.1.6)
20
+ i18n (1.8.4)
20
21
  concurrent-ruby (~> 1.0)
21
22
  jaro_winkler (1.5.4)
22
23
  makandra-rubocop (4.2.0)
@@ -28,9 +29,9 @@ GEM
28
29
  parallel (1.19.1)
29
30
  parser (2.7.0.2)
30
31
  ast (~> 2.4.0)
31
- rack (2.1.1)
32
+ rack (2.2.3)
32
33
  rainbow (3.0.0)
33
- rake (10.5.0)
34
+ rake (13.0.1)
34
35
  rubocop (0.76.0)
35
36
  jaro_winkler (~> 1.5.1)
36
37
  parallel (~> 1.10)
@@ -54,7 +55,6 @@ DEPENDENCIES
54
55
  bundler (~> 2)
55
56
  capistrano-opscomplete!
56
57
  makandra-rubocop (~> 4)
57
- rake (~> 10.0)
58
58
 
59
59
  BUNDLED WITH
60
60
  2.1.4
data/README.md CHANGED
@@ -36,7 +36,13 @@ An example configuration could look like this:
36
36
  after 'deploy:updating', 'opscomplete:ruby:ensure'
37
37
  ```
38
38
 
39
- and in case you enabled [`Procfile support`](https://makandracards.com/opscomplete/67829-procfile-support) you can use the following tasks:
39
+ If you want to handle the ruby version for rollbacks too, you should add:
40
+
41
+ ```ruby
42
+ after 'deploy:reverting', 'opscomplete:ruby:ensure'
43
+ ```
44
+
45
+ And in case you enabled [`Procfile support`](https://makandracards.com/opscomplete/67829-procfile-support) you can use the following tasks:
40
46
 
41
47
  opscomplete:supervisor:gen_config
42
48
  opscomplete:supervisor:restart_procs
@@ -59,7 +65,7 @@ To change the role where these tasks will get executed, set `:procfile_role` in
59
65
  set :procfile_role, :sidekiq
60
66
  ```
61
67
 
62
- If you want to run different Procfiles on differen servers, you can set the `:procfile` property in your `config/deploy/${env}.rb`:
68
+ If you want to run different Procfiles on different servers, you can set the `:procfile` property in your `config/deploy/${env}.rb`:
63
69
 
64
70
  ```
65
71
  # In this example, `Procfile` will get used for supervisor on srv2.example.com and `Procfile.sidekiq` for supervisor on srv1.example.com.
@@ -151,6 +157,24 @@ There are many hooks available in the [default deploy flow](https://capistranorb
151
157
  after 'deploy:updating', 'opscomplete:ruby:ensure'
152
158
  ```
153
159
 
160
+ ## Managing your nodejs version with `capistrano-opscomplete`
161
+
162
+ You can manage NodeJS also with `capistrano-opscomplete`. It will check the `.nvmrc`, `.node-version` and `.tool-versions` in the release direcotry (in this order) or you can configure it with `:opscomplete_nodejs_version` in your capistrano configuration.
163
+
164
+ Include the gem in your applications Gemfile:
165
+
166
+ ```ruby
167
+ gem 'capistrano-opscomplete'
168
+ ```
169
+
170
+ Now, add some [hooks](#using-capistrano-hooks) in your capistrano configuration (e.g. `deploy.rb`).
171
+ An example configuration could look like this:
172
+
173
+ ```ruby
174
+ # After unpacking your release, before bundling, compiling assets, ...
175
+ after 'deploy:updating', 'opscomplete:nodejs:ensure'
176
+ ```
177
+
154
178
  ## Contributing
155
179
 
156
180
  Bug reports and pull requests are welcome. Don't hesitate to [open a new issue](https://github.com/makandra/capistrano-opscomplete/issues/new).
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
38
38
 
39
39
  spec.add_development_dependency 'makandra-rubocop', '~> 4'
40
40
  spec.add_development_dependency 'bundler', '~> 2'
41
- spec.add_development_dependency 'rake', '~> 10.0'
42
41
 
42
+ spec.add_dependency 'rake'
43
43
  spec.add_dependency 'capistrano', '>=3.0', '<4.0.0'
44
44
  end
@@ -24,17 +24,17 @@ module Capistrano
24
24
  # 1) Get version from capistrano configuration (highest precedence, 'override')
25
25
  if fetch(:opscomplete_ruby_version)
26
26
  debug("Using version from :opscomplete_ruby_version setting: #{fetch(:opscomplete_ruby_version)}.")
27
- return fetch(:opscomplete_ruby_version)
27
+ fetch(:opscomplete_ruby_version)
28
28
 
29
29
  # 2) Get version from .ruby-version in release dir (after deploy:updating, before deploy:updated)
30
30
  elsif test("[ -f #{release_ruby_version_file_path} ]")
31
31
  debug("Using version from server's release_dir/.ruby-version file: #{capture(:cat, release_ruby_version_file_path)}")
32
- return capture(:cat, release_ruby_version_file_path)
32
+ capture(:cat, release_ruby_version_file_path)
33
33
 
34
34
  # 3) Get version from local checkout/cwd
35
35
  elsif File.readable?('.ruby-version')
36
36
  debug("Using version from local (cwd) .ruby-version file: #{File.read('.ruby-version').strip}")
37
- return File.read('.ruby-version').strip
37
+ File.read('.ruby-version').strip
38
38
 
39
39
  # FAIL: We have no idea which version to use
40
40
  else
@@ -65,7 +65,7 @@ module Capistrano
65
65
  end
66
66
 
67
67
  def rbenv_installable_rubies
68
- rbenv_installable_rubies = capture(:rbenv, :install, '--list').split("\n")
68
+ rbenv_installable_rubies = capture(:rbenv, :install, '--list-all').split("\n")
69
69
  rbenv_installable_rubies.map!(&:strip)
70
70
  rbenv_installable_rubies.delete('Available version:')
71
71
  rbenv_installable_rubies
@@ -108,6 +108,38 @@ module Capistrano
108
108
  def rubygems_install(version)
109
109
  rbenv_exec("gem update --no-document --system '#{version}'")
110
110
  end
111
+
112
+ def managed_nodejs?
113
+ test("[ -f ${HOME}/.nodejs_managed_by_makandra ]")
114
+ end
115
+
116
+ def app_nodejs_version
117
+
118
+ # 1) Get version from capistrano configuration (highest precedence, 'override')
119
+ if fetch(:opscomplete_nodejs_version)
120
+ debug("Using version from :opscomplete_nodejs_version setting: #{fetch(:opscomplete_nodejs_version)}.")
121
+ fetch(:opscomplete_nodejs_version)
122
+
123
+ # 2) Get version from version file in release dir (after deploy:updating, before deploy:updated)
124
+ elsif capture(:nodejs_get_version, release_path)
125
+ debug("Using version from server's release_dir/.nvmrc, .node-version or .tool-versions file: #{capture(:nodejs_get_version, release_path)}")
126
+ capture(:nodejs_get_version, release_path)
127
+
128
+ else
129
+ raise Capistrano::ValidationError, 'Could not find application\'s Node.js version. Consider setting opscomplete_ruby_version.'
130
+ end
131
+ end
132
+
133
+ def nodejs_installable_versions
134
+ nodejs_installable_versions = capture(:nodejs_installable_versions).split("\n")
135
+ nodejs_installable_versions.map!(&:strip)
136
+ nodejs_installable_versions
137
+ end
138
+
139
+ def nodejs_installed_versions
140
+ nodejs_installed_versions = capture(:nodejs_installed_versions).split("\n")
141
+ nodejs_installed_versions.map!(&:strip)
142
+ end
111
143
  end
112
144
  end
113
145
  end
@@ -1,5 +1,9 @@
1
1
  require 'capistrano/opscomplete/version'
2
2
 
3
+ # Need to require rake before we can use the Rake DSL (task do ..., namespace do, ...)
4
+ require 'rake'
5
+
3
6
  load File.expand_path('opscomplete/ruby.rake', __dir__)
7
+ load File.expand_path('opscomplete/nodejs.rake', __dir__)
4
8
  load File.expand_path('opscomplete/supervisor.rake', __dir__)
5
- load File.expand_path('opscomplete/deploy.rake', __dir__)
9
+ load File.expand_path('../opscomplete/hooks.rb', __FILE__)
@@ -0,0 +1 @@
1
+ after 'deploy:failed', 'opscomplete:ruby:broken_gems_warning'
@@ -0,0 +1,53 @@
1
+ # vim: filetype=ruby
2
+ require 'capistrano/dsl/opscomplete'
3
+
4
+ namespace :opscomplete do
5
+ include Capistrano::DSL::Opscomplete
6
+ # desc 'Validate opscomplete specific configuration'
7
+ task :validate do
8
+ invoke('opscomplete:nodejs:check')
9
+ end
10
+
11
+ namespace :nodejs do
12
+ desc 'Check if nodejs version is set according to application\'s .node-version or .nvmrc (in this order).'
13
+ task :check do
14
+ on roles fetch(:nodejs_roles, :all) do |host|
15
+ warn("#{host}: Managed Node.js environment! Won't do any changes to nodejs version.") if managed_nodejs?
16
+ unless capture(:nodejs_current_version) == app_nodejs_version
17
+ raise Capistrano::ValidationError,
18
+ "#{host}: Node.js version is not set according to application\'s .node-version or .nvmrc file. Use cap opscomplete:nodejs:ensure."
19
+ end
20
+ info("#{host}: Node.js #{app_nodejs_version} is installed.")
21
+ end
22
+ end
23
+
24
+ desc 'Update Node.js version management tool'
25
+ task :update_nodejs_build do
26
+ on roles fetch(:nodejs_roles, :all) do
27
+ execute :nodejs_update_management_tool
28
+ end
29
+ end
30
+
31
+ desc 'Install and configure NodeJS according to applications .nvmrc, .node-version or .tool-versions.'
32
+ task :ensure do
33
+ invoke('opscomplete:nodejs:update_nodejs_build')
34
+ on roles fetch(:nodejs_roles, :all) do |host|
35
+ if managed_nodejs?
36
+ raise Capistrano::ValidationError, "#{host}: Managed Node.js environment! Won't do any changes to Node.js version."
37
+ end
38
+ if nodejs_installed_versions.include?(app_nodejs_version)
39
+ info("#{host}: Node.js #{app_nodejs_version} is installed.")
40
+ elsif nodejs_installable_versions.include?(app_nodejs_version)
41
+ info("#{host}: Configured Node.js version is not installed, but available for installation.")
42
+ with tmpdir: fetch(:tmp_dir) do
43
+ execute(:nodejs_install_version, "'#{app_nodejs_version}'")
44
+ end
45
+ else
46
+ raise Capistrano::ValidationError,
47
+ "#{host}: Configured Node.js version is neither installed nor installable."
48
+ end
49
+ execute(:nodejs_set_version, "'#{app_nodejs_version}'")
50
+ end
51
+ end
52
+ end
53
+ end
@@ -106,12 +106,52 @@ namespace :opscomplete do
106
106
  raise Capistrano::ValidationError,
107
107
  "#{host}: Configured Ruby version is neither installed nor installable using ruby-install."
108
108
  end
109
- execute(:rbenv, :global, "'#{app_ruby_version}'") unless capture(:rbenv, :global) == app_ruby_version
109
+ unless capture(:rbenv, :global) == app_ruby_version
110
+ set :ruby_modified, true
111
+ execute(:rbenv, :global, "'#{app_ruby_version}'")
112
+ end
110
113
  end
111
114
  invoke('opscomplete:ruby:install_rubygems')
112
115
  invoke('opscomplete:ruby:install_bundler')
113
116
  invoke('opscomplete:ruby:install_geordi')
114
117
  invoke('opscomplete:ruby:rehash') if fetch(:rbenv_needs_rehash, false)
115
118
  end
119
+
120
+ desc 'resets the global ruby version and gems to Gemfile and .ruby-version in current_path.'
121
+ task :reset do
122
+ on roles fetch(:rbenv_roles, :all) do |host|
123
+ within current_path do
124
+ current_ruby_version_file_path = current_path.join('.ruby-version').to_s
125
+ if test("[ -f #{current_ruby_version_file_path} ]")
126
+ execute(:rbenv, :global, capture(:cat, current_ruby_version_file_path))
127
+ else
128
+ raise Capistrano::ValidationError,
129
+ "#{host}: Missing .ruby-version in #{current_path}. Won't set a new global version."
130
+ end
131
+ if test("[ -f '#{current_path}/.bundle/config' ]")
132
+ debug("#{host}: Found #{current_path}/.bundle/config, running bundle pristine.")
133
+ set :bundle_gemfile, -> { current_path.join('Gemfile') }
134
+ execute(:bundle, :pristine)
135
+ else
136
+ raise Capistrano::ValidationError,
137
+ "Unable to find #{current_path}/.bundle/config, won't run bundle pristine."
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ desc 'Set the old ruby version before the change and invoke bundle pristine.'
144
+ task :broken_gems_warning do
145
+ on roles fetch(:rbenv_roles, :all) do |host|
146
+ if fetch(:ruby_modified, false)
147
+ warn("Deploy failed and the ruby version has been modified in this deploy.")
148
+ warn("If this was a minor ruby version upgrade your running application may run into issues with native gem extensions.")
149
+ warn("If your deploy failed before deploy:symlink:release you may run bundle exec `cap #{fetch(:stage)} opscomplete:ruby:reset`.")
150
+ warn("Please refer https://makandracards.com/makandra/477884-bundler-in-deploy-mode-shares-gems-between-patch-level-ruby-versions")
151
+ else
152
+ debug("#{host}: Ruby not modified in current deploy.")
153
+ end
154
+ end
155
+ end
116
156
  end
117
157
  end
@@ -27,7 +27,7 @@ namespace :opscomplete do
27
27
  end
28
28
  end
29
29
  end
30
-
30
+
31
31
  # Can be used for example to quiet sidekiq with a task like this:
32
32
  #
33
33
  # namespace :sidekiq do
@@ -36,12 +36,12 @@ namespace :opscomplete do
36
36
  # on roles :cron do
37
37
  # # The TSTP signal tells sidekiq to quiet all workers.
38
38
  # # see: https://github.com/mperham/sidekiq/wiki/Signals#tstp
39
- # invoke('supervisor:signal_procs', 'TSTP', 'sidekiq')
39
+ # invoke('opscomplete:supervisor:signal_procs', 'TSTP', 'sidekiq')
40
40
  # end
41
41
  # end
42
42
  # end
43
43
  desc 'Sends the signal (e.g. USR1 or TSTP) to all programs or if specified to program_name.'
44
- task :signal_procs, :signal, :program_name do |task_name, args|
44
+ task :signal_procs, :signal, :program_name do |_task_name, args|
45
45
  signal = args.fetch(:signal)
46
46
  program_name = args.fetch(:program_name, nil)
47
47
 
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Opscomplete
3
- VERSION = '0.6.0'.freeze
3
+ VERSION = '0.6.5'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-opscomplete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Makandra Operations
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-13 00:00:00.000000000 Z
11
+ date: 2020-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: makandra-rubocop
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
48
- type: :development
47
+ version: '0'
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: capistrano
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +79,7 @@ executables: []
79
79
  extensions: []
80
80
  extra_rdoc_files: []
81
81
  files:
82
+ - ".ruby-version"
82
83
  - CHANGELOG.md
83
84
  - Gemfile
84
85
  - Gemfile.lock
@@ -90,7 +91,8 @@ files:
90
91
  - capistrano-opscomplete.gemspec
91
92
  - lib/capistrano/dsl/opscomplete.rb
92
93
  - lib/capistrano/opscomplete.rb
93
- - lib/capistrano/opscomplete/deploy.rake
94
+ - lib/capistrano/opscomplete/hooks.rb
95
+ - lib/capistrano/opscomplete/nodejs.rake
94
96
  - lib/capistrano/opscomplete/ruby.rake
95
97
  - lib/capistrano/opscomplete/supervisor.rake
96
98
  - lib/capistrano/opscomplete/version.rb
@@ -1,10 +0,0 @@
1
- namespace :deploy do
2
- desc 'Show deployed revision'
3
- task :revision do
4
- on roles :app do
5
- within current_path do
6
- info "Revision: #{capture(:cat, 'REVISION')}"
7
- end
8
- end
9
- end
10
- end