capistrano-opscomplete 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +6 -0
- data/LICENSE +9 -0
- data/README.md +108 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/capistrano-opscomplete.gemspec +36 -0
- data/lib/capistrano-opscomplete.rb +0 -0
- data/lib/capistrano/dsl/opscomplete.rb +50 -0
- data/lib/capistrano/opscomplete.rb +4 -0
- data/lib/capistrano/opscomplete/deploy.rake +10 -0
- data/lib/capistrano/opscomplete/tasks.rake +105 -0
- data/lib/capistrano/opscomplete/version.rb +5 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a434f5baae62ed091c04472a4dc20f427a79aadc
|
4
|
+
data.tar.gz: d4a151042cfaf864fcfe0a9b9b33b6924b3cffa9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '09ee42b231e8269735885573d3acda6b1a12d46d0813f17b2167e6ac37a1e9ec7edfcbc7c2e554918cbbdeb6a79983afce3f9a50d7f3361657f6220da90b33cf'
|
7
|
+
data.tar.gz: dfc4c295ea1c29a0366c0a6cbcd8fc4c7fdbdae69d3515d53bace18d02dd386f0a328d4dc2d3fa75117dcea3bba76873024a9e25c3885b74e2da2fa947c6dad7
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 makandra GmbH
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Capistrano::Opscomplete
|
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.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Include the gem in your applications Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'capistrano-opscomplete'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it manually with:
|
19
|
+
|
20
|
+
$ gem install capistrano-opscomplete
|
21
|
+
|
22
|
+
Now, include the DSL extensions and tasks by adding the following line to your `Capfile` _after_ `capistrano/deploy`:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'capistrano/opscomplete'
|
26
|
+
```
|
27
|
+
|
28
|
+
Verify the gem was installed and tasks are available:
|
29
|
+
|
30
|
+
$ bundle exec cap -T | grep opscomplete
|
31
|
+
|
32
|
+
Optional: If you want to manage ruby versions for certain roles, set `rbenv_roles` in your `deploy.rb`:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
set :rbenv_roles, :app
|
36
|
+
```
|
37
|
+
|
38
|
+
You might also want to configure some hooks, see [using capistrano hooks](#using-capistrano-hooks).
|
39
|
+
|
40
|
+
## Usage
|
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.
|
44
|
+
|
45
|
+
### List available tasks
|
46
|
+
|
47
|
+
To see available capistrano tasks, execute:
|
48
|
+
|
49
|
+
$ bundle exec cap -T
|
50
|
+
|
51
|
+
### opscomplete:ruby:check
|
52
|
+
|
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.
|
55
|
+
|
56
|
+
$ bundle exec cap <ENVIRONMENT> opscomplete:ruby:check
|
57
|
+
|
58
|
+
Where `<ENVIRONMENT>` could be `production`, `staging`, ...
|
59
|
+
|
60
|
+
### opscomplete:ruby:ensure
|
61
|
+
|
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.
|
64
|
+
|
65
|
+
$ bundle exec cap <ENVIRONMENT> opscomplete:ruby:ensure
|
66
|
+
|
67
|
+
Where `<ENVIRONMENT>` could be `production`, `staging`, ...
|
68
|
+
|
69
|
+
More specifically this task will:
|
70
|
+
- 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
|
+
- 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 `rbenv global` version is set according to application's `.ruby-version` file. Change it if required.
|
75
|
+
- Install the `bundler` and `geordi` gem if required.
|
76
|
+
- Run `rbenv rehash` if required.
|
77
|
+
|
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:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
set :opscomplete_ruby_version, '<VERSION>'
|
83
|
+
```
|
84
|
+
|
85
|
+
Where `<VERSION>` is the desired ruby version.
|
86
|
+
|
87
|
+
### opscomplete:appserver:restart
|
88
|
+
|
89
|
+
To restart your application server execute:
|
90
|
+
|
91
|
+
$ bundle exec cap <ENVIRONMENT> opscomplete:appserver:restart
|
92
|
+
|
93
|
+
Where `<ENVIRONMENT>` could be `production`, `staging`, ...
|
94
|
+
|
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.
|
96
|
+
|
97
|
+
### Using capistrano hooks
|
98
|
+
|
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`.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
before 'deploy:starting', 'opscomplete:ruby:ensure'
|
103
|
+
after 'deploy:published', 'opscomplete:appserver:restart'
|
104
|
+
```
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
Bug reports and pull requests are welcome.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "capistrano/opscomplete"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "capistrano/opscomplete/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "capistrano-opscomplete"
|
7
|
+
spec.version = Capistrano::Opscomplete::VERSION
|
8
|
+
spec.authors = ["Makandra Operations"]
|
9
|
+
spec.email = ["ops@makandra.de"]
|
10
|
+
|
11
|
+
spec.summary = %q{Capistrano tasks for easy deployment to a makandra opscomplete environment.}
|
12
|
+
spec.homepage = "https://opscomplete.com/ruby"
|
13
|
+
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
if spec.respond_to?(:metadata)
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
else
|
19
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
20
|
+
"public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^((test|spec|features)/|.gitignore|.rubocop.yml)}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
|
35
|
+
spec.add_dependency 'capistrano', '>=3.0', '<4.0.0'
|
36
|
+
end
|
File without changes
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module DSL
|
3
|
+
# A whole capistrano/rake namespace, for grouping our helpers and tasks
|
4
|
+
module Opscomplete
|
5
|
+
def managed_ruby
|
6
|
+
test("[ -f #{rbenv_root_path}/.ruby_managed_by_makandra ]")
|
7
|
+
end
|
8
|
+
|
9
|
+
def rbenv_ruby_build_path
|
10
|
+
"#{rbenv_root_path}/plugins/ruby-build"
|
11
|
+
end
|
12
|
+
|
13
|
+
def rbenv_repo_url
|
14
|
+
'https://github.com/rbenv/rbenv.git'
|
15
|
+
end
|
16
|
+
|
17
|
+
def ruby_build_repo_url
|
18
|
+
'https://github.com/rbenv/ruby-build.git'
|
19
|
+
end
|
20
|
+
|
21
|
+
def app_ruby_version
|
22
|
+
app_ruby_version_file_path = release_path.join('.ruby-version').to_s
|
23
|
+
if fetch(:opscomplete_ruby_version)
|
24
|
+
warn("Using version from :opscomplete_ruby_version setting: #{fetch(:opscomplete_ruby_version)}.")
|
25
|
+
return fetch(:opscomplete_ruby_version)
|
26
|
+
elsif test("[ -f #{app_ruby_version_file_path} ]")
|
27
|
+
return capture(:cat, app_ruby_version_file_path)
|
28
|
+
else
|
29
|
+
raise Capistrano::ValidationError, 'Could not find application\'s .ruby-version. Consider setting opscomplete_ruby_version.'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def rbenv_installable_rubies
|
34
|
+
rbenv_installable_rubies = capture(:rbenv, :install, '--list').split("\n")
|
35
|
+
rbenv_installable_rubies.map!(&:strip)
|
36
|
+
rbenv_installable_rubies.delete("Available version:")
|
37
|
+
rbenv_installable_rubies
|
38
|
+
end
|
39
|
+
|
40
|
+
def rbenv_root_path
|
41
|
+
capture(:rbenv, :root)
|
42
|
+
end
|
43
|
+
|
44
|
+
def rbenv_installed_rubies
|
45
|
+
rbenv_installed_rubies = capture(:ls, '-1', "#{rbenv_root_path}/versions").split("\n")
|
46
|
+
rbenv_installed_rubies.map!(&:strip)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,105 @@
|
|
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:ruby:check')
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :ruby do
|
12
|
+
# desc 'Rehash rbenv shims (run this after installing executables).'
|
13
|
+
task :rehash do
|
14
|
+
on roles fetch(:rbenv_roles) do
|
15
|
+
execute(:rbenv, :rehash)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Check if rbenv global ruby is set according to application\'s .ruby-version.'
|
20
|
+
task :check do
|
21
|
+
on roles fetch(:rbenv_roles) do |host|
|
22
|
+
warn("#{host}: Managed ruby environment! Won't do any changes to ruby version.") if managed_ruby
|
23
|
+
unless capture(:rbenv, :global) == app_ruby_version
|
24
|
+
raise Capistrano::ValidationError,
|
25
|
+
"Ruby version is not set according to application's .ruby-version file. Use cap opscomplete:ruby:ensure."
|
26
|
+
end
|
27
|
+
info("#{host}: Required ruby version '#{app_ruby_version}' is installed.")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# desc 'Install rbenv plugin ruby-build'
|
32
|
+
task :install_ruby_build do
|
33
|
+
on roles fetch(:rbenv_roles) do
|
34
|
+
next if test "[ -d #{rbenv_ruby_build_path} ]"
|
35
|
+
execute :git, :clone, ruby_build_repo_url, rbenv_ruby_build_path
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# desc 'Update rbenv plugin ruby-build'
|
40
|
+
task :update_ruby_build do
|
41
|
+
on roles fetch(:rbenv_roles) do
|
42
|
+
if test "[ -d #{rbenv_ruby_build_path} ]"
|
43
|
+
within rbenv_ruby_build_path do
|
44
|
+
execute :git, :pull
|
45
|
+
end
|
46
|
+
else
|
47
|
+
warn('Could not find ruby-build.')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# desc 'Install bundler gem'
|
53
|
+
task :install_bundler do
|
54
|
+
on roles fetch(:rbenv_roles) do
|
55
|
+
next if test(:rbenv, :exec, :gem, :query, '--quiet --installed --name-matches ^bundler$')
|
56
|
+
execute(:rbenv, :exec, :gem, :install, :bundler, '--quiet --no-rdoc --no-ri')
|
57
|
+
invoke!('opscomplete:ruby:rehash')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# desc 'Install geordi gem'
|
62
|
+
task :install_geordi do
|
63
|
+
on roles fetch(:rbenv_roles) do
|
64
|
+
next if test(:rbenv, :exec, :gem, :query, '--quiet --installed --name-matches ^geordi$')
|
65
|
+
execute(:rbenv, :exec, :gem, :install, :geordi, '--quiet --no-rdoc --no-ri')
|
66
|
+
invoke!('opscomplete:ruby:rehash')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
desc 'Install and configure ruby according to applications .ruby-version.'
|
71
|
+
task :ensure do
|
72
|
+
on roles fetch(:rbenv_roles) do |host|
|
73
|
+
if managed_ruby
|
74
|
+
raise Capistrano::ValidationError, "Managed ruby environment! Won't do any changes to ruby version."
|
75
|
+
end
|
76
|
+
if rbenv_installed_rubies.include?(app_ruby_version)
|
77
|
+
info("#{host}: Required ruby version '#{app_ruby_version}' is installed.")
|
78
|
+
else
|
79
|
+
invoke('opscomplete:ruby:update_ruby_build')
|
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}.")
|
83
|
+
execute(:rbenv, :install, app_ruby_version)
|
84
|
+
invoke!('opscomplete:ruby:rehash')
|
85
|
+
else
|
86
|
+
raise Capistrano::ValidationError,
|
87
|
+
'Ruby version required by application is neither installed nor installable using ruby-install.'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
execute(:rbenv, :global, app_ruby_version) unless capture(:rbenv, :global) == app_ruby_version
|
91
|
+
end
|
92
|
+
invoke('opscomplete:ruby:install_bundler')
|
93
|
+
invoke('opscomplete:ruby:install_geordi')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
namespace :appserver do
|
98
|
+
desc 'Restart Application'
|
99
|
+
task :restart do
|
100
|
+
on roles :app do
|
101
|
+
execute "sudo passenger-config restart-app --ignore-app-not-running #{fetch(:deploy_to)}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-opscomplete
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Makandra Operations
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capistrano
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 4.0.0
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3.0'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 4.0.0
|
61
|
+
description:
|
62
|
+
email:
|
63
|
+
- ops@makandra.de
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- capistrano-opscomplete.gemspec
|
75
|
+
- lib/capistrano-opscomplete.rb
|
76
|
+
- lib/capistrano/dsl/opscomplete.rb
|
77
|
+
- lib/capistrano/opscomplete.rb
|
78
|
+
- lib/capistrano/opscomplete/deploy.rake
|
79
|
+
- lib/capistrano/opscomplete/tasks.rake
|
80
|
+
- lib/capistrano/opscomplete/version.rb
|
81
|
+
homepage: https://opscomplete.com/ruby
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata:
|
85
|
+
allowed_push_host: https://rubygems.org
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.6.13
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Capistrano tasks for easy deployment to a makandra opscomplete environment.
|
106
|
+
test_files: []
|