baboon 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/baboon.rb CHANGED
@@ -4,23 +4,10 @@
4
4
  # are persisted throughout the entire Baboon configuration and as well
5
5
  # as the config initializer baboon.rb file that is generated in the
6
6
  # standing Rails application.
7
- #
8
- # option[:application] String => Has no berrance to the deployment, call it whatever.
9
- # option[:repository] String => For now baboon only supports Git. This should be the actual Git repository of the application baboon will deploy.
10
- # option[:deploy_path] String => The actual deploy path the application will sit at on the server. Exactly where the app's .git/ folder would be.
11
- # option[:deploy_user] String/Symbol => The user baboon will be authenticating with on the server. Should have your key stored for optimal authentication.
12
- # option[:branch] String/Symbol => The branch on your repository baboon will be pulling from.
13
- # option[:rails_env] String/Symbol => For rake tasks to be run properly on your server, baboon needs to know what env it will be running on your server.
14
- # option[:server] Array[String] => This will be an array of ip addresses of the servers baboon will deploy to.
15
- BABOON_CONFIGURATION_OPTIONS = [
16
- :application, # => This will be the name of the Application - not the directory
17
- :repository, # => This will be the :scm of the repository the application will be cloning
18
- :deploy_path, # => This will be the actual deploy path of the application, should have /home/#{user}/app
19
- :deploy_user, # => This will be the user the system will authenticate with to do the deploy, should have sudo
20
- :branch, # => Branch we will be cloning from on GIT
21
- :rails_env, # => The rails environment the sever will be running
22
- :servers # => An array of servers baboon will push to
23
- ]
7
+
8
+ # Nicely formatted output of the Baboon title
9
+ BABOON_TITLE = "\033[22;31mB\033[22;35ma\033[22;36mb\033[22;32mo\033[01;31mo\033[01;33mn\033[22;37m"
10
+ BABOON_ENVIRONMENT_SETTINGS = ['branch', 'deploy_path', 'deploy_user', 'rails_env', 'servers']
24
11
 
25
12
  require 'baboon/configuration'
26
13
  require 'baboon/cli'
data/lib/baboon/cli.rb CHANGED
@@ -1,87 +1,18 @@
1
1
  require 'baboon'
2
2
  require 'baboon/configuration'
3
- require 'baboon/logger'
3
+ require 'baboon/util'
4
4
 
5
5
  require 'find'
6
6
  require 'net/ssh'
7
7
  require 'thor'
8
+ require 'yaml'
8
9
 
9
- module Baboon
10
- class Error
11
- class << self
12
- # stop
13
- # @param:
14
- # @return: StandardError class, will halt execution of program
15
- def stop reason
16
- raise StandardError, reason
17
- end
18
- end
19
- end
20
-
21
- class Util
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]
58
- def read_configuration(file)
59
- configuration = []
60
- line_number = 0
61
- text = File.open(file).read
62
- text.gsub!(/\r\n?/, '\n')
63
-
64
- text.each_line do |line|
65
- next if line.include?('Baboon.configure')
66
- next if line.include?('end')
67
- line.gsub!(/^(.*)\s=\s/, '')
68
- line.gsub!('\'', '')
69
- line.strip!
70
-
71
- configuration << { BABOON_CONFIGURATION_OPTIONS[line_number] => line }
72
- line_number += 1
73
- end
74
-
75
- return configuration.reduce({}, :merge)
76
- end
77
- end
78
- end
79
-
10
+ module Baboon
80
11
  class Cli < Thor
81
12
  # @logger: call an instance of the logger class, use throughout baboon
82
13
  # @configuration: holds the default baboon configuration set in config file
83
14
  # @configuration_file: the exact file location of baboon configuration
84
- attr_accessor :logger, :configuration, :configuration_file, :block
15
+ attr_accessor :configuration, :configuration_file, :stop
85
16
 
86
17
  # initialize
87
18
  # @param: Array
@@ -89,92 +20,93 @@ module Baboon
89
20
  def initialize(*args)
90
21
  super
91
22
  $stdout.sync ||= true
92
- @logger ||= Logger.new({level: 3, disable_formatters: false})
23
+
24
+ # Set our yaml engine
25
+ YAML::ENGINE.yamler = 'syck'
93
26
 
94
27
  # Attempt to locate the configuration file in the project if it was not set.
95
28
  @configuration_file = Util.locate_file
96
29
 
97
30
  # Return if file not found
98
31
  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"
32
+ printf "#{BABOON_TITLE}\n"
33
+ printf " \033[22;31mError:\033[22;37m no configuration file is present anywhere in the application or at config/baboon.yml\n"
101
34
  printf " \033[01;32mUsage:\033[22;37m rails g baboon:install\n"
102
- @block = true
35
+ @stop = true
103
36
  return
104
37
  end
105
38
 
106
- # Load the users baboon configuration
107
- if File.exists?(@configuration_file) # tad redundant
108
- @configuration = Util.read_configuration(@configuration_file)
109
-
110
- # configure the servers
111
- Baboon.configure do |config|
112
- config.application = @configuration[:application]
113
- config.repository = @configuration[:repository]
114
- config.deploy_path = @configuration[:deploy_path]
115
- config.deploy_user = @configuration[:deploy_user]
116
- config.branch = @configuration[:branch]
117
- config.rails_env = @configuration[:rails_env]
118
- config.servers = @configuration[:servers].gsub('[', '').gsub(']', '').split(',').collect(&:strip)
119
- end
120
- else
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
39
+ # Load the file now that we know its not nil
40
+ @configuration = YAML.load_file(@configuration_file)
41
+
42
+ # Double check that configuration is setup properly
43
+ if @configuration['baboon'].has_key?('environments')
44
+ @configuration['baboon']['environments'].map do |environment|
45
+ hash = Hash[*environment]
46
+ key = hash.keys.first
47
+
48
+ # Must have all defined keys filled out
49
+ unless BABOON_ENVIRONMENT_SETTINGS.collect { |k| hash[key].has_key?(k) }.all?
50
+ printf "#{BABOON_TITLE}\n"
51
+ printf " \033[22;31mError:\033[22;37m incorrect settings for the \"#{key}\" in config/baboon.yml\n"
52
+ printf " \033[01;32mUsage:\033[22;37m rails g baboon:install\n"
53
+ @stop = true
54
+ return
55
+ end
56
+ end
126
57
  end
127
58
  end
128
59
 
129
- desc "deploy", "Deploys the application to the configured servers."
130
- def deploy
131
- return if @block
132
- printf @logger.format("== Baboon starting deploy", "32", 1)
60
+ desc "deploy ENVIRONMENT", "Deploys the application to the configured servers."
61
+ def deploy environment
62
+ return if @stop
133
63
 
134
- # Loop through each server and do deploy, we will add threading later to do simultaneous deploys
135
- Baboon.configuration.servers.each do |server|
136
- current = server.to_s.strip
137
-
138
- printf @logger.format("== [#{current}]", "35", 1)
64
+ # Double checked the user typed the correct key
65
+ unless @configuration['baboon']['environments'].has_key?(environment)
66
+ printf "#{BABOON_TITLE}\n"
67
+ printf " \033[22;31mError:\033[22;37m looks like you typed an incorrect key for an environment you specified in your baboon.yml file\n"
68
+ printf " \033[01;32mUsage:\033[22;37m try one of these #{@configuration['baboon']['environments'].keys}\n"
69
+ @stop = true
70
+ return
71
+ end
72
+
73
+ # Get the current config for this environment
74
+ current_environment_configuration = @configuration['baboon']['environments'][environment]
75
+
76
+ # Loop through the servers
77
+ current_environment_configuration['servers'].each do |host|
78
+ printf "Deploying[#{host}]"
139
79
 
140
- # Essentially these are the instructions we need run for the Ubuntu 11.04 for rails
141
80
  # TODO: add lib of different instruction sets for Play framework, nodejs, etc
142
81
  instructions = [
143
- "cd '#{Baboon.configuration.deploy_path}' && git fetch",
144
- "cd '#{Baboon.configuration.deploy_path}' && git checkout #{Baboon.configuration.branch.to_s}",
145
- "cd '#{Baboon.configuration.deploy_path}' && git merge origin/#{Baboon.configuration.branch.to_s}",
146
- "cd '#{Baboon.configuration.deploy_path}' && bundle install --deployment",
147
- "cd '#{Baboon.configuration.deploy_path}' && touch tmp/restart.txt"
82
+ "cd '#{current_environment_configuration['deploy_path']}' && git fetch",
83
+ "cd '#{current_environment_configuration['deploy_path']}' && git checkout #{current_environment_configuration['branch']}",
84
+ "cd '#{current_environment_configuration['deploy_path']}' && git merge origin/#{current_environment_configuration['branch']}",
85
+ "cd '#{current_environment_configuration['deploy_path']}' && bundle install --deployment",
86
+ "cd '#{current_environment_configuration['deploy_path']}' && touch tmp/restart.txt"
148
87
  ]
149
-
88
+
150
89
  # Vars for connecting via ssh to the server
151
90
  credentials = {
152
- user: Baboon.configuration.deploy_user.to_s,
153
- host: current
91
+ user: current_environment_configuration['deploy_user'],
92
+ host: host
154
93
  }
155
-
94
+
95
+ # Start the connection and excute command
156
96
  Net::SSH.start(credentials[:host], credentials[:user]) do |session|
157
97
  instructions.each do |instruction|
158
- printf "[#{current}]: #{instruction}\n"
98
+ printf "[#{host}]: #{instruction}\n"
159
99
  session.exec instruction
160
100
  session.loop
161
101
  end
162
102
  end
163
- end # Looping servers
164
-
165
- printf @logger.format("== Baboon deploy Complete", "31", 1)
166
- end
103
+ end
104
+ end # def deploy
167
105
 
168
106
  desc "configuration", "Shows the current configuration for baboon."
169
107
  def configuration
170
- return if @block
171
- printf @logger.format("Baboon[Application]: #{Baboon.configuration.application}", "37", 1)
172
- printf @logger.format("Baboon[Repository]: #{Baboon.configuration.repository}", "37", 1)
173
- printf @logger.format("Baboon[Deploy_path]: #{Baboon.configuration.deploy_path}", "37", 1)
174
- printf @logger.format("Baboon[Deploy_user]: #{Baboon.configuration.deploy_user}", "37", 1)
175
- printf @logger.format("Baboon[Branch]: #{Baboon.configuration.branch}", "37", 1)
176
- printf @logger.format("Baboon[Rails_env]: #{Baboon.configuration.rails_env}", "37", 1)
177
- printf @logger.format("Baboon[Servers]: #{Baboon.configuration.servers}", "37", 1)
108
+ return if @stop
109
+ puts @configuration.inspect
178
110
  end
179
111
  end
180
112
  end
@@ -0,0 +1,10 @@
1
+ module Baboon
2
+ class Exception < StandardError
3
+ attr_reader :response
4
+
5
+ def initialize response
6
+ @response = response
7
+ super
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Baboon
2
+ module Instructions
3
+ class Rails
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ module Baboon
2
+ class Util
3
+ class << self
4
+ # file_check!
5
+ # @param: String file path
6
+ # @return: Boolean || String depending on if file is found
7
+ def file_check! file
8
+ return false if file.nil? || !file
9
+ end
10
+
11
+ # locate_file
12
+ # Will try and locate the baboon.rb file it it does not exist. Great method
13
+ # used especially for testing Baboon.
14
+ # @param:
15
+ # @return: String[file path, used to locate and initialize the configuration file]
16
+ def locate_file
17
+ config_file = ''
18
+ default_baboon_file_path = "config/baboon.yml"
19
+ if File.exists?(default_baboon_file_path)
20
+ config_file = default_baboon_file_path
21
+ else
22
+ Find.find('.') do |path|
23
+ if path.include?('baboon.yml')
24
+ config_file = path
25
+ break
26
+ end
27
+ end
28
+ end
29
+ config_file
30
+ end
31
+ end # class << self
32
+ end # class Util
33
+ end # module Baboon
@@ -1,3 +1,3 @@
1
1
  module Baboon
2
- VERSION = '1.0.8'
2
+ VERSION = '1.0.9'
3
3
  end
@@ -3,14 +3,11 @@ require 'rails/generators/base'
3
3
  module Baboon
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
- desc 'Creates an initializer for Baboon at config/initializers/baboon.rb'
7
-
8
- def self.source_root
9
- @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
10
- end
11
-
6
+ desc 'Creates an initializer for Baboon at config/baboon.yml'
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
12
9
  def create_initializer_file
13
- template "baboon.rb", "config/initializers/baboon.rb"
10
+ template 'baboon.yml', 'config/baboon.yml'
14
11
  end
15
12
  end
16
13
  end
@@ -0,0 +1,52 @@
1
+ baboon:
2
+ # Give you application a descriptive name, has no effect on the actual
3
+ # running path or location of your application. Can be different then
4
+ # what is stored in your scm.
5
+ application: 'Vacuum HQ'
6
+
7
+ # For now, Baboon will determine what scm the remote code is stored in
8
+ # based on the scm path. For now, GIT and SVN are the two supported
9
+ # scm applications that are supported.
10
+ repository: 'git@github.com:amanelis/vacuum.git'
11
+
12
+ # Pass multiple environments in this section. When running a standard
13
+ # 'baboon deploy' all defined hosts here will be deployed to. You can
14
+ # specify which host you want to deploy to by typing that as a param
15
+ # in the command 'baboon deploy development'.
16
+ environments:
17
+ # Name each environment to your own standard. Baboon, will use the
18
+ # settings defined after the env to to the deploy.
19
+ staging:
20
+ # Branch that the baboon will merge code in from the remote scm
21
+ # baboon['repository'] url that is defined in this file.
22
+ branch: 'staging'
23
+
24
+ # This is the actual path on the server where the root of the
25
+ # application is stored, not where /public is in terms of a rails
26
+ # setup.
27
+ deploy_path: '/home/rails/vacuum'
28
+
29
+ # This is the actual user that baboon will use for SSH authentication
30
+ # into the servers that are defined here.
31
+ deploy_user: 'rails'
32
+
33
+ # Env that we will run all rake/bundler commands with.
34
+ rails_env: 'staging'
35
+
36
+ # These are the host machines that baboon will ssh into on each deploy.
37
+ # They can be defined as an ip address or a host name
38
+ servers:
39
+ - '127.0.0.1'
40
+ - '127.0.0.2'
41
+
42
+ # You can define as many different environments as needed to your application
43
+ production:
44
+ branch: 'production'
45
+ deploy_path: '/home/rails/vacuum'
46
+ deploy_user: 'rails'
47
+ rails_env: 'production'
48
+ servers:
49
+ - '10.0.0.1'
50
+ - '10.0.0.2'
51
+ - '10.0.0.3'
52
+ - 'production.node1.east.com'
data/spec/spec_helper.rb CHANGED
@@ -11,8 +11,6 @@ Dir["spec/support/**/*.rb"].each { |f| require f }
11
11
  PROJECT_ROOT = File.expand_path('../..', __FILE__)
12
12
  $LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
13
13
 
14
- $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
15
-
16
14
  RSpec.configure do |config|
17
15
  config.color_enabled = true
18
16
  config.tty = true
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.8
4
+ version: 1.0.9
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-11 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -248,14 +248,17 @@ files:
248
248
  - lib/baboon/cli/options.rb
249
249
  - lib/baboon/cli.rb
250
250
  - lib/baboon/configuration.rb
251
+ - lib/baboon/exception.rb
252
+ - lib/baboon/instructions/rails.rb
251
253
  - lib/baboon/logger.rb
254
+ - lib/baboon/util.rb
252
255
  - lib/baboon/version.rb
253
256
  - lib/baboon.rb
254
257
  - lib/core_ext/string.rb
255
258
  - lib/generators/baboon/config/config_generator.rb
256
259
  - lib/generators/baboon/config/templates/baboon.yml
257
260
  - lib/generators/baboon/install/install_generator.rb
258
- - lib/generators/baboon/install/templates/baboon.rb
261
+ - lib/generators/baboon/install/templates/baboon.yml
259
262
  - spec/lib/baboon/cli_spec.rb
260
263
  - spec/lib/baboon/configuration_spec.rb
261
264
  - spec/lib/baboon_spec.rb
@@ -277,7 +280,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
277
280
  version: '0'
278
281
  segments:
279
282
  - 0
280
- hash: -4459336840231193725
283
+ hash: 1179810549053676199
281
284
  required_rubygems_version: !ruby/object:Gem::Requirement
282
285
  none: false
283
286
  requirements:
@@ -286,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
289
  version: '0'
287
290
  segments:
288
291
  - 0
289
- hash: -4459336840231193725
292
+ hash: 1179810549053676199
290
293
  requirements: []
291
294
  rubyforge_project: baboon
292
295
  rubygems_version: 1.8.24
@@ -1,9 +0,0 @@
1
- Baboon.configure do |config|
2
- config.application = 'NAME OF YOUR APPLICATION'
3
- config.repository = 'git@github.com:{some-project}.git'
4
- config.deploy_path = '{path_to_application_on_server}'
5
- config.deploy_user = 'rails'
6
- config.branch = 'master'
7
- config.rails_env = 'production'
8
- config.servers = ['server_1', 'server_2']
9
- end