baboon 1.0.6 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -10
- data/Rakefile +1 -1
- data/lib/baboon/cli/options.rb +13 -15
- data/lib/baboon/cli.rb +74 -57
- data/lib/baboon/version.rb +1 -1
- data/spec/lib/baboon/cli_spec.rb +34 -0
- data/spec/lib/baboon/configuration_spec.rb +9 -7
- data/spec/spec_helper.rb +41 -0
- metadata +5 -5
- data/spec/lib/baboon/cli.rb +0 -0
data/README.md
CHANGED
@@ -14,20 +14,18 @@ Baboon is simple. You provide your server addresses, environments, path, reposit
|
|
14
14
|
# Install
|
15
15
|
This must be installed under a current rails application. We recommend vendoring or installing through bundler.
|
16
16
|
|
17
|
-
gem install baboon
|
17
|
+
$ gem install baboon
|
18
18
|
|
19
19
|
---
|
20
20
|
# Configure
|
21
21
|
|
22
22
|
In your Gemfile, then `bundle install`.
|
23
23
|
|
24
|
-
|
25
|
-
gem 'baboon'
|
26
|
-
end
|
24
|
+
gem 'baboon'
|
27
25
|
|
28
26
|
Now that the gem is installed, run the config generator
|
29
27
|
|
30
|
-
rails g baboon:install
|
28
|
+
$ rails g baboon:install
|
31
29
|
|
32
30
|
This will build a file into your application under `config/initializers/baboon.rb`. Open this file and start editing. Here is an example of the main configuration options:
|
33
31
|
|
@@ -45,13 +43,17 @@ These must be properly filled out so baboon can properly make deploys.
|
|
45
43
|
|
46
44
|
---
|
47
45
|
# Commands
|
48
|
-
Once everything is setup you can run `baboon` to see
|
46
|
+
Once everything is setup you can run `baboon` to see available commands. Start by seeing if your configuration was properly generated by running the following command:
|
47
|
+
|
48
|
+
$ baboon configuration
|
49
|
+
|
50
|
+
Once you see and verify your Baboon.configuration you can now go ahead and test a deploy. For now, lets assume you have everything in your config correct and you are deploying to production, run the following command to do a cold deploy:
|
49
51
|
|
50
|
-
baboon
|
52
|
+
$ baboon deploy
|
51
53
|
|
52
|
-
|
54
|
+
To view the available servers you have setup in your config file, the following command will tell you which servers are set to be deploy to:
|
53
55
|
|
54
|
-
baboon
|
56
|
+
$ baboon servers
|
55
57
|
|
56
58
|
Thats it? Yeah, thats it! You should see your bundle installing and Baboon running all tasks. Custom tasks coming soon.
|
57
59
|
|
@@ -91,7 +93,7 @@ Intial setup of the CLI and basic deploys are working.
|
|
91
93
|
Multiple server deployments now work.
|
92
94
|
|
93
95
|
#### 1.0.6
|
94
|
-
Changed the order of bundle installing on Rails package
|
96
|
+
Changed the order of bundle installing on Rails package. Wrote tests for CLI.
|
95
97
|
|
96
98
|
## How to contribute
|
97
99
|
|
data/Rakefile
CHANGED
data/lib/baboon/cli/options.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'baboon/version'
|
2
3
|
|
3
4
|
module Baboon
|
4
5
|
class CLI
|
@@ -20,9 +21,6 @@ module Baboon
|
|
20
21
|
# The hash of (parsed) command-line options
|
21
22
|
attr_reader :options
|
22
23
|
|
23
|
-
# Return an OptionParser instance that defines the acceptable command
|
24
|
-
# line switches for Capistrano, and what their corresponding behaviors
|
25
|
-
# are.
|
26
24
|
def option_parser #:nodoc:
|
27
25
|
@logger = Logger.new
|
28
26
|
@option_parser ||= OptionParser.new do |opts|
|
@@ -58,13 +56,13 @@ module Baboon
|
|
58
56
|
"Choose logger method. STDERR used by default."
|
59
57
|
) do |value|
|
60
58
|
options[:output] = if value.nil? || value.upcase == 'STDERR'
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
59
|
+
# Using default logger.
|
60
|
+
nil
|
61
|
+
elsif value.upcase == 'STDOUT'
|
62
|
+
$stdout
|
63
|
+
else
|
64
|
+
value
|
65
|
+
end
|
68
66
|
end
|
69
67
|
|
70
68
|
opts.on("-n", "--dry-run",
|
@@ -113,10 +111,10 @@ module Baboon
|
|
113
111
|
) { options[:tool] = true }
|
114
112
|
|
115
113
|
opts.on("-V", "--version",
|
116
|
-
"Display the
|
114
|
+
"Display the Baboon version, and exit."
|
117
115
|
) do
|
118
|
-
require '
|
119
|
-
puts "
|
116
|
+
require 'baboon/version'
|
117
|
+
puts "Baboon v#{Baboon::Version}"
|
120
118
|
exit
|
121
119
|
end
|
122
120
|
|
@@ -128,7 +126,7 @@ module Baboon
|
|
128
126
|
end
|
129
127
|
|
130
128
|
opts.on("-X", "--skip-system-config",
|
131
|
-
"Don't load the system config file (
|
129
|
+
"Don't load the system config file (Baboon.configuration)"
|
132
130
|
) { options.delete(:sysconf) }
|
133
131
|
|
134
132
|
opts.on("-x", "--skip-user-config",
|
@@ -199,7 +197,7 @@ module Baboon
|
|
199
197
|
end
|
200
198
|
|
201
199
|
def default_sysconf #:nodoc:
|
202
|
-
File.join(sysconf_directory, "
|
200
|
+
File.join(sysconf_directory, "Baboon.configuration")
|
203
201
|
end
|
204
202
|
|
205
203
|
def default_dotfile #:nodoc:
|
data/lib/baboon/cli.rb
CHANGED
@@ -2,12 +2,16 @@ require 'baboon'
|
|
2
2
|
require 'baboon/configuration'
|
3
3
|
require 'baboon/logger'
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'find'
|
6
6
|
require 'net/ssh'
|
7
|
+
require 'thor'
|
7
8
|
|
8
9
|
module Baboon
|
9
10
|
class Error
|
10
11
|
class << self
|
12
|
+
# stop
|
13
|
+
# @param:
|
14
|
+
# @return: StandardError class, will halt execution of program
|
11
15
|
def stop reason
|
12
16
|
raise StandardError, reason
|
13
17
|
end
|
@@ -16,6 +20,41 @@ module Baboon
|
|
16
20
|
|
17
21
|
class Util
|
18
22
|
class << self
|
23
|
+
# file_check!
|
24
|
+
# @param: String file path
|
25
|
+
# @return: Boolean || String depending on if file is found
|
26
|
+
def file_check! file
|
27
|
+
return false if file.nil? || !file
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# locate_file
|
32
|
+
# Will try and locate the baboon.rb file it it does not exist. Great method
|
33
|
+
# used especially for testing Baboon.
|
34
|
+
# @param:
|
35
|
+
# @return: String[file path, used to locate and initialize the configuration file]
|
36
|
+
def locate_file
|
37
|
+
config_file = ''
|
38
|
+
default_baboon_file_path = "config/initializers/baboon.rb"
|
39
|
+
if File.exists?(default_baboon_file_path)
|
40
|
+
config_file = default_baboon_file_path
|
41
|
+
else
|
42
|
+
Find.find('.') do |path|
|
43
|
+
if path.include?('baboon.rb')
|
44
|
+
next unless File.open(path, &:readline).include?('Baboon.configure do |config|')
|
45
|
+
config_file = path
|
46
|
+
break
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
config_file
|
51
|
+
end
|
52
|
+
|
53
|
+
# read_configuration
|
54
|
+
# This will attempt to read the configuration file, only need until after the file
|
55
|
+
# is found in the application.
|
56
|
+
# @param: String[file path, relative to the directory of the configuration]
|
57
|
+
# @return: Hash[configuration options in the config file, use these to set Baboon.configuration]
|
19
58
|
def read_configuration(file)
|
20
59
|
configuration = []
|
21
60
|
line_number = 0
|
@@ -39,20 +78,36 @@ module Baboon
|
|
39
78
|
end
|
40
79
|
|
41
80
|
class Cli < Thor
|
42
|
-
|
81
|
+
# @logger: call an instance of the logger class, use throughout baboon
|
82
|
+
# @configuration: holds the default baboon configuration set in config file
|
83
|
+
# @configuration_file: the exact file location of baboon configuration
|
84
|
+
attr_accessor :logger, :configuration, :configuration_file, :block
|
43
85
|
|
86
|
+
# initialize
|
87
|
+
# @param: Array
|
88
|
+
# @ereturn: instance
|
44
89
|
def initialize(*args)
|
45
90
|
super
|
91
|
+
$stdout.sync ||= true
|
46
92
|
@logger ||= Logger.new({level: 3, disable_formatters: false})
|
47
93
|
|
48
|
-
|
94
|
+
# Attempt to locate the configuration file in the project if it was not set.
|
95
|
+
@configuration_file = Util.locate_file
|
96
|
+
|
97
|
+
# Return if file not found
|
98
|
+
if @configuration_file.nil? || @configuration_file == ''
|
99
|
+
printf "\033[22;31mB\033[22;35ma\033[22;36mb\033[22;32mo\033[01;31mo\033[01;33mn\033[22;37m - version #{Baboon::VERSION}\n"
|
100
|
+
printf " \033[22;31mError:\033[22;37m no configuration file is present anywhere in the application or at config/initializers/baboon.rb\n"
|
101
|
+
printf " \033[01;32mUsage:\033[22;37m rails g baboon:install\n"
|
102
|
+
@block = true
|
103
|
+
return
|
104
|
+
end
|
49
105
|
|
50
106
|
# Load the users baboon configuration
|
51
|
-
if File.exists?(
|
52
|
-
@configuration = Util.read_configuration(
|
107
|
+
if File.exists?(@configuration_file) # tad redundant
|
108
|
+
@configuration = Util.read_configuration(@configuration_file)
|
53
109
|
|
54
110
|
# configure the servers
|
55
|
-
|
56
111
|
Baboon.configure do |config|
|
57
112
|
config.application = @configuration[:application]
|
58
113
|
config.repository = @configuration[:repository]
|
@@ -61,16 +116,19 @@ module Baboon
|
|
61
116
|
config.branch = @configuration[:branch]
|
62
117
|
config.rails_env = @configuration[:rails_env]
|
63
118
|
config.servers = @configuration[:servers].gsub('[', '').gsub(']', '').split(',').collect(&:strip)
|
64
|
-
end
|
119
|
+
end
|
65
120
|
else
|
66
|
-
|
67
|
-
printf
|
68
|
-
printf
|
121
|
+
printf "\033[22;31mB\033[22;35mA\033[22;36mB\033[22;32mO\033[01;31mO\033[01;33mN\033[22;37m - version #{Baboon::VERSION}\n"
|
122
|
+
printf " \033[22;31mError:\033[22;37m no configuration file is present anywhere in the application or at config/initializers/baboon.rb\n"
|
123
|
+
printf " \033[01;32mUsage:\033[22;37m rails g baboon:install\n"
|
124
|
+
@block = true
|
125
|
+
return
|
69
126
|
end
|
70
127
|
end
|
71
128
|
|
72
|
-
desc "deploy", "
|
129
|
+
desc "deploy", "Deploys the application to the configured servers."
|
73
130
|
def deploy
|
131
|
+
return if @block
|
74
132
|
printf @logger.format("== Baboon starting deploy", "32", 1)
|
75
133
|
|
76
134
|
# Loop through each server and do deploy, we will add threading later to do simultaneous deploys
|
@@ -97,8 +155,7 @@ module Baboon
|
|
97
155
|
|
98
156
|
Net::SSH.start(credentials[:host], credentials[:user]) do |session|
|
99
157
|
instructions.each do |instruction|
|
100
|
-
|
101
|
-
puts ""
|
158
|
+
printf "[#{current}]: #{instruction}\n"
|
102
159
|
session.exec instruction
|
103
160
|
session.loop
|
104
161
|
end
|
@@ -108,8 +165,9 @@ module Baboon
|
|
108
165
|
printf @logger.format("== Baboon deploy Complete", "31", 1)
|
109
166
|
end
|
110
167
|
|
111
|
-
desc "configuration", "Shows the current configuration for baboon"
|
112
|
-
def configuration
|
168
|
+
desc "configuration", "Shows the current configuration for baboon."
|
169
|
+
def configuration
|
170
|
+
return if @block
|
113
171
|
printf @logger.format("Baboon[Application]: #{Baboon.configuration.application}", "37", 1)
|
114
172
|
printf @logger.format("Baboon[Repository]: #{Baboon.configuration.repository}", "37", 1)
|
115
173
|
printf @logger.format("Baboon[Deploy_path]: #{Baboon.configuration.deploy_path}", "37", 1)
|
@@ -118,46 +176,5 @@ module Baboon
|
|
118
176
|
printf @logger.format("Baboon[Rails_env]: #{Baboon.configuration.rails_env}", "37", 1)
|
119
177
|
printf @logger.format("Baboon[Servers]: #{Baboon.configuration.servers}", "37", 1)
|
120
178
|
end
|
121
|
-
|
122
|
-
desc "servers", "Shows the current servers that will get deployed to"
|
123
|
-
def servers
|
124
|
-
printf @logger.format(Baboon.configuration.servers.inspect, "31", 1)
|
125
|
-
end
|
126
|
-
|
127
|
-
# desc "init", "Generates deployment customization scripts for your app"
|
128
|
-
# def init
|
129
|
-
# require 'generators/baboon/install/intall_generator'
|
130
|
-
# InstallGenerator::start([])
|
131
|
-
# end
|
132
|
-
#
|
133
|
-
# desc "restart", "Restarts the application on the server"
|
134
|
-
# def restart
|
135
|
-
# run "cd #{deploy_to} && deploy/restart | tee -a log/deploy.log"
|
136
|
-
# end
|
137
|
-
#
|
138
|
-
# desc "rollback", "Rolls back the checkout to before the last push"
|
139
|
-
# def rollback
|
140
|
-
# run "cd #{deploy_to} && git reset --hard ORIG_HEAD"
|
141
|
-
# invoke :restart
|
142
|
-
# end
|
143
|
-
#
|
144
|
-
# desc "log", "Shows the last part of the deploy log on the server"
|
145
|
-
# method_option :tail, :aliases => '-t', :type => :boolean, :default => false
|
146
|
-
# method_option :lines, :aliases => '-l', :type => :numeric, :default => 20
|
147
|
-
# def log(n = nil)
|
148
|
-
# tail_args = options.tail? ? '-f' : "-n#{n || options.lines}"
|
149
|
-
# run "tail #{tail_args} #{deploy_to}/log/deploy.log"
|
150
|
-
# end
|
151
|
-
#
|
152
|
-
# desc "upload <files>", "Copy local files to the remote app"
|
153
|
-
# def upload(*files)
|
154
|
-
# files = files.map { |f| Dir[f.strip] }.flatten
|
155
|
-
# abort "Error: Specify at least one file to upload" if files.empty?
|
156
|
-
#
|
157
|
-
# scp_upload files.inject({}) { |all, file|
|
158
|
-
# all[file] = File.join(deploy_to, file)
|
159
|
-
# all
|
160
|
-
# }
|
161
|
-
# end
|
162
179
|
end
|
163
|
-
end
|
180
|
+
end
|
data/lib/baboon/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Baboon::Cli do
|
4
|
+
describe "#initialize" do
|
5
|
+
before do
|
6
|
+
$stdout.sync ||= true
|
7
|
+
end
|
8
|
+
|
9
|
+
context "when a proper configuration file is in the current path" do
|
10
|
+
context "when `baboon` is called from the command line with no parameters" do
|
11
|
+
it "gives the proper output and usage for baboon" do
|
12
|
+
content = capture(:stdout) { Baboon::Cli.start([]) }
|
13
|
+
expect(content).to match(/Tasks:\n/)
|
14
|
+
expect(content).to match(/configuration # Shows the current configuration for baboon.\n/)
|
15
|
+
expect(content).to match(/deploy # Deploys the application to the configured servers.\n/)
|
16
|
+
expect(content).to match(/help \[TASK\] # Describe available tasks or one specific task\n\n/)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when `baboon configuration` is called from the command line" do
|
21
|
+
it "it lists the configuration settings for the current baboon installation" do
|
22
|
+
content = capture(:stdout) { Baboon::Cli.start(['configuration']) }
|
23
|
+
expect(content).to match(/Baboon\[Application\]: console/)
|
24
|
+
expect(content).to match(/Baboon\[Repository\]: git@github.com:128lines\/console.fm.git/)
|
25
|
+
expect(content).to match(/Baboon\[Deploy_path\]: \/home\/rails\/console.fm\//)
|
26
|
+
expect(content).to match(/Baboon\[Deploy_user\]: :rails/)
|
27
|
+
expect(content).to match(/Baboon\[Branch\]: :master/)
|
28
|
+
expect(content).to match(/Baboon\[Rails_env\]: :production/)
|
29
|
+
expect(content).to match(/Baboon\[Servers\]: \[\"10.0.0.1\", \"10.0.0.1\"\]/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end #intiailize do
|
34
|
+
end #describe Baboon::Cli do
|
@@ -3,7 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe Baboon::Configuration do
|
4
4
|
describe 'configuration object should respond accordingly if not configured' do
|
5
5
|
before do
|
6
|
-
Baboon.configure do |config
|
6
|
+
Baboon.configure do |config|
|
7
|
+
config.application = nil
|
8
|
+
config.repository = nil
|
9
|
+
config.deploy_path = nil
|
10
|
+
config.deploy_user = nil
|
11
|
+
config.branch = nil
|
12
|
+
config.rails_env = nil
|
13
|
+
config.servers = nil
|
14
|
+
end
|
7
15
|
end
|
8
16
|
|
9
17
|
context 'when nothing is given for application' do
|
@@ -103,11 +111,5 @@ describe Baboon::Configuration do
|
|
103
111
|
Baboon.configuration.servers.should eq(['server_1', 'server_2'])
|
104
112
|
end
|
105
113
|
end
|
106
|
-
|
107
|
-
context 'when multiple servers are assigned' do
|
108
|
-
it 'should return accordingly' do
|
109
|
-
# puts Baboon.configuration.servers.inspect
|
110
|
-
end
|
111
|
-
end
|
112
114
|
end
|
113
115
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,11 +6,52 @@ end
|
|
6
6
|
ENV['RAILS_ENV'] ||= 'test'
|
7
7
|
require File.expand_path('../../lib/baboon', __FILE__)
|
8
8
|
|
9
|
+
Dir["spec/support/**/*.rb"].each { |f| require f }
|
10
|
+
|
9
11
|
PROJECT_ROOT = File.expand_path('../..', __FILE__)
|
10
12
|
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
|
11
13
|
|
14
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
15
|
+
|
12
16
|
RSpec.configure do |config|
|
13
17
|
config.color_enabled = true
|
14
18
|
config.tty = true
|
15
19
|
config.mock_with :rspec
|
20
|
+
|
21
|
+
config.before(:each) do
|
22
|
+
ARGV.clear
|
23
|
+
$stdout.sync ||= true
|
24
|
+
end
|
25
|
+
|
26
|
+
# Captures the output for analysis later
|
27
|
+
#
|
28
|
+
# @example Capture `$stderr`
|
29
|
+
#
|
30
|
+
# output = capture(:stderr) { $stderr.puts "this is captured" }
|
31
|
+
#
|
32
|
+
# @param [Symbol] stream `:stdout` or `:stderr`
|
33
|
+
# @yield The block to capture stdout/stderr for.
|
34
|
+
# @return [String] The contents of $stdout or $stderr
|
35
|
+
def capture(stream)
|
36
|
+
begin
|
37
|
+
stream = stream.to_s
|
38
|
+
eval "$#{stream} = StringIO.new"
|
39
|
+
yield
|
40
|
+
result = eval("$#{stream}").string
|
41
|
+
ensure
|
42
|
+
eval("$#{stream} = #{stream.upcase}")
|
43
|
+
end
|
44
|
+
|
45
|
+
result
|
46
|
+
end
|
47
|
+
|
48
|
+
# Silences the output stream
|
49
|
+
#
|
50
|
+
# @example Silence `$stdout`
|
51
|
+
#
|
52
|
+
# silence(:stdout) { $stdout.puts "hi" }
|
53
|
+
#
|
54
|
+
# @param [IO] stream The stream to use such as $stderr or $stdout
|
55
|
+
# @return [nil]
|
56
|
+
alias :silence :capture
|
16
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baboon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -256,7 +256,7 @@ files:
|
|
256
256
|
- lib/generators/baboon/config/templates/baboon.yml
|
257
257
|
- lib/generators/baboon/install/install_generator.rb
|
258
258
|
- lib/generators/baboon/install/templates/baboon.rb
|
259
|
-
- spec/lib/baboon/
|
259
|
+
- spec/lib/baboon/cli_spec.rb
|
260
260
|
- spec/lib/baboon/configuration_spec.rb
|
261
261
|
- spec/lib/baboon_spec.rb
|
262
262
|
- spec/lib/generators/baboon/install/install_generator_spec.rb
|
@@ -277,7 +277,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
277
277
|
version: '0'
|
278
278
|
segments:
|
279
279
|
- 0
|
280
|
-
hash: -
|
280
|
+
hash: -4459336840231193725
|
281
281
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
282
282
|
none: false
|
283
283
|
requirements:
|
@@ -286,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
286
286
|
version: '0'
|
287
287
|
segments:
|
288
288
|
- 0
|
289
|
-
hash: -
|
289
|
+
hash: -4459336840231193725
|
290
290
|
requirements: []
|
291
291
|
rubyforge_project: baboon
|
292
292
|
rubygems_version: 1.8.24
|
data/spec/lib/baboon/cli.rb
DELETED
File without changes
|