ors 0.2.10 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +71 -0
- data/bin/ors +1 -1
- data/lib/ors.rb +21 -2
- data/lib/ors/base.rb +30 -0
- data/lib/ors/commands/base.rb +56 -12
- data/lib/ors/commands/changes.rb +21 -7
- data/lib/ors/commands/console.rb +16 -18
- data/lib/ors/commands/deploy.rb +24 -13
- data/lib/ors/commands/env.rb +9 -9
- data/lib/ors/commands/exec.rb +14 -7
- data/lib/ors/commands/help.rb +9 -11
- data/lib/ors/commands/logs.rb +16 -14
- data/lib/ors/commands/migrate.rb +8 -9
- data/lib/ors/commands/restart.rb +9 -11
- data/lib/ors/commands/ruby.rb +8 -6
- data/lib/ors/commands/runner.rb +29 -25
- data/lib/ors/commands/setup.rb +16 -16
- data/lib/ors/commands/start.rb +9 -11
- data/lib/ors/commands/stop.rb +9 -11
- data/lib/ors/commands/symlink.rb +31 -0
- data/lib/ors/commands/timestamps.rb +27 -0
- data/lib/ors/commands/update.rb +15 -11
- data/lib/ors/config.rb +88 -58
- data/lib/ors/helpers.rb +107 -76
- data/lib/ors/log_unifier.rb +2 -2
- data/lib/ors/version.rb +2 -2
- data/spec/ors/{command_spec.rb → base_spec.rb} +11 -8
- data/spec/ors/commands/base_spec.rb +17 -9
- data/spec/ors/commands/deploy_spec.rb +4 -3
- data/spec/ors/commands/runner_spec.rb +8 -27
- data/spec/ors/commands/timestamps_spec.rb +16 -0
- data/spec/ors/commands/update_spec.rb +8 -3
- data/spec/ors/config_spec.rb +56 -61
- data/spec/ors/helpers_spec.rb +6 -2
- data/spec/ors/log_unifier_spec.rb +2 -2
- metadata +82 -57
- data/README +0 -52
- data/lib/ors/command.rb +0 -46
- data/lib/ors/commands/check.rb +0 -27
- data/lib/ors/commands/sync.rb +0 -27
- data/lib/ors/core_ext.rb +0 -53
- data/spec/ors/commands/check_spec.rb +0 -15
data/README.markdown
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Set Up
|
2
|
+
|
3
|
+
Required Files:
|
4
|
+
|
5
|
+
* .rvmrc
|
6
|
+
* Gemfile
|
7
|
+
* Gemfile.lock
|
8
|
+
* config/database.yml
|
9
|
+
* .git/config
|
10
|
+
* config/unicorn.rb
|
11
|
+
|
12
|
+
|
13
|
+
### Setting up .git/config
|
14
|
+
|
15
|
+
|
16
|
+
Your .git/config should know about the remotes you will be using to deploy to the server (usually just origin) as it will pull information about the remote from your local config file
|
17
|
+
|
18
|
+
|
19
|
+
### Setting up RVM
|
20
|
+
|
21
|
+
On your ruby servers you should create a .rvmrc in the home directory of the user running unicorn.
|
22
|
+
|
23
|
+
```bash
|
24
|
+
rvm_install_on_use_flag=1
|
25
|
+
|
26
|
+
rvm_gemset_create_on_use_flag=1
|
27
|
+
|
28
|
+
rvm_trust_rvmrcs_flag=1
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
### Required gems
|
33
|
+
|
34
|
+
* rake
|
35
|
+
* bundler
|
36
|
+
* unicorn
|
37
|
+
|
38
|
+
ors deploy commands assume you are using unicorn for your servers.
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
# Usage
|
43
|
+
|
44
|
+
run `ors help` for a list of commands to use.
|
45
|
+
|
46
|
+
|
47
|
+
### Brief Examples
|
48
|
+
|
49
|
+
Deploying to the staging website
|
50
|
+
|
51
|
+
```bash
|
52
|
+
bundle exec ors deploy to staging
|
53
|
+
```
|
54
|
+
|
55
|
+
Deploying a feature branch to the production website
|
56
|
+
|
57
|
+
```bash
|
58
|
+
bundle exec ors deploy origin/feature_branch
|
59
|
+
```
|
60
|
+
|
61
|
+
Deploying a feature branch to the staging website
|
62
|
+
|
63
|
+
```bash
|
64
|
+
bundle exec ors deploy origin/feature_branch to staging
|
65
|
+
```
|
66
|
+
|
67
|
+
### Notes
|
68
|
+
* By default the environment is assumed to be production and the branch you are deploying is assumed to be origin/#{environment}.
|
69
|
+
* You can override settings by implementing a config/deploy.yml file in your repo.
|
70
|
+
|
71
|
+
|
data/bin/ors
CHANGED
data/lib/ors.rb
CHANGED
@@ -3,9 +3,28 @@ require "git"
|
|
3
3
|
require "yaml"
|
4
4
|
require "erb"
|
5
5
|
|
6
|
+
require "ors/base"
|
6
7
|
require "ors/version"
|
7
|
-
require "ors/core_ext"
|
8
8
|
require "ors/log_unifier"
|
9
9
|
require "ors/config"
|
10
10
|
require "ors/helpers"
|
11
|
-
|
11
|
+
|
12
|
+
# commands
|
13
|
+
require "ors/commands/base"
|
14
|
+
require "ors/commands/changes"
|
15
|
+
require "ors/commands/console"
|
16
|
+
require "ors/commands/deploy"
|
17
|
+
require "ors/commands/env"
|
18
|
+
require "ors/commands/exec"
|
19
|
+
require "ors/commands/help"
|
20
|
+
require "ors/commands/logs"
|
21
|
+
require "ors/commands/migrate"
|
22
|
+
require "ors/commands/restart"
|
23
|
+
require "ors/commands/ruby"
|
24
|
+
require "ors/commands/runner"
|
25
|
+
require "ors/commands/setup"
|
26
|
+
require "ors/commands/start"
|
27
|
+
require "ors/commands/stop"
|
28
|
+
require "ors/commands/symlink"
|
29
|
+
require "ors/commands/timestamps"
|
30
|
+
require "ors/commands/update"
|
data/lib/ors/base.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
class ORS
|
2
|
+
def self.config(options = [])
|
3
|
+
@config ||= ORS::Config.new(options)
|
4
|
+
end
|
5
|
+
|
6
|
+
def run args
|
7
|
+
command, *options = args
|
8
|
+
klass_string = command.to_s.capitalize
|
9
|
+
|
10
|
+
# setup initial config
|
11
|
+
ORS.config(options)
|
12
|
+
|
13
|
+
# determine command to use
|
14
|
+
if command =~ /-*version/i
|
15
|
+
puts "ORS v#{ORS::VERSION}"
|
16
|
+
else
|
17
|
+
if available_commands.include? klass_string
|
18
|
+
ORS::Commands.const_get(klass_string).run
|
19
|
+
else
|
20
|
+
ORS::Commands::Help.run
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def available_commands
|
28
|
+
ORS::Commands.constants.map {|klass| klass.to_s }
|
29
|
+
end
|
30
|
+
end
|
data/lib/ors/commands/base.rb
CHANGED
@@ -1,18 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
class ORS
|
2
|
+
module Commands
|
3
|
+
class Base
|
4
|
+
include ORS::Helpers
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
module ClassMethods
|
7
|
+
def run_without_setup
|
8
|
+
new.execute
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
command = new
|
13
|
+
command.setup
|
14
|
+
|
15
|
+
# now that the command has had a chance at the args
|
16
|
+
# we let our config finish its setup of variables
|
17
|
+
ORS.config.finalize!
|
18
|
+
|
19
|
+
if ORS.config.valid?
|
20
|
+
# now execute the command
|
21
|
+
command.execute
|
22
|
+
else
|
23
|
+
info "ERROR: Invalid options given."
|
24
|
+
ORS::Commands::Help.run_without_setup
|
25
|
+
end
|
26
|
+
end
|
8
27
|
end
|
9
|
-
|
10
|
-
extend ClassMethods
|
28
|
+
extend ClassMethods
|
11
29
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
30
|
+
def setup
|
31
|
+
end
|
15
32
|
|
16
|
-
|
33
|
+
def usage
|
34
|
+
"./ors base [options]"
|
35
|
+
end
|
17
36
|
|
37
|
+
def description
|
38
|
+
"Base Command Class"
|
39
|
+
end
|
40
|
+
|
41
|
+
def help_options
|
42
|
+
<<-END
|
43
|
+
=== Options
|
44
|
+
from|to environment Set which environment to use (default production)
|
45
|
+
--pretend (or -p) Don't execute anything, just show me what you're going to do
|
46
|
+
--no-gateway (or -ng) Don't use a gateway (if you're inside the firewall)
|
47
|
+
END
|
48
|
+
end
|
49
|
+
|
50
|
+
def help
|
51
|
+
puts <<-END
|
52
|
+
Usage: #{usage}
|
53
|
+
|
54
|
+
=== Description
|
55
|
+
#{description}
|
56
|
+
|
57
|
+
#{help_options}
|
58
|
+
END
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
18
62
|
end
|
data/lib/ors/commands/changes.rb
CHANGED
@@ -1,13 +1,27 @@
|
|
1
|
-
|
1
|
+
class ORS
|
2
|
+
module Commands
|
3
|
+
class Changes < Base
|
4
|
+
def setup
|
5
|
+
@local_ref = ORS.config[:args].shift
|
6
|
+
parse_remote_and_or_branch
|
7
|
+
end
|
2
8
|
|
3
|
-
|
9
|
+
def execute
|
10
|
+
results = execute_command(ORS.config[:console_server],
|
11
|
+
prepare_environment_with_rvm,
|
12
|
+
%(git show | head -1),
|
13
|
+
:capture => true)
|
4
14
|
|
5
|
-
|
6
|
-
|
15
|
+
system('git', 'log', [@local_ref, "remotes/#{ORS.config[:remote]}/#{ORS.config[:branch]}"].join("..")) if results =~ /commit (.*)/
|
16
|
+
end
|
7
17
|
|
8
|
-
|
9
|
-
|
18
|
+
def usage
|
19
|
+
"./ors changes local_ref [remote|remote/branch] [options]"
|
20
|
+
end
|
10
21
|
|
22
|
+
def description
|
23
|
+
"Detects changes between local commits and what is deployed"
|
24
|
+
end
|
25
|
+
end # Changes < Base
|
11
26
|
end
|
12
|
-
|
13
27
|
end
|
data/lib/ors/commands/console.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
class ORS
|
2
|
+
module Commands
|
3
|
+
class Console < Base
|
4
|
+
def execute
|
5
|
+
execute_command(ORS.config[:console_server],
|
6
|
+
prepare_environment_with_rvm,
|
7
|
+
%(if [ -f script/rails ]; then bundle exec rails console #{ORS.config[:environment]}; else ./script/console #{ORS.config[:environment]}; fi),
|
8
|
+
:exec => true)
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
def usage
|
12
|
+
"./ors console [options]"
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
Replaces current process and runs rails console.
|
15
|
-
|
16
|
-
|
17
|
-
--pretend (or -p) Don't execute anything, just show me what you're going to do
|
18
|
-
--no-gateway (or -ng) Don't use a gateway (if you're inside the firewall)
|
19
|
-
END
|
20
|
-
end
|
15
|
+
def description
|
16
|
+
"Replaces current process and runs rails console."
|
17
|
+
end
|
18
|
+
end # Console < Base
|
21
19
|
end
|
22
20
|
end
|
data/lib/ors/commands/deploy.rb
CHANGED
@@ -1,23 +1,34 @@
|
|
1
|
-
|
1
|
+
class ORS
|
2
|
+
module Commands
|
3
|
+
class Deploy < Base
|
2
4
|
|
3
|
-
|
5
|
+
def setup
|
6
|
+
parse_remote_and_or_branch
|
7
|
+
end
|
4
8
|
|
5
|
-
|
6
|
-
|
9
|
+
def execute
|
10
|
+
info "deploying #{ORS.config[:name]} #{ORS.config[:environment]}..."
|
7
11
|
|
8
|
-
|
12
|
+
[Update, Symlink, Migrate].each {|command| command.run_without_setup }
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
if ORS.config[:remote_deploy_hook]
|
15
|
+
execute_in_parallel(ORS.config[:app_servers]) do |server|
|
16
|
+
execute_command server, prepare_environment, "RAILS_ENV=#{ORS.config[:environment]} #{ORS.config[:remote_deploy_hook]}"
|
17
|
+
end
|
13
18
|
end
|
14
|
-
end
|
15
19
|
|
16
|
-
|
20
|
+
Restart.run_without_setup
|
17
21
|
|
18
|
-
|
19
|
-
|
22
|
+
eval ERB.new(ORS.config[:deploy_hook]).result(binding) if ORS.config[:deploy_hook]
|
23
|
+
end
|
20
24
|
|
21
|
-
|
25
|
+
def usage
|
26
|
+
"./ors deploy [remote|remote/branch] [options]"
|
27
|
+
end
|
22
28
|
|
29
|
+
def description
|
30
|
+
"Deploys given branch (origin/environment by default) to given environment"
|
31
|
+
end
|
32
|
+
end # Deploy < Base
|
33
|
+
end
|
23
34
|
end
|
data/lib/ors/commands/env.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
|
1
|
+
class ORS
|
2
|
+
module Commands
|
3
|
+
class Env < Base
|
2
4
|
|
3
|
-
|
5
|
+
def execute
|
6
|
+
puts "ORS v#{ORS::VERSION} configuration:\n\n"
|
4
7
|
|
5
|
-
def execute
|
6
|
-
puts "ORS v#{ORS::VERSION} configuration:\n\n"
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
ORS.config._options.each_pair do |key, value|
|
10
|
+
puts "%20s: %-40s" % [key, value.inspect]
|
11
|
+
end
|
11
12
|
end
|
12
|
-
end
|
13
|
-
|
13
|
+
end # Env < Base
|
14
14
|
end
|
15
15
|
end
|
data/lib/ors/commands/exec.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
|
-
|
1
|
+
class ORS
|
2
|
+
module Commands
|
3
|
+
class Exec < Base
|
2
4
|
|
3
|
-
|
5
|
+
def setup
|
6
|
+
@command = ORS.config[:args].shift
|
7
|
+
end
|
4
8
|
|
5
|
-
|
6
|
-
|
9
|
+
def execute
|
10
|
+
info "executing command for #{ORS.config[:name]} #{ORS.config[:environment]}..."
|
7
11
|
|
8
|
-
|
9
|
-
|
12
|
+
execute_command migration_server, prepare_environment, %(bundle exec #{@command})
|
13
|
+
end
|
10
14
|
|
15
|
+
def usage
|
16
|
+
"./ors exec command [options]"
|
17
|
+
end
|
18
|
+
end # Exec < Base
|
11
19
|
end
|
12
|
-
|
13
20
|
end
|
data/lib/ors/commands/help.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
class ORS
|
2
|
+
module Commands
|
3
|
+
class Help < Base
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
def execute
|
6
|
-
puts <<-END
|
5
|
+
def execute
|
6
|
+
puts <<-END
|
7
7
|
Usage: ./ors <action> [environment=production] [options]
|
8
8
|
|
9
9
|
=== Actions
|
@@ -25,11 +25,9 @@ update Updates the code on all servers
|
|
25
25
|
Must be one of: production demo staging
|
26
26
|
Defaults to production.
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
|
28
|
+
#{help_options}
|
29
|
+
END
|
30
|
+
end
|
31
|
+
end # Help < Base
|
34
32
|
end
|
35
33
|
end
|
data/lib/ors/commands/logs.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class ORS
|
2
|
+
module Commands
|
3
|
+
class Logs < Base
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
puts ORS::LogUnifier.new(all_logs).unify unless pretending
|
15
|
-
end
|
5
|
+
def execute
|
6
|
+
all_logs = ORS.config[:app_servers].map do |server|
|
7
|
+
[
|
8
|
+
server,
|
9
|
+
execute_command(server,
|
10
|
+
prepare_environment,
|
11
|
+
%(tail -n #{ORS.config[:log_lines]} log/#{ORS.config[:environment]}.log),
|
12
|
+
:capture => true)
|
13
|
+
]
|
14
|
+
end
|
16
15
|
|
16
|
+
puts ORS::LogUnifier.new(all_logs).unify unless ORS.config[:pretending]
|
17
|
+
end
|
18
|
+
end # Logs < Base
|
17
19
|
end
|
18
20
|
end
|