capistrano-hostmenu 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d795ea1362f08f1483ed9bc56e9e8370df5c0b1c
4
+ data.tar.gz: 27471bb378fb5a8eb14972c98785df573164e91a
5
+ SHA512:
6
+ metadata.gz: 6712121f3e1dd486dd87ee1372d785f0bca0a64786eea8a78f6833a433b740a4dc0e328e41e01e4baf7178ab4b5cc35fd661b8b8b076e035c68b4379b4cf0153
7
+ data.tar.gz: 8d35b3e09c4e23d975adeb9d5a8887d4193e86f04bd9a59a219681979f20fc8077aed871d0c50fc25debc72c1f14f60232a8600a85b9c56d81f7c9f57f71d765
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-hostmenu (0.1.0)
5
+ capistrano (>= 3.0.0)
6
+
7
+ GEM
8
+ specs:
9
+ capistrano (3.3.5)
10
+ capistrano-stats (~> 1.1.0)
11
+ i18n
12
+ rake (>= 10.0.0)
13
+ sshkit (~> 1.3)
14
+ capistrano-stats (1.1.1)
15
+ colorize (0.7.5)
16
+ i18n (0.7.0)
17
+ net-scp (1.2.1)
18
+ net-ssh (>= 2.6.5)
19
+ net-ssh (2.9.2)
20
+ rake (10.4.2)
21
+ sshkit (1.6.1)
22
+ colorize (>= 0.7.0)
23
+ net-scp (>= 1.1.2)
24
+ net-ssh (>= 2.8.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler
31
+ capistrano-hostmenu!
32
+ rake
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # capistrano-hostmenu
2
+ A capistrano plugin which allows you to choose deploy host via a text menu.
3
+
4
+ Here's an example:
5
+
6
+ ~~~sh
7
+ Please choose which server(s) to deploy:
8
+ [1] example1.com
9
+ [2] example2.com
10
+ [3] all (default)
11
+ Please enter host_numbers (3):
12
+ ~~~
13
+
14
+ ## Installation
15
+
16
+ ~~~sh
17
+ gem install capistrano-hostmenu
18
+ ~~~
19
+
20
+ or put this in your `Gemfile` then run `bundle install`:
21
+
22
+ ~~~ruby
23
+ gem 'capistrano-hostmenu'
24
+ ~~~
25
+
26
+ After the gem is installed, put this in your `Capfile`:
27
+
28
+ ~~~ruby
29
+ require 'capistrano/hostmenu'
30
+ ~~~
31
+
32
+ Then you will see host selecting menu any time before deploying.
33
+
34
+ ## Configurations
35
+
36
+ set these variables in your deploy config (commonly `deploy.rb`)
37
+
38
+ ~~~ruby
39
+ set :host_menu_prompt_msg, 'Please choose which server(s) to deploy:'.blue
40
+ set :host_menu_default_selection, :all # or :first, 1
41
+ set :host_menu_caption_of_all, 'all'
42
+ set :host_menu_caption_of_default, '(default)'
43
+ set :host_menu_invalid_range_msg, 'Please provide a number in (1..%d)'.red
44
+ set :host_menu_invalid_multi_choose_msg, 'Do you mean to choose all servers?'.red
45
+ ~~~
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+
10
+ # Generate documentation
11
+ YARD::Rake::YardocTask.new(:doc) do |t|
12
+ #t.files = %w{lib/hsf.rb}
13
+ end
14
+
15
+ ## Developping tasks
16
+ require "rake/extensiontask"
17
+
18
+ # `rake compile` to compile
19
+ Rake::ExtensionTask.new "hsf" do |ext|
20
+ ext.name = "hsf_cpp"
21
+ end
@@ -0,0 +1,100 @@
1
+ module Capistrano
2
+
3
+ class Hostmenu
4
+
5
+ include ::Capistrano::DSL
6
+
7
+ def self.set_default_config
8
+ set :host_menu_prompt_msg, 'Please choose which server(s) to deploy:'.blue
9
+ set :host_menu_default_selection, :all # or :first, 1
10
+ set :host_menu_caption_of_all, 'all'
11
+ set :host_menu_caption_of_default, '(default)'
12
+ set :host_menu_invalid_range_msg, 'Please provide a number in (1..%d)'.red
13
+ set :host_menu_invalid_multi_choose_msg, 'Do you mean to choose all servers?'.red
14
+ end
15
+
16
+ def initialize
17
+ if deploy_hosts.size > 1
18
+ prompt_menu default: fetch(:host_menu_default_selection)
19
+ end
20
+ end
21
+
22
+ def prompt_menu default: :all
23
+ puts fetch(:host_menu_prompt_msg)
24
+
25
+ default = input_for(default)
26
+ default_cap = fetch(:host_menu_caption_of_default)
27
+
28
+ (deploy_hosts + [fetch(:host_menu_caption_of_all)]).each_with_index do |host, i|
29
+ cap = if i == default - 1
30
+ "[%d] %s %s" % [i+1, host, default_cap]
31
+ else
32
+ "[%d] %s" % [i+1, host]
33
+ end
34
+ puts " " << cap.green
35
+ end
36
+
37
+ ask :host_numbers, default.to_s
38
+ set_hosts
39
+ end
40
+
41
+ private
42
+
43
+ def input_for selection
44
+ case selection
45
+ when :all
46
+ max_selection
47
+ when 0
48
+ 1
49
+ when Fixnum
50
+ selection
51
+ else
52
+ 1
53
+ end
54
+ end
55
+
56
+ def max_selection
57
+ deploy_hosts.size + 1
58
+ end
59
+
60
+ def deploy_hosts
61
+ release_roles(:all)
62
+ end
63
+
64
+ def selection_for_all
65
+ max_selection
66
+ end
67
+
68
+ def set_hosts
69
+ ids = fetch(:host_numbers).split(/\s*,\s*/).map(&:to_i).uniq
70
+ unless ids.all? {|i| (1..max_selection).include? i}
71
+ puts fetch(:host_menu_invalid_range_msg) % max_selection
72
+ exit 1
73
+ end
74
+
75
+ if ids.size > 1 && ids.include?(selection_for_all)
76
+ puts fetch(:host_menu_invalid_multi_choose_msg)
77
+ exit 1
78
+ end
79
+
80
+ unless ids.include?(selection_for_all)
81
+ set_host_filter ids.map {|i| deploy_hosts[i-1].hostname}
82
+ end
83
+ end
84
+
85
+ def set_host_filter hosts
86
+ if defined? Capistrano::Configuration::Servers::HostFilter
87
+ set :filter, hosts: hosts
88
+ else
89
+ # hack for Capistrano v3.3+
90
+ Capistrano::Configuration.env.send(:servers).send(:servers).select! do |srv|
91
+ hosts.include?(srv.hostname)
92
+ end
93
+ end
94
+ end
95
+
96
+ end
97
+ end
98
+
99
+ load File.expand_path('../tasks/hostmenu.rake', __FILE__)
100
+
@@ -0,0 +1,40 @@
1
+ namespace :deploy do
2
+
3
+ desc 'print environment variables'
4
+ task :info do
5
+ puts "--" * 50
6
+ puts "About to deploy, check your seatbelt~"
7
+ puts "env: #{fetch(:rails_env).bold.blue}"
8
+ puts "branch: #{fetch(:branch).bold.green}"
9
+ puts "server: #{roles(:all).map(&:hostname).join("\n ").red}"
10
+ puts "--" * 50
11
+ end
12
+
13
+ desc <<-DESC
14
+ Prompt a text based list menu for user to select. \
15
+ Following changes will only be applied on selected servers.
16
+
17
+ User will see menu like this:
18
+
19
+ ~~~
20
+ Please select target host(s):
21
+ [1] my.example1.com
22
+ [2] my.example2.com
23
+ [3] all (default)
24
+ Please enter host_numbers (3):
25
+ ~~~
26
+ DESC
27
+ task :host_menu do
28
+ next if fetch(:show_host_menu) == false
29
+
30
+ Capistrano::Hostmenu.new
31
+ invoke 'deploy:info' unless fetch(:host_menu_show_info_after_select) == false
32
+ end
33
+ end
34
+
35
+
36
+ Capistrano::Hostmenu.set_default_config
37
+
38
+ Capistrano::DSL.stages.each do |stage|
39
+ after stage, 'deploy:host_menu'
40
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-hostmenu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - qhwa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email: qhwa@163.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files:
60
+ - README.md
61
+ files:
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - README.md
65
+ - Rakefile
66
+ - lib/capistrano/hostmenu.rb
67
+ - lib/capistrano/tasks/hostmenu.rake
68
+ homepage: https://github.com/qhwa/capistrano-hostmenu
69
+ licenses: []
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options:
73
+ - "--main"
74
+ - README.md
75
+ require_paths:
76
+ - lib
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.5
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Capistrano plugin that prompt a text menu to choose target host.
94
+ test_files: []
95
+ has_rdoc: false