baboon 1.0.9 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +19 -0
- data/.rspec +4 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +24 -0
- data/LICENSE +22 -0
- data/README.md +113 -33
- data/Rakefile +2 -2
- data/baboon.gemspec +25 -0
- data/lib/baboon.rb +4 -4
- data/lib/baboon/cli.rb +155 -51
- data/lib/baboon/instructions/rails.rb +4 -2
- data/lib/baboon/util.rb +21 -15
- data/lib/baboon/version.rb +2 -2
- data/lib/generators/baboon/install/templates/baboon.yml +36 -17
- data/media/baboon.psd +0 -0
- data/spec/baboon.yml +30 -0
- data/spec/lib/baboon/cli_spec.rb +37 -28
- data/spec/lib/baboon/util_spec.rb +19 -0
- data/spec/lib/baboon_spec.rb +11 -3
- data/spec/spec_helper.rb +40 -3
- metadata +36 -220
- data/lib/baboon/cli/options.rb +0 -241
- data/lib/baboon/configuration.rb +0 -38
- data/lib/baboon/logger.rb +0 -153
- data/lib/generators/baboon/config/config_generator.rb +0 -17
- data/lib/generators/baboon/config/templates/baboon.yml +0 -11
- data/spec/lib/baboon/configuration_spec.rb +0 -115
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3303b225f210852b4ea5f95e4d981c9a9a33e148
|
4
|
+
data.tar.gz: e71c11a4101e4e1ad5de22f2605f0ab45a9e3c68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca0a49f09866a6429fb498022e1f0a4c7c7d398a8e786ea5874ad695a6fba9502896c68df55dec75594e687c7a881e33261643272df9382babe42313733e79c9
|
7
|
+
data.tar.gz: 9c772ded6c4db6f1e70a384b45754c79080a9a193451a6bf9d349d8d4958945e4335d69c483882e2f5e21b48145d1e56e36bd69350b94cb43d3bdeb7ff8e2c76
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: 3zOeqgeUoXhK90RsGclfu8NYgrC68fIjb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
baboon
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'pry'
|
6
|
+
gem 'thor', '0.19.1'
|
7
|
+
gem 'net-ssh', '~> 2.6'
|
8
|
+
gem 'net-ssh-session', '0.1.6'
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem 'rake'
|
12
|
+
gem 'rails'
|
13
|
+
gem 'rspec'
|
14
|
+
gem 'rspec-core'
|
15
|
+
gem 'rspec-mocks'
|
16
|
+
gem 'rspec-rails'
|
17
|
+
gem 'rspec-expectations'
|
18
|
+
gem 'shoulda-matchers'
|
19
|
+
gem 'simplecov'
|
20
|
+
gem 'webmock'
|
21
|
+
gem 'capybara'
|
22
|
+
gem 'faker'
|
23
|
+
gem 'coveralls'
|
24
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Alex Manelis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
# Baboon
|
2
|
-
![cardinal](https://alexweb.s3.amazonaws.com/baboon.
|
3
|
-
|
4
|
-
[![Build Status](https://secure.travis-ci.org/amanelis/baboon.png)](http://travis-ci.org/amanelis/baboon)
|
5
|
-
[![Dependency Status](https://gemnasium.com/amanelis/baboon.png)](https://gemnasium.com/amanelis/baboon)
|
1
|
+
# Baboon - simple rails deployment.
|
2
|
+
![cardinal](https://alexweb.s3.amazonaws.com/baboon.png)
|
6
3
|
|
7
4
|
A simple and light weight deployment library for a ruby on rails application 3.0+. No symlinks, no releases, just git and your application.
|
8
5
|
|
6
|
+
<!--[![Build Status](https://secure.travis-ci.org/amanelis/baboon.png)](http://travis-ci.org/amanelis/baboon)-->
|
7
|
+
<!--[![Dependency Status](https://gemnasium.com/amanelis/baboon.svg)](https://gemnasium.com/amanelis/baboon)-->
|
8
|
+
<!--[![Code Climate](https://codeclimate.com/github/amanelis/baboon.png)](https://codeclimate.com/github/amanelis/baboon)-->
|
9
|
+
<!--[![Coverage Status](https://coveralls.io/repos/amanelis/baboon/badge.png?branch=master)](https://coveralls.io/r/amanelis/baboon)-->
|
10
|
+
|
9
11
|
|
10
12
|
# How it works
|
11
13
|
Baboon is simple. You provide your server addresses, environments, path, repository, username and Baboon does the rest. By running a simple `baboon deploy {env}` it will do all neccessary operations you intend for it to do on a full deploy to a production staging or development server. All you need is a working rails application on a server with a git repository.
|
@@ -21,25 +23,97 @@ This must be installed under a current rails application. We recommend vendoring
|
|
21
23
|
|
22
24
|
In your Gemfile, then `bundle install`.
|
23
25
|
|
24
|
-
|
26
|
+
```rb
|
27
|
+
gem 'baboon'
|
28
|
+
```
|
25
29
|
|
26
30
|
Now that the gem is installed, run the config generator
|
27
31
|
|
28
32
|
$ rails g baboon:install
|
29
33
|
|
30
|
-
This will build a file into your application under `config/
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
This will build a file into your application under `config/baboon.yml`. Open this file and start editing. Here is an example of the main configuration options:
|
35
|
+
```yaml
|
36
|
+
baboon:
|
37
|
+
# Give you application a descriptive name, has no effect on the actual
|
38
|
+
# running path or location of your application. Can be different then
|
39
|
+
# what is stored in your scm.
|
40
|
+
application: 'Vacuum HQ'
|
41
|
+
|
42
|
+
# For now, Baboon will determine what scm the remote code is stored
|
43
|
+
# in based on the scm path.
|
44
|
+
repository: 'git@github.com:amanelis/vacuum.git'
|
45
|
+
|
46
|
+
# Pass multiple environments in this section. Each environment you
|
47
|
+
# specify then becomes part of the deploy command: baboon deploy
|
48
|
+
# {environment}. Below, we have defined two envs of staging and
|
49
|
+
# production. Add more as needed.
|
50
|
+
environments:
|
51
|
+
# Name each environment to your own standard. Baboon, will use the
|
52
|
+
# settings defined after the env to to the deploy. This environment
|
53
|
+
# is named 'staging' -> baboon deploy staging
|
54
|
+
staging:
|
55
|
+
# This is the branch from your scm that Baboon will pull and merge
|
56
|
+
# code from. The repository is defined in the root node of this
|
57
|
+
# configuration file.
|
58
|
+
branch: 'staging'
|
59
|
+
|
60
|
+
# Callbacks, pre and post deploy. Specify any command you want
|
61
|
+
# executed pre and post in blocks below as array elements.
|
62
|
+
callbacks:
|
63
|
+
# These will be run before the code fetch and server restart.
|
64
|
+
before_deploy:
|
65
|
+
- '/etc/init.d/my_service stop'
|
66
|
+
- 'ruby clean_and_free_memory.rb'
|
67
|
+
|
68
|
+
# These will be run after the code fetch and server restart.
|
69
|
+
after_deploy:
|
70
|
+
- '/etc/init.d/my_service start'
|
71
|
+
- 'ruby warm_cache.rb'
|
72
|
+
|
73
|
+
# This is the path on the server where the root of the
|
74
|
+
# application is stored, not where /public is in terms of a rails
|
75
|
+
# setup.
|
76
|
+
deploy_path: '/home/rails/vacuum'
|
77
|
+
|
78
|
+
# This is the user that baboon will use for SSH authentication
|
79
|
+
# into the servers that are defined here.
|
80
|
+
deploy_user: 'rails'
|
81
|
+
|
82
|
+
# Rails environment that Baboon will run all rake/bundler commands
|
83
|
+
# with.
|
84
|
+
rails_env: 'staging'
|
85
|
+
|
86
|
+
# Custom server restart_command. If your server happens to not respond
|
87
|
+
# `touch tmp/restart.txt` - specify your restart command. Otherwise
|
88
|
+
# default Baboon will try and touch the restart.txt file.
|
89
|
+
restart_command: '/etc/init.d/appache2 restart'
|
90
|
+
|
91
|
+
# These are the host machines that baboon will ssh into on each
|
92
|
+
# deploy. They can be defined as an ip address or a host name
|
93
|
+
servers:
|
94
|
+
- '127.0.0.1'
|
95
|
+
- '127.0.0.2'
|
96
|
+
|
97
|
+
# You can define as many different environments as needed.
|
98
|
+
production:
|
99
|
+
branch: 'master'
|
100
|
+
callbacks:
|
101
|
+
before_deploy:
|
102
|
+
- '/etc/init.d/my_service stop'
|
103
|
+
after_deploy:
|
104
|
+
- '/etc/init.d/my_service start'
|
105
|
+
deploy_path: '/home/rails/vacuum'
|
106
|
+
deploy_user: 'rails'
|
107
|
+
rails_env: 'production'
|
108
|
+
restart_command: '/etc/init.d/apache2 restart'
|
109
|
+
servers:
|
110
|
+
- '10.0.0.1'
|
111
|
+
- '10.0.0.2'
|
112
|
+
- '10.0.0.3'
|
113
|
+
- 'production.node1.east.com'
|
114
|
+
```
|
41
115
|
|
42
|
-
These must be properly filled out so baboon can properly make deploys.
|
116
|
+
These must be properly filled out so baboon can properly make deploys. One single environment always has a `branch` that baboon will know where to pull the deployable code from. It will assume the `repository` from the root node. For the environment, baboon will need to know what user to login as via the `deploy_user` and where to cd to via the `deploy_path`. Once it knows the location of the app, baboon will need to know what env to run as, hence the `rails_env` setting. The last option is the `servers` collection. Fill as many servers as you would like and baboon will deploy to all for the given env. Asynchronous is the next option we would like to add.
|
43
117
|
|
44
118
|
---
|
45
119
|
# Commands
|
@@ -47,31 +121,31 @@ Once everything is setup you can run `baboon` to see available commands. Start b
|
|
47
121
|
|
48
122
|
$ baboon configuration
|
49
123
|
|
50
|
-
|
124
|
+
For now, lets assume you have everything in your config correct and you are deploying to production, run the following command to do a deploy:
|
125
|
+
|
126
|
+
$ baboon deploy production
|
127
|
+
|
128
|
+
Any other deploy to a different env that you specify in your config file can be done as follows:
|
51
129
|
|
52
|
-
$ baboon deploy
|
130
|
+
$ baboon deploy {environment}
|
53
131
|
|
54
132
|
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:
|
55
133
|
|
56
|
-
$ baboon servers
|
134
|
+
$ baboon servers production
|
57
135
|
|
58
136
|
Thats it? Yeah, thats it! You should see your bundle installing and Baboon running all tasks. Custom tasks coming soon.
|
59
137
|
|
60
138
|
The next commands that will be realeased with future versions of baboon are:
|
61
139
|
|
62
|
-
baboon setup # no manually editing of configuration file
|
63
|
-
baboon check # checks the server and config file for proper configuration
|
64
|
-
baboon migrate # runs pending migrations
|
65
|
-
baboon restart # restarts your server
|
66
|
-
baboon rollback # rolls back your to your previous commit, info in ./log/baboon.log
|
67
|
-
baboon rake # run custom rake tasks on server
|
68
|
-
baboon execute # run a single command on the server
|
69
|
-
baboon shell # open a remote shell with the config user
|
70
140
|
|
71
|
-
|
72
|
-
#
|
73
|
-
|
74
|
-
|
141
|
+
baboon setup # no manually editing of configuration file
|
142
|
+
baboon check # checks the server and config file for proper configuration
|
143
|
+
baboon migrate # runs pending migrations
|
144
|
+
baboon restart # restarts your server
|
145
|
+
baboon rollback # rolls back your to your previous commit, info in ./log/baboon.log
|
146
|
+
baboon rake # run custom rake tasks on server
|
147
|
+
baboon execute # run a single command on the server
|
148
|
+
baboon shell # open a remote shell with the config user
|
75
149
|
|
76
150
|
|
77
151
|
---
|
@@ -95,6 +169,12 @@ Multiple server deployments now work.
|
|
95
169
|
#### 1.0.6
|
96
170
|
Changed the order of bundle installing on Rails package. Wrote tests for CLI.
|
97
171
|
|
172
|
+
#### 1.0.9
|
173
|
+
Removed ruby configuration and added configuration by `config/baboon.yml`. More environments.
|
174
|
+
|
175
|
+
## Thanks
|
176
|
+
I'd like to thank Enrique Ruiz Davila for making the beautiful [Baboon](http://www.behance.net/davila) image.
|
177
|
+
|
98
178
|
## How to contribute
|
99
179
|
|
100
180
|
* Fork the project.
|
data/Rakefile
CHANGED
data/baboon.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'baboon/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'baboon'
|
7
|
+
s.version = Baboon::VERSION.dup
|
8
|
+
s.executables = %w[ baboon ]
|
9
|
+
s.license = 'MIT'
|
10
|
+
s.homepage = 'https://github.com/amanelis/baboon'
|
11
|
+
|
12
|
+
s.authors = ['Alex Manelis']
|
13
|
+
s.email = ['amanelis@gmail.com']
|
14
|
+
s.description = %q{A lite deployment package for rails applications.}
|
15
|
+
s.summary = %q{Add a configuration file, setup and deploy.}
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.required_ruby_version = '>= 2.1.0'
|
21
|
+
|
22
|
+
s.add_dependency 'thor', '~> 0.19.1'
|
23
|
+
s.add_dependency 'net-ssh', '~> 2.6'
|
24
|
+
s.add_dependency 'net-ssh-session', '~> 0.1.6'
|
25
|
+
end
|
data/lib/baboon.rb
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
|
8
8
|
# Nicely formatted output of the Baboon title
|
9
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',
|
10
|
+
BABOON_ENVIRONMENT_SETTINGS = ['branch', 'deploy_path', 'deploy_user',
|
11
|
+
'rails_env', 'restart_command', 'servers']
|
11
12
|
|
12
|
-
require 'baboon/configuration'
|
13
13
|
require 'baboon/cli'
|
14
|
-
require 'baboon/
|
15
|
-
require '
|
14
|
+
require 'baboon/version'
|
15
|
+
require 'yaml'
|
data/lib/baboon/cli.rb
CHANGED
@@ -1,112 +1,216 @@
|
|
1
1
|
require 'baboon'
|
2
|
-
require 'baboon/configuration'
|
3
2
|
require 'baboon/util'
|
4
3
|
|
5
|
-
require 'find'
|
6
4
|
require 'net/ssh'
|
5
|
+
require 'net/ssh/session'
|
6
|
+
require 'find'
|
7
7
|
require 'thor'
|
8
8
|
require 'yaml'
|
9
9
|
|
10
|
-
module Baboon
|
10
|
+
module Baboon
|
11
|
+
class InvalidConfigurationError < StandardError
|
12
|
+
end
|
13
|
+
|
11
14
|
class Cli < Thor
|
12
|
-
#
|
15
|
+
# Name the package output
|
16
|
+
package_name "Baboon"
|
17
|
+
|
13
18
|
# @configuration: holds the default baboon configuration set in config file
|
14
19
|
# @configuration_file: the exact file location of baboon configuration
|
15
|
-
attr_accessor :configuration, :configuration_file, :stop
|
20
|
+
attr_accessor :configuration, :configuration_file, :errors, :stop
|
16
21
|
|
17
22
|
# initialize
|
18
23
|
# @param: Array
|
19
|
-
# @
|
20
|
-
def initialize
|
24
|
+
# @return: instance
|
25
|
+
def initialize *args
|
21
26
|
super
|
27
|
+
|
28
|
+
# Sync stdout for when communicating over ssh channel
|
22
29
|
$stdout.sync ||= true
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
30
|
+
|
31
|
+
# Store any errors here during the process so they can be printed to STDOUT
|
32
|
+
@errors = []
|
33
|
+
|
27
34
|
# Attempt to locate the configuration file in the project if it was not set.
|
28
|
-
@configuration_file = Util.
|
29
|
-
|
35
|
+
@configuration_file = Util.locate_baboon_configuration_file
|
36
|
+
|
30
37
|
# Return if file not found
|
31
|
-
if @configuration_file.nil?
|
38
|
+
if @configuration_file.nil?
|
32
39
|
printf "#{BABOON_TITLE}\n"
|
33
40
|
printf " \033[22;31mError:\033[22;37m no configuration file is present anywhere in the application or at config/baboon.yml\n"
|
34
41
|
printf " \033[01;32mUsage:\033[22;37m rails g baboon:install\n"
|
35
|
-
|
42
|
+
errors << "#initialize: failed to load a valid configuration file, please be sure a proper one is created at config/baboon.yml"
|
43
|
+
@stop = true
|
36
44
|
return
|
37
45
|
end
|
38
|
-
|
46
|
+
|
39
47
|
# Load the file now that we know its not nil
|
40
48
|
@configuration = YAML.load_file(@configuration_file)
|
41
|
-
|
49
|
+
|
42
50
|
# Double check that configuration is setup properly
|
43
51
|
if @configuration['baboon'].has_key?('environments')
|
44
52
|
@configuration['baboon']['environments'].map do |environment|
|
45
53
|
hash = Hash[*environment]
|
46
54
|
key = hash.keys.first
|
47
|
-
|
55
|
+
|
48
56
|
# Must have all defined keys filled out
|
49
57
|
unless BABOON_ENVIRONMENT_SETTINGS.collect { |k| hash[key].has_key?(k) }.all?
|
50
58
|
printf "#{BABOON_TITLE}\n"
|
51
59
|
printf " \033[22;31mError:\033[22;37m incorrect settings for the \"#{key}\" in config/baboon.yml\n"
|
52
60
|
printf " \033[01;32mUsage:\033[22;37m rails g baboon:install\n"
|
61
|
+
errors << "#initialize: incorrect key:val [#{key}:#{k}] pair in config/baboon.yml"
|
53
62
|
@stop = true
|
54
63
|
return
|
55
64
|
end
|
56
65
|
end
|
57
66
|
end
|
58
67
|
end
|
59
|
-
|
60
|
-
desc "deploy ENVIRONMENT", "Deploys the application to the configured servers."
|
68
|
+
|
69
|
+
desc "deploy [ENVIRONMENT]", "Deploys the application to the configured servers via ssh."
|
61
70
|
def deploy environment
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
71
|
+
check_configuration(environment)
|
72
|
+
|
73
|
+
raise InvalidConfigurationError.new("Your configuration is invalid, please check if you have misssss spelled something.") if @stop
|
74
|
+
|
73
75
|
# Get the current config for this environment
|
74
76
|
current_environment_configuration = @configuration['baboon']['environments'][environment]
|
75
|
-
|
77
|
+
|
76
78
|
# Loop through the servers
|
77
79
|
current_environment_configuration['servers'].each do |host|
|
78
|
-
printf "Deploying[#{host}]"
|
79
|
-
|
80
|
+
printf "Deploying[#{host}]\n"
|
81
|
+
|
80
82
|
# TODO: add lib of different instruction sets for Play framework, nodejs, etc
|
81
83
|
instructions = [
|
82
84
|
"cd '#{current_environment_configuration['deploy_path']}' && git fetch",
|
83
85
|
"cd '#{current_environment_configuration['deploy_path']}' && git checkout #{current_environment_configuration['branch']}",
|
84
86
|
"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']}' &&
|
87
|
+
"cd '#{current_environment_configuration['deploy_path']}' && RAILS_ENV=#{current_environment_configuration['rails_env']} bundle install --deployment --without development test",
|
88
|
+
"cd '#{current_environment_configuration['deploy_path']}' && RAILS_ENV=#{current_environment_configuration['rails_env']} bundle exec rake assets:precompile",
|
89
|
+
"cd '#{current_environment_configuration['deploy_path']}' && RAILS_ENV=#{current_environment_configuration['rails_env']} bundle exec rake db:migrate"
|
87
90
|
]
|
88
|
-
|
91
|
+
|
92
|
+
if current_environment_configuration.has_key?('restart_command') && !current_environment_configuration['restart_command'].nil?
|
93
|
+
instructions << current_environment_configuration['restart_command']
|
94
|
+
else
|
95
|
+
instructions << "cd '#{current_environment_configuration['deploy_path']}' && touch tmp/restart.txt"
|
96
|
+
end
|
97
|
+
|
89
98
|
# Vars for connecting via ssh to the server
|
90
|
-
credentials = {
|
91
|
-
user: current_environment_configuration['deploy_user'],
|
99
|
+
credentials = {
|
100
|
+
user: current_environment_configuration['deploy_user'],
|
92
101
|
host: host
|
93
102
|
}
|
94
|
-
|
95
|
-
#
|
96
|
-
Net::SSH.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
103
|
+
|
104
|
+
# Initialize the SSH class
|
105
|
+
session = Net::SSH::Session.new(credentials[:host], credentials[:user], nil)
|
106
|
+
|
107
|
+
# Open the session
|
108
|
+
session.open
|
109
|
+
|
110
|
+
# Set the rails_env session if var is present
|
111
|
+
session.export_hash(
|
112
|
+
'RAILS_ENV' => current_environment_configuration['rails_env'],
|
113
|
+
'RACK_ENV' => current_environment_configuration['rails_env']
|
114
|
+
)
|
115
|
+
|
116
|
+
# Check if user has added the callbacks block
|
117
|
+
can_run_callbacks = current_environment_configuration.has_key?('callbacks')
|
118
|
+
|
119
|
+
# Run pre instructions
|
120
|
+
if can_run_callbacks
|
121
|
+
pre_callbacks = current_environment_configuration['callbacks']['before_deploy']
|
122
|
+
|
123
|
+
if !pre_callbacks.nil? && pre_callbacks.is_a?(Array) && pre_callbacks.count >= 1
|
124
|
+
printf "[\033[36m#{host}\033[0m]: Running pre callbacks...\n"
|
125
|
+
run_commands(host, session, pre_callbacks)
|
101
126
|
end
|
102
127
|
end
|
103
|
-
|
104
|
-
|
128
|
+
|
129
|
+
# Execute commands
|
130
|
+
run_commands(host, session, instructions)
|
131
|
+
|
132
|
+
# Run post instructions
|
133
|
+
if can_run_callbacks
|
134
|
+
post_callbacks = current_environment_configuration['callbacks']['after_deploy']
|
135
|
+
|
136
|
+
if !post_callbacks.nil? && post_callbacks.is_a?(Array) && post_callbacks.count >= 1
|
137
|
+
printf "[\033[36m#{host}\033[0m]: Running post callbacks...\n"
|
138
|
+
run_commands(host, session, post_callbacks)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Close and exit the session
|
143
|
+
begin
|
144
|
+
session.exit
|
145
|
+
rescue => e
|
146
|
+
# Here well want to write to stdout if --debug flag was passed
|
147
|
+
end
|
148
|
+
|
149
|
+
printf "[\033[36m#{host}\033[0m]: \033[32mComplete!\033[0m\n"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
desc "fetc", "Fetches a given file from your project's directory"
|
154
|
+
def fetch environment, file
|
155
|
+
current_configuration = @configuration['baboon']['environments'][environment]
|
156
|
+
|
157
|
+
raise InvalidHostError.new("No host found in your configuration, please add one") if current_configuration['servers'].first.nil?
|
158
|
+
|
159
|
+
host = current_configuration['servers'].first
|
160
|
+
|
161
|
+
# Initialize the SSH class
|
162
|
+
session = Net::SSH::Session.new(current_configuration['servers'].first, current_configuration['deploy_user'], nil)
|
163
|
+
session.open
|
164
|
+
|
165
|
+
file_path = file.gsub(/^\//, '')
|
166
|
+
printf "[\033[36m#{host}\033[0m]: Fetching file '#{file_path}'\n"
|
167
|
+
fetch_result = session.run("/bin/cat #{current_configuration['deploy_path']}/#{file_path}")
|
168
|
+
session.exit
|
169
|
+
|
170
|
+
printf "[\033[36m#{host}\033[0m]: Results below.\n"
|
171
|
+
printf fetch_result.output + "\n"
|
172
|
+
printf "[\033[36m#{host}\033[0m]: Complete.\n"
|
173
|
+
end
|
174
|
+
|
175
|
+
desc "ref", "Current git ref HEAD of the running code"
|
176
|
+
def ref
|
177
|
+
current_configuration = @configuration['baboon']['environments'][environment]
|
178
|
+
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
desc "rollback", "Rollsback the application to a given state via ssh."
|
183
|
+
def rollback environment
|
184
|
+
puts "This functionality has not been implemented yet, coming soon, I promise :)"
|
185
|
+
end
|
105
186
|
|
106
187
|
desc "configuration", "Shows the current configuration for baboon."
|
107
|
-
def configuration
|
188
|
+
def configuration
|
108
189
|
return if @stop
|
109
|
-
puts @configuration
|
190
|
+
puts @configuration['baboon']['application']
|
191
|
+
end
|
192
|
+
|
193
|
+
desc "version", "Shows the version of Baboon."
|
194
|
+
def version
|
195
|
+
puts Baboon::VERSION
|
196
|
+
end
|
197
|
+
|
198
|
+
private
|
199
|
+
|
200
|
+
def check_configuration(environment)
|
201
|
+
if !@configuration['baboon']['environments'].has_key?(environment)
|
202
|
+
printf "#{BABOON_TITLE}\n"
|
203
|
+
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"
|
204
|
+
printf " \033[01;32mUsage:\033[22;37m try one of these #{@configuration['baboon']['environments'].keys}\n"
|
205
|
+
errors << "#deploy: missing {environment} key inside of config/baboon.yml - you need at least 1 environment to deploy."
|
206
|
+
@stop = true
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def run_commands(host, session, instructions)
|
211
|
+
session.run_multiple(instructions) do |cmd|
|
212
|
+
printf "[\033[36m#{host}\033[0m]: #{cmd}\n"
|
213
|
+
end
|
110
214
|
end
|
111
215
|
end
|
112
|
-
end
|
216
|
+
end
|