subcontractor 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +17 -8
- data/lib/subcontractor/cli.rb +13 -17
- data/lib/subcontractor/command.rb +40 -0
- data/lib/subcontractor/version.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- data/spec/subcontractor/cli_spec.rb +54 -0
- data/subcontractor.gemspec +2 -0
- metadata +41 -43
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,7 @@ gem install subcontractor
|
|
18
18
|
or with bundler
|
19
19
|
|
20
20
|
```ruby
|
21
|
-
gem 'subcontractor', '0.
|
21
|
+
gem 'subcontractor', '0.8.0'
|
22
22
|
```
|
23
23
|
|
24
24
|
The gem provides an executable called ```subcontract``` that you will use from your Procfile. You can see what it does by running ```subcontract --help```
|
@@ -26,7 +26,8 @@ The gem provides an executable called ```subcontract``` that you will use from y
|
|
26
26
|
```
|
27
27
|
USAGE: subcontract [options] -- executable
|
28
28
|
-r, --rvm RVM run in a specific RVM (use `.` for ruby from `PATH`)
|
29
|
-
-b, --rbenv RBENV run in a specific RBENV
|
29
|
+
-b, --rbenv RBENV run in a specific RBENV (use `.` for local rbenv)
|
30
|
+
-c, --choose-env ENV run in either a specified RBENV or RVM, whichever is present
|
30
31
|
-d, --chdir PATH chdir to PATH before starting process
|
31
32
|
-s, --signal SIGNAL signal to send to process to kill it, default TERM
|
32
33
|
```
|
@@ -40,25 +41,32 @@ another_app: subcontract --rvm ruby-1.8.7-p249@another_app --chdir ../another_ap
|
|
40
41
|
|
41
42
|
Here another_app will be launch from the sibling directory another_app and will use the rvm ruby-1.8.7-p249@another_app. As you can see, the command that we wish to use to launch our application follows the double dashes (--).
|
42
43
|
|
43
|
-
You can also allow another_app to use its existing .rvmrc file
|
44
|
+
You can also allow another_app to use its existing .rvmrc file. This will load the .rvmrc file out of the current folder once it has been changed to the folder specified by --chdir
|
44
45
|
|
45
46
|
```
|
46
47
|
rails: rails s
|
47
|
-
another_app: subcontract --rvm
|
48
|
+
another_app: subcontract --rvm . --chdir ../another_app --signal INT -- rails s -p 3001
|
48
49
|
```
|
49
50
|
|
50
|
-
|
51
|
+
You can use specific rbenv version.
|
51
52
|
|
52
53
|
```
|
53
|
-
|
54
|
+
rbenv_app: bundle exec subcontract --rbenv 'ree-1.8.7-2012.02' --chdir ~/rbenv_app -- bundle exec rails server -p 3001
|
54
55
|
```
|
55
56
|
|
56
|
-
|
57
|
+
Or you can use whatever the local rbenv settings are for a project. This will load whatever `rbenv local` returns out of the current folder once it has been changed to the folder specified by --chdir
|
57
58
|
|
58
59
|
```
|
59
|
-
rbenv_app: bundle exec subcontract --rbenv
|
60
|
+
rbenv_app: bundle exec subcontract --rbenv . --chdir ~/rbenv_app -- bundle exec rails server -p 3001
|
60
61
|
```
|
61
62
|
|
63
|
+
If you have team members using both rvm and rbenv on a project then use --choose-env to use whatever version manager is present on the system. If both are present rbenv is chosen.
|
64
|
+
|
65
|
+
```
|
66
|
+
mixed_env_manager_app: bundle exec subcontract --choose-env . --chdir ~/mixed_env_manager_app -- bundle exec rails server -p 3001
|
67
|
+
```
|
68
|
+
|
69
|
+
|
62
70
|
### Contributions
|
63
71
|
* Fork the project
|
64
72
|
* Make your change
|
@@ -71,3 +79,4 @@ rbenv_app: bundle exec subcontract --rbenv 'ree-1.8.7-2012.02' --chdir ~/rbenv_a
|
|
71
79
|
* Paul Gross [github](http://github.com/pgr0ss) [blog](http://www.pgrs.net) [twitter](http://twitter.com/pgr0ss)
|
72
80
|
* Rune Skjoldborg Madsen [github](https://github.com/runemadsen)
|
73
81
|
* Masahiro Ihara [github](http://github.com/ihara2525) [twitter](http://twitter.com/ihara2525)
|
82
|
+
* Michael Nussbaum [github](https://github.com/mnussbaum)
|
data/lib/subcontractor/cli.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "optparse"
|
2
|
+
require "pty"
|
3
|
+
require "subcontractor/command"
|
3
4
|
|
4
5
|
$stdout.sync = true
|
5
6
|
|
6
7
|
module SafePty
|
7
8
|
def self.spawn command, &block
|
8
|
-
if Object.const_defined?(
|
9
|
+
if Object.const_defined?("Bundler")
|
9
10
|
Bundler.with_clean_env do
|
10
11
|
self.clear_more_env
|
11
12
|
self.spawn_internal command, &block
|
@@ -29,16 +30,15 @@ module SafePty
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def self.clear_more_env
|
32
|
-
[
|
33
|
+
["GEM_HOME", "GEM_PATH", "RUBYOPT", "RBENV_DIR"].each { |e| ENV.delete(e) }
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
37
|
module Subcontractor
|
37
38
|
class CLI
|
38
|
-
|
39
39
|
def run
|
40
40
|
options = parse_options(ARGV)
|
41
|
-
command =
|
41
|
+
command = Subcontractor::Command.build(ARGV, options)
|
42
42
|
Dir.chdir(options[:chdir]) if options[:chdir]
|
43
43
|
signal = options[:signal] || "TERM"
|
44
44
|
SafePty.spawn(command) do |stdin, stdout, pid|
|
@@ -74,26 +74,23 @@ module Subcontractor
|
|
74
74
|
end.map(&:first).map(&:to_i)
|
75
75
|
end
|
76
76
|
|
77
|
-
def build_command(parts, options)
|
78
|
-
parts.unshift("rvm #{options[:rvm]} exec") if options.has_key?(:rvm)
|
79
|
-
parts.unshift("env RBENV_VERSION=#{options[:rbenv]} rbenv exec") if options.has_key?(:rbenv)
|
80
|
-
parts.join(' ')
|
81
|
-
end
|
82
|
-
|
83
77
|
def parse_options(argv)
|
84
78
|
options = {}
|
85
79
|
parser = OptionParser.new do |opt|
|
86
80
|
opt.banner = "USAGE: subcontract [options] -- executable"
|
87
|
-
opt.on(
|
81
|
+
opt.on("-r", "--rvm RVM", "run in a specific RVM") do |rvm|
|
88
82
|
options[:rvm] = rvm
|
89
83
|
end
|
90
|
-
opt.on(
|
84
|
+
opt.on("-b", "--rbenv RBENV", "run in a specific RBENV") do |rbenv|
|
91
85
|
options[:rbenv] = rbenv
|
92
86
|
end
|
93
|
-
opt.on(
|
87
|
+
opt.on("-c", "--choose-env ENV", "run in either specified RBENV or RVM, whichever is present") do |env|
|
88
|
+
options[:choose_env] = env
|
89
|
+
end
|
90
|
+
opt.on("-d", "--chdir PATH", "chdir to PATH before starting process") do |path|
|
94
91
|
options[:chdir] = path
|
95
92
|
end
|
96
|
-
opt.on(
|
93
|
+
opt.on("-s", "--signal SIGNAL", "signal to send to process to kill it, default TERM") do |signal|
|
97
94
|
options[:signal] = signal
|
98
95
|
end
|
99
96
|
end
|
@@ -101,6 +98,5 @@ module Subcontractor
|
|
101
98
|
parser.parse! argv
|
102
99
|
options
|
103
100
|
end
|
104
|
-
|
105
101
|
end
|
106
102
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Subcontractor
|
2
|
+
class Command
|
3
|
+
def self.build(parts, options)
|
4
|
+
new(parts.dup, options).build
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(parts, options)
|
8
|
+
@parts = parts
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def build
|
13
|
+
if _use_command?(:rbenv)
|
14
|
+
@parts.unshift("#{_set_rbenv_version} rbenv exec")
|
15
|
+
elsif _use_command?(:rvm)
|
16
|
+
@parts.unshift("rvm #{_env_specifier(:rvm)} exec")
|
17
|
+
end
|
18
|
+
|
19
|
+
@parts.join(" ")
|
20
|
+
end
|
21
|
+
|
22
|
+
def _use_command?(command)
|
23
|
+
@options.has_key?(command) || _choose_env_and_command_present?(command)
|
24
|
+
end
|
25
|
+
|
26
|
+
def _choose_env_and_command_present?(command)
|
27
|
+
@options.has_key?(:choose_env) && system("which #{command} > /dev/null 2>&1")
|
28
|
+
end
|
29
|
+
|
30
|
+
def _set_rbenv_version
|
31
|
+
env_specifier = _env_specifier(:rbenv)
|
32
|
+
env_specifier = "`rbenv local`" if env_specifier == "."
|
33
|
+
"env RBENV_VERSION=#{env_specifier}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def _env_specifier(command)
|
37
|
+
@options[command] || @options[:choose_env]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Subcontractor::CLI do
|
4
|
+
before(:each) do
|
5
|
+
Object.instance_eval{ remove_const(:ARGV) }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#run" do
|
9
|
+
it "uses rvm with --rvm" do
|
10
|
+
ARGV = ["--rvm", ".", "test"]
|
11
|
+
SafePty.should_receive(:spawn).with("rvm . exec test")
|
12
|
+
Subcontractor::CLI.new.run
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with --rbenv" do
|
16
|
+
it "specifies a rbenv" do
|
17
|
+
ARGV = ["--rbenv", "1.9.3", "test"]
|
18
|
+
SafePty.should_receive(:spawn).with("env RBENV_VERSION=1.9.3 rbenv exec test")
|
19
|
+
Subcontractor::CLI.new.run
|
20
|
+
end
|
21
|
+
|
22
|
+
it "uses 'rbenv local' if a '.' is given as the rbenv version" do
|
23
|
+
ARGV = ["--rbenv", ".", "test"]
|
24
|
+
SafePty.should_receive(:spawn).with("env RBENV_VERSION=`rbenv local` rbenv exec test")
|
25
|
+
Subcontractor::CLI.new.run
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "creates a valid command if no environment manager is specifed" do
|
30
|
+
ARGV = ["test"]
|
31
|
+
SafePty.should_receive(:spawn).with("test")
|
32
|
+
Subcontractor::CLI.new.run
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with --choose-env" do
|
36
|
+
it "uses rbenv when rbenv is present" do
|
37
|
+
ARGV = ["--choose-env", "1.9.3", "test"]
|
38
|
+
SafePty.should_receive(:spawn).with("env RBENV_VERSION=1.9.3 rbenv exec test")
|
39
|
+
command = Subcontractor::Command.any_instance
|
40
|
+
command.should_receive(:system).with("which rbenv > /dev/null 2>&1").and_return(true)
|
41
|
+
Subcontractor::CLI.new.run
|
42
|
+
end
|
43
|
+
|
44
|
+
it "uses rvm when rvm is present and rbenv isn't" do
|
45
|
+
ARGV = ["--choose-env", ".", "test"]
|
46
|
+
SafePty.should_receive(:spawn).with("rvm . exec test")
|
47
|
+
command = Subcontractor::Command.any_instance
|
48
|
+
command.should_receive(:system).with("which rbenv > /dev/null 2>&1").and_return(false)
|
49
|
+
command.should_receive(:system).with("which rvm > /dev/null 2>&1").and_return(true)
|
50
|
+
Subcontractor::CLI.new.run
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/subcontractor.gemspec
CHANGED
@@ -14,6 +14,8 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = "subcontractor"
|
16
16
|
|
17
|
+
s.add_development_dependency("rspec")
|
18
|
+
|
17
19
|
s.files = `git ls-files`.split("\n")
|
18
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
21
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,34 +1,40 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: subcontractor
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 7
|
9
|
-
- 0
|
10
|
-
version: 0.7.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Tony Pitluga
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2013-10-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
22
30
|
description: rvm aware process launcher for foreman
|
23
|
-
email:
|
31
|
+
email:
|
24
32
|
- tony.pitluga@gmail.com
|
25
|
-
executables:
|
33
|
+
executables:
|
26
34
|
- subcontract
|
27
35
|
extensions: []
|
28
|
-
|
29
36
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
files:
|
37
|
+
files:
|
32
38
|
- .gitignore
|
33
39
|
- .rvmrc
|
34
40
|
- Gemfile
|
@@ -45,41 +51,33 @@ files:
|
|
45
51
|
- examples/webapp/config.ru
|
46
52
|
- lib/subcontractor.rb
|
47
53
|
- lib/subcontractor/cli.rb
|
54
|
+
- lib/subcontractor/command.rb
|
48
55
|
- lib/subcontractor/version.rb
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
- spec/subcontractor/cli_spec.rb
|
49
58
|
- subcontractor.gemspec
|
50
|
-
has_rdoc: true
|
51
59
|
homepage: https://github.com/pitluga/subcontractor
|
52
60
|
licenses: []
|
53
|
-
|
54
61
|
post_install_message:
|
55
62
|
rdoc_options: []
|
56
|
-
|
57
|
-
require_paths:
|
63
|
+
require_paths:
|
58
64
|
- lib
|
59
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
66
|
none: false
|
61
|
-
requirements:
|
62
|
-
- -
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
|
65
|
-
|
66
|
-
- 0
|
67
|
-
version: "0"
|
68
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
72
|
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
segments:
|
75
|
-
- 0
|
76
|
-
version: "0"
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
77
|
requirements: []
|
78
|
-
|
79
78
|
rubyforge_project: subcontractor
|
80
|
-
rubygems_version: 1.
|
79
|
+
rubygems_version: 1.8.23
|
81
80
|
signing_key:
|
82
81
|
specification_version: 3
|
83
82
|
summary: rvm aware process launcher for foreman
|
84
83
|
test_files: []
|
85
|
-
|