capistrano-opscomplete 0.6.2 → 0.6.7

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: 8aabbac9cbd5d4ce1c8b7201690802466c79f380b5d98535e9c8a3201773a5e8
4
- data.tar.gz: bed5187c564efca3b4e50f8976cc1c097dda9e3015dd0bbf91d6e8a445cf5074
3
+ metadata.gz: 342b22962198a630ea6f41463f0cd69cbb5e6edfdd0d66df3b2fe24c5ff81397
4
+ data.tar.gz: 9ded78666b373b6322e0981dc1fad8ad5c6012549bfab62b7740120f54f4972d
5
5
  SHA512:
6
- metadata.gz: 680364a17d2971034fdcd6e998060433fa23db9572fc9718f364b73d24620619bec3b6c3d004e73f9e0b4b7d335e5c244a84f1dc592057ec7ce2079d7e1ad9dd
7
- data.tar.gz: 7ecf151b6799902e90850d95102fed634221e53efa2b39a882e61fc648690b784941868618f00de6619d6dd9c08bdd8e5e2949c2fee7294da0af56ca324bd2fd
6
+ metadata.gz: 99e89af95cf85d01a9a2deb3d43e914c72f3725f1070b099c0b502d0417ba64663d5ec3c5cb740ea801ba7bc05ac96b1d02d2c3728985c370cd4c2698fdc35bf
7
+ data.tar.gz: 354a993896fb9b019b5be292dec3a3dbe9b76fbbba780e5a982b72474a9585829eab2f8feab03c3387a9dd74e84e74bb7466f9bc628677bd4ad9c6bb2a02496b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,35 @@
1
+ ## [0.6.7] - 2021-02-05
2
+
3
+ ### Fixed
4
+ - Fix missing command in opscomplete:nodejs:check
5
+
6
+ ### Changed
7
+ - Improve error message for wrong Node.js version
8
+
9
+ ## [0.6.6] - 2020-12-08
10
+
11
+ ### Fixed
12
+ - Fix the error `undefined method 'after' for main:Object (NoMethodError)` when starting the rails application with capistrano-opscomplete required
13
+
14
+ ## [0.6.5] - 2020-11-20
15
+
16
+ ### Fixed
17
+ - Correct warning message for `opscomplete:ruby:broken_gems_warning`
18
+
19
+ ## [0.6.4] - 2020-11-19
20
+
21
+ ### Added
22
+ - You can now manage the Node.js version which needs to be installed
23
+ - 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))
24
+
25
+ ### Fixed
26
+ - Added missing namespace for code example
27
+
28
+ ## [0.6.3] - 2020-07-23
29
+
30
+ ### Fixed
31
+ - regression after ([#18](https://github.com/makandra/capistrano-opscomplete/issues/18)) was merged
32
+
1
33
  ## [0.6.2] - 2020-07-23
2
34
 
3
35
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano-opscomplete (0.6.2)
4
+ capistrano-opscomplete (0.6.7)
5
5
  capistrano (>= 3.0, < 4.0.0)
6
6
  rake
7
7
 
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
@@ -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).
File without changes
@@ -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
@@ -4,5 +4,6 @@ require 'capistrano/opscomplete/version'
4
4
  require 'rake'
5
5
 
6
6
  load File.expand_path('opscomplete/ruby.rake', __dir__)
7
+ load File.expand_path('opscomplete/nodejs.rake', __dir__)
7
8
  load File.expand_path('opscomplete/supervisor.rake', __dir__)
8
- 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,55 @@
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_get_version, release_path) == 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
+ info("#{host}: Check if the configured Node.js version is part of the installable versions")
47
+ execute :nodejs_installable_versions
48
+ raise Capistrano::ValidationError,
49
+ "#{host}: Configured Node.js version is neither installed nor installable."
50
+ end
51
+ execute(:nodejs_set_version, "'#{app_nodejs_version}'")
52
+ end
53
+ end
54
+ end
55
+ 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
@@ -36,7 +36,7 @@ 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
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Opscomplete
3
- VERSION = '0.6.2'.freeze
3
+ VERSION = '0.6.7'.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.2
4
+ version: 0.6.7
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-07-23 00:00:00.000000000 Z
11
+ date: 2021-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: makandra-rubocop
@@ -89,8 +89,11 @@ files:
89
89
  - bin/console
90
90
  - bin/setup
91
91
  - capistrano-opscomplete.gemspec
92
+ - lib/capistrano-opscomplete.rb
92
93
  - lib/capistrano/dsl/opscomplete.rb
93
94
  - lib/capistrano/opscomplete.rb
95
+ - lib/capistrano/opscomplete/hooks.rb
96
+ - lib/capistrano/opscomplete/nodejs.rake
94
97
  - lib/capistrano/opscomplete/ruby.rake
95
98
  - lib/capistrano/opscomplete/supervisor.rake
96
99
  - lib/capistrano/opscomplete/version.rb