capistrano-opscomplete 0.6.3 → 0.6.4

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: 8ab19048934d110250b8fafc444f686dba2467f8d3dec1a70cfebe206f2fb801
4
- data.tar.gz: 49fd120dc3b325fe7356eb1eb7200030e16bb1077a223b6570b53d1f8a1d2b9b
3
+ metadata.gz: e0b8b15686f2822308863e7af85b079aa35e1473fbd23c3ed8a31251686d02b4
4
+ data.tar.gz: 2907023f2972eba8710484f9d2a995b028021e8db4a7b21677672c489f42454f
5
5
  SHA512:
6
- metadata.gz: 1c287a757274a0961a0038b0f20cc1d145ae96645b063565b85cbe4742cb04c554adf2a4ea5ff5a663d7d4c16e9ee54f929af61f49db156942ab78e14d1ed94b
7
- data.tar.gz: cc172a2a4c4c14f053096e1a94bd4c32b711fbeeb1ac6bcbf1ace135c0afe515b1251b712d47d66f71a3ccf1a8a5c5b94e2d737cafdab712e3497d8738bbe90a
6
+ metadata.gz: '0288303aa496066cc38cba7ee7136647c8da697841831efd16dcd2203794225260e7d2564e99d0b1c6a8b5c874e2f67b31bfd90fb9c95c59b65ea4472f37f824'
7
+ data.tar.gz: 35d0304e8b112ee6939bd0c20f93b73c1ec39dcaf753673aa0441f91dd3f46ffb244752c2a3c2098c3d035c7648575e24ec0c3292767aeb602534fae6cdb0f84
@@ -1,3 +1,12 @@
1
+ ## [0.6.4] - 2020-11-19
2
+
3
+ ### Added
4
+ - You can now manage the Node.js version which needs to be installed
5
+ - 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))
6
+
7
+ ### Fixed
8
+ - Added missing namespace for code example
9
+
1
10
  ## [0.6.3] - 2020-07-23
2
11
 
3
12
  ### Fixed
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano-opscomplete (0.6.3)
4
+ capistrano-opscomplete (0.6.4)
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).
@@ -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,4 +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__)
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 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.3'.freeze
3
+ VERSION = '0.6.4'.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.3
4
+ version: 0.6.4
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: 2020-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: makandra-rubocop
@@ -91,6 +91,8 @@ files:
91
91
  - capistrano-opscomplete.gemspec
92
92
  - lib/capistrano/dsl/opscomplete.rb
93
93
  - lib/capistrano/opscomplete.rb
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