capistrano-opscomplete 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: a434f5baae62ed091c04472a4dc20f427a79aadc
4
- data.tar.gz: d4a151042cfaf864fcfe0a9b9b33b6924b3cffa9
3
+ metadata.gz: 9557996df286d6b2ad029eb5915b019a1c158f6e
4
+ data.tar.gz: f53793ef28924bf828c7b9c3a7daa4a9eb4d4c4c
5
5
  SHA512:
6
- metadata.gz: '09ee42b231e8269735885573d3acda6b1a12d46d0813f17b2167e6ac37a1e9ec7edfcbc7c2e554918cbbdeb6a79983afce3f9a50d7f3361657f6220da90b33cf'
7
- data.tar.gz: dfc4c295ea1c29a0366c0a6cbcd8fc4c7fdbdae69d3515d53bace18d02dd386f0a328d4dc2d3fa75117dcea3bba76873024a9e25c3885b74e2da2fa947c6dad7
6
+ metadata.gz: 47efafd91d9cca904694c487043c6b7475a581fe6a625a8f437da6c9ea64251af51f688677e4706c39e5da9441416d141dfac2775c7bf19d75a81cc90d9d47dd
7
+ data.tar.gz: c2ae884f910cbc6fd398d7c3df31c8670cc80e6cb213fbdbf92422629fb25690692016be0b6d71b6df5aeb65984f0f5091fb157780017cb65c3ce5936938442d
@@ -0,0 +1,17 @@
1
+ ## [0.2.0] - 2018-08-28
2
+ ### Added
3
+ - Look up .ruby-version from your local branch (cwd) if other options fail
4
+
5
+ ### Changed
6
+ - Don't use Task#invoke!() to allow support of more capistrano versions (<3.8.2)
7
+ - Update documentation to use other capistrano hook, so release_dir is available
8
+ - .ruby-version lookup precedence now includes local branch (cwd)
9
+ - Fixed a bug where capistrano exits if no ruby version has ever been installed using rbenv
10
+ - Less verbose output while updating ruby-build plugin
11
+ - If no :rbenv_roles have been provided, default to :all role
12
+
13
+ ## 0.1.0 - 2018-07-11
14
+ ### Added
15
+ - Initial release.
16
+
17
+ [0.2.0]: https://github.com/makandra/capistrano-opscomplete/compare/v0.1.0...v0.2.0
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Capistrano::Opscomplete
2
2
 
3
- This gem provides capistrano tasks for convenient deployment to a makandra [OpsComplete for Ruby](https://opscomplete.com/ruby) environment. If you find any bugs or run
4
- into a problem, please drop us a mail or open an issue.
3
+ This gem provides capistrano tasks for convenient deployment to a makandra [OpsComplete for Ruby](https://opscomplete.com/ruby) environment. If you find any bugs or run into a problem, please drop us a mail or open an issue.
5
4
 
6
5
  ## Installation
7
6
 
@@ -27,20 +26,23 @@ require 'capistrano/opscomplete'
27
26
 
28
27
  Verify the gem was installed and tasks are available:
29
28
 
30
- $ bundle exec cap -T | grep opscomplete
29
+ $ bundle exec cap -T opscomplete
31
30
 
32
- Optional: If you want to manage ruby versions for certain roles, set `rbenv_roles` in your `deploy.rb`:
31
+ Now, add some [hooks](#using-capistrano-hooks) in your capistrano configuration. An example configuration could look like this:
33
32
 
34
33
  ```ruby
35
- set :rbenv_roles, :app
34
+ # After unpacking your release, before bundling, compiling assets, ...
35
+ after 'deploy:updating', 'opscomplete:ruby:ensure'
36
+ # After your application has been successfully deployed and the current symlink has been set
37
+ after 'deploy:published', 'opscomplete:appserver:restart'
36
38
  ```
37
39
 
38
- You might also want to configure some hooks, see [using capistrano hooks](#using-capistrano-hooks).
39
-
40
40
  ## Usage
41
41
 
42
- If you encounter any errors, please make sure you have the newest version of the capistrano-opscomplete gem installed. Don't hesitate to
43
- contact the OpsComplete for Ruby team for further support.
42
+ If you encounter any errors, please make sure you have the newest version of the capistrano-opscomplete gem installed. Don't hesitate to contact the OpsComplete for Ruby team for further support.
43
+
44
+ You might also want to configure some hooks to automatically update the ruby version, see [using capistrano hooks](#using-capistrano-hooks).
45
+
44
46
 
45
47
  ### List available tasks
46
48
 
@@ -48,19 +50,19 @@ To see available capistrano tasks, execute:
48
50
 
49
51
  $ bundle exec cap -T
50
52
 
53
+
51
54
  ### opscomplete:ruby:check
52
55
 
53
- The `opscomplete:ruby:check` task checks for a properly configured ruby. It will not try to correct any misconfigurations, but just abort
54
- the capistrano run.
56
+ The `opscomplete:ruby:check` task checks for a properly configured ruby. It will not try to correct any misconfigurations, but just abort the capistrano run.
55
57
 
56
58
  $ bundle exec cap <ENVIRONMENT> opscomplete:ruby:check
57
59
 
58
60
  Where `<ENVIRONMENT>` could be `production`, `staging`, ...
59
61
 
62
+
60
63
  ### opscomplete:ruby:ensure
61
64
 
62
- The `opscomplete:ruby:ensure` task checks for a ruby as requested in application's `.ruby-version` file and will try to correct some
63
- misconfigurations.
65
+ The `opscomplete:ruby:ensure` task checks for a ruby as requested in application's `.ruby-version` file and will try to correct some misconfigurations.
64
66
 
65
67
  $ bundle exec cap <ENVIRONMENT> opscomplete:ruby:ensure
66
68
 
@@ -69,14 +71,16 @@ Where `<ENVIRONMENT>` could be `production`, `staging`, ...
69
71
  More specifically this task will:
70
72
  - Check whether you are running a 'managed ruby' (installed with OpsComplete for Ruby) or if you have to install ruby using this gem or rbenv.
71
73
  - If you are using 'unmanaged ruby':
72
- - Checks if ruby version requested by `.ruby-version` is installed.
73
- - If it is not installed, checks if it can be installed using `ruby-build` and installs it.
74
+ - Check if desired ruby version is installed. The following lookup precedence for the desired version is being used:
75
+ 1) The value of `:opscomplete_ruby_version` from your capistrano config. Leave this empty unless you want to override the desired version.
76
+ 2) A file in the `release_path` on the server (e.g. `/var/www/staging.myapp.biz/releases/20180523234205/.ruby-version`)
77
+ 3) A file in the current working directory of your local checkout (e.g. `/home/user/code/myapp/.ruby-version`)
78
+ - If the desired version is not installed, it checks if it can be installed using `ruby-build` and installs it.
74
79
  - Check if `rbenv global` version is set according to application's `.ruby-version` file. Change it if required.
75
80
  - Install the `bundler` and `geordi` gem if required.
76
81
  - Run `rbenv rehash` if required.
77
82
 
78
- *Note:* If, for any reason, no `.ruby-version` file can be found in your release directory, you may set the following option in
79
- deploy.rb:
83
+ **Note:** If, for any reason, no `.ruby-version` file can be found in your release or current working directory, you may set the following option in deploy.rb:
80
84
 
81
85
  ```ruby
82
86
  set :opscomplete_ruby_version, '<VERSION>'
@@ -84,25 +88,33 @@ set :opscomplete_ruby_version, '<VERSION>'
84
88
 
85
89
  Where `<VERSION>` is the desired ruby version.
86
90
 
91
+ **Optional:** By default, the ruby version is checked/installed for all server roles. If you want to limit the rbenv operations to certain roles, set `rbenv_roles` in your `deploy.rb`:
92
+
93
+ ```ruby
94
+ set :rbenv_roles, :web
95
+ # or
96
+ set :rbenv_roles, [:web, :worker]
97
+ ```
98
+
87
99
  ### opscomplete:appserver:restart
88
100
 
89
101
  To restart your application server execute:
90
102
 
91
103
  $ bundle exec cap <ENVIRONMENT> opscomplete:appserver:restart
92
104
 
93
- Where `<ENVIRONMENT>` could be `production`, `staging`, ...
105
+ Where `<ENVIRONMENT>` could be `production`, `staging**, ...
94
106
 
95
- Note: The current version of this gem only support the passenger app server. The current version of this gem does not support restarting your application, if multiple instances of passenger are running on the same host. This would be the case if you have Apache _and_ Nginx servers running on the same host.
107
+ **Note**: The current version of this gem only support the passenger app server. The current version of this gem does not support restarting your application, if multiple instances of passenger are running on the same host. This would be the case if you have Apache _and_ Nginx servers running on the same host.
96
108
 
97
109
  ### Using capistrano hooks
98
110
 
99
- There are many hooks in the [default deploy flow](https://capistranorb.com/documentation/getting-started/flow/) to integrate tasks into your own deployment configuration. To ensure a ruby version according to your application is installed during deployment, add the following to your `Capfile`.
111
+ There are many hooks available in the [default deploy flow](https://capistranorb.com/documentation/getting-started/flow/) to integrate tasks into your own deployment configuration. To ensure a ruby version according to your application is installed during deployment, add the following to your `Capfile`.
100
112
 
101
113
  ```ruby
102
- before 'deploy:starting', 'opscomplete:ruby:ensure'
114
+ after 'deploy:updating', 'opscomplete:ruby:ensure'
103
115
  after 'deploy:published', 'opscomplete:appserver:restart'
104
116
  ```
105
117
 
106
118
  ## Contributing
107
119
 
108
- Bug reports and pull requests are welcome.
120
+ Bug reports and pull requests are welcome. Don't hesitate to [open a new issue](https://github.com/makandra/capistrano-opscomplete/issues/new).
@@ -19,12 +19,24 @@ module Capistrano
19
19
  end
20
20
 
21
21
  def app_ruby_version
22
- app_ruby_version_file_path = release_path.join('.ruby-version').to_s
22
+ release_ruby_version_file_path = release_path.join('.ruby-version').to_s
23
+
24
+ # 1) Get version from capistrano configuration (highest precedence, 'override')
23
25
  if fetch(:opscomplete_ruby_version)
24
- warn("Using version from :opscomplete_ruby_version setting: #{fetch(:opscomplete_ruby_version)}.")
26
+ debug("Using version from :opscomplete_ruby_version setting: #{fetch(:opscomplete_ruby_version)}.")
25
27
  return fetch(:opscomplete_ruby_version)
26
- elsif test("[ -f #{app_ruby_version_file_path} ]")
27
- return capture(:cat, app_ruby_version_file_path)
28
+
29
+ # 2) Get version from .ruby-version in release dir (after deploy:updating, before deploy:updated)
30
+ elsif test("[ -f #{release_ruby_version_file_path} ]")
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)
33
+
34
+ # 3) Get version from local checkout/cwd
35
+ elsif File.readable?('.ruby-version')
36
+ debug("Using version from local (cwd) .ruby-version file: #{File.read('.ruby-version').strip}")
37
+ return File.read('.ruby-version').strip
38
+
39
+ # FAIL: We have no idea which version to use
28
40
  else
29
41
  raise Capistrano::ValidationError, 'Could not find application\'s .ruby-version. Consider setting opscomplete_ruby_version.'
30
42
  end
@@ -33,7 +45,7 @@ module Capistrano
33
45
  def rbenv_installable_rubies
34
46
  rbenv_installable_rubies = capture(:rbenv, :install, '--list').split("\n")
35
47
  rbenv_installable_rubies.map!(&:strip)
36
- rbenv_installable_rubies.delete("Available version:")
48
+ rbenv_installable_rubies.delete('Available version:')
37
49
  rbenv_installable_rubies
38
50
  end
39
51
 
@@ -42,8 +54,13 @@ module Capistrano
42
54
  end
43
55
 
44
56
  def rbenv_installed_rubies
45
- rbenv_installed_rubies = capture(:ls, '-1', "#{rbenv_root_path}/versions").split("\n")
46
- rbenv_installed_rubies.map!(&:strip)
57
+ if test("[ -d #{rbenv_root_path}/versions ]")
58
+ rbenv_installed_rubies = capture(:ls, '-1', "#{rbenv_root_path}/versions").split("\n")
59
+ return rbenv_installed_rubies.map!(&:strip)
60
+ else
61
+ warn("Could not look up installed versions from missing '.rbenv/versions' directory. This is probably the first ruby install for this rbenv.")
62
+ return []
63
+ end
47
64
  end
48
65
  end
49
66
  end
@@ -11,18 +11,18 @@ namespace :opscomplete do
11
11
  namespace :ruby do
12
12
  # desc 'Rehash rbenv shims (run this after installing executables).'
13
13
  task :rehash do
14
- on roles fetch(:rbenv_roles) do
14
+ on roles fetch(:rbenv_roles, :all) do
15
15
  execute(:rbenv, :rehash)
16
16
  end
17
17
  end
18
18
 
19
19
  desc 'Check if rbenv global ruby is set according to application\'s .ruby-version.'
20
20
  task :check do
21
- on roles fetch(:rbenv_roles) do |host|
21
+ on roles fetch(:rbenv_roles, :all) do |host|
22
22
  warn("#{host}: Managed ruby environment! Won't do any changes to ruby version.") if managed_ruby
23
23
  unless capture(:rbenv, :global) == app_ruby_version
24
24
  raise Capistrano::ValidationError,
25
- "Ruby version is not set according to application's .ruby-version file. Use cap opscomplete:ruby:ensure."
25
+ "#{host}: Ruby version is not set according to application\'s .ruby-version file. Use cap opscomplete:ruby:ensure."
26
26
  end
27
27
  info("#{host}: Required ruby version '#{app_ruby_version}' is installed.")
28
28
  end
@@ -30,7 +30,7 @@ namespace :opscomplete do
30
30
 
31
31
  # desc 'Install rbenv plugin ruby-build'
32
32
  task :install_ruby_build do
33
- on roles fetch(:rbenv_roles) do
33
+ on roles fetch(:rbenv_roles, :all) do
34
34
  next if test "[ -d #{rbenv_ruby_build_path} ]"
35
35
  execute :git, :clone, ruby_build_repo_url, rbenv_ruby_build_path
36
36
  end
@@ -38,10 +38,10 @@ namespace :opscomplete do
38
38
 
39
39
  # desc 'Update rbenv plugin ruby-build'
40
40
  task :update_ruby_build do
41
- on roles fetch(:rbenv_roles) do
41
+ on roles fetch(:rbenv_roles, :all) do
42
42
  if test "[ -d #{rbenv_ruby_build_path} ]"
43
43
  within rbenv_ruby_build_path do
44
- execute :git, :pull
44
+ execute :git, :pull, '-q'
45
45
  end
46
46
  else
47
47
  warn('Could not find ruby-build.')
@@ -51,46 +51,46 @@ namespace :opscomplete do
51
51
 
52
52
  # desc 'Install bundler gem'
53
53
  task :install_bundler do
54
- on roles fetch(:rbenv_roles) do
54
+ on roles fetch(:rbenv_roles, :all) do
55
55
  next if test(:rbenv, :exec, :gem, :query, '--quiet --installed --name-matches ^bundler$')
56
56
  execute(:rbenv, :exec, :gem, :install, :bundler, '--quiet --no-rdoc --no-ri')
57
- invoke!('opscomplete:ruby:rehash')
57
+ set :rbenv_needs_rehash, true
58
58
  end
59
59
  end
60
60
 
61
61
  # desc 'Install geordi gem'
62
62
  task :install_geordi do
63
- on roles fetch(:rbenv_roles) do
63
+ on roles fetch(:rbenv_roles, :all) do
64
64
  next if test(:rbenv, :exec, :gem, :query, '--quiet --installed --name-matches ^geordi$')
65
65
  execute(:rbenv, :exec, :gem, :install, :geordi, '--quiet --no-rdoc --no-ri')
66
- invoke!('opscomplete:ruby:rehash')
66
+ set :rbenv_needs_rehash, true
67
67
  end
68
68
  end
69
69
 
70
70
  desc 'Install and configure ruby according to applications .ruby-version.'
71
71
  task :ensure do
72
- on roles fetch(:rbenv_roles) do |host|
72
+ on roles fetch(:rbenv_roles, :all) do |host|
73
73
  if managed_ruby
74
- raise Capistrano::ValidationError, "Managed ruby environment! Won't do any changes to ruby version."
74
+ raise Capistrano::ValidationError, "#{host}: Managed ruby environment! Won't do any changes to ruby version."
75
75
  end
76
76
  if rbenv_installed_rubies.include?(app_ruby_version)
77
77
  info("#{host}: Required ruby version '#{app_ruby_version}' is installed.")
78
78
  else
79
79
  invoke('opscomplete:ruby:update_ruby_build')
80
80
  if rbenv_installable_rubies.include?(app_ruby_version)
81
- warn('Required ruby version is not installed, but available for installation.')
82
- info("Installing ruby #{app_ruby_version}.")
81
+ info("#{host}: Required ruby version is not installed, but available for installation.")
83
82
  execute(:rbenv, :install, app_ruby_version)
84
- invoke!('opscomplete:ruby:rehash')
83
+ set :rbenv_needs_rehash, true
85
84
  else
86
85
  raise Capistrano::ValidationError,
87
- 'Ruby version required by application is neither installed nor installable using ruby-install.'
86
+ "#{host}: Ruby version required by application is neither installed nor installable using ruby-install."
88
87
  end
89
88
  end
90
89
  execute(:rbenv, :global, app_ruby_version) unless capture(:rbenv, :global) == app_ruby_version
91
90
  end
92
91
  invoke('opscomplete:ruby:install_bundler')
93
92
  invoke('opscomplete:ruby:install_geordi')
93
+ invoke('opscomplete:ruby:rehash') if fetch(:rbenv_needs_rehash, false)
94
94
  end
95
95
  end
96
96
 
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Opscomplete
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Makandra Operations
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-11 00:00:00.000000000 Z
11
+ date: 2018-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,7 @@ executables: []
65
65
  extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
+ - CHANGELOG.md
68
69
  - Gemfile
69
70
  - LICENSE
70
71
  - README.md