HeSYINUvSBZfxqA-foreman 0.20.0.3 → 0.20.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,5 @@
1
1
  require "foreman"
2
2
  require "foreman/engine"
3
- require "foreman/export"
4
3
  require "thor"
5
4
  require "yaml"
6
5
 
@@ -13,7 +12,8 @@ class Foreman::CLI < Thor
13
12
  method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env"
14
13
  method_option :port, :type => :numeric, :aliases => "-p"
15
14
  method_option :min, :type => :numeric, :aliases => "-m"
16
- method_option :concurrency, :type => :string, :aliases => "-c", :banner => '"alpha=5,bar=3"'
15
+ method_option :concurrency, :type => :string, :aliases => "-c", :banner => '"alpha=5,bar=3,feh,meh"'
16
+ method_option :args, :type => :array, :aliases => "-a", :banner => 'alpha bar feh meh'
17
17
 
18
18
  def start(process=nil)
19
19
  check_procfile!
@@ -25,31 +25,6 @@ class Foreman::CLI < Thor
25
25
  end
26
26
  end
27
27
 
28
- desc "export FORMAT LOCATION", "Export the application to another process management format"
29
-
30
- method_option :app, :type => :string, :aliases => "-a"
31
- method_option :log, :type => :string, :aliases => "-l"
32
- method_option :port, :type => :numeric, :aliases => "-p"
33
- method_option :user, :type => :string, :aliases => "-u"
34
- method_option :template, :type => :string, :aliases => "-t"
35
- method_option :concurrency, :type => :string, :aliases => "-c",
36
- :banner => '"alpha=5,bar=3"'
37
-
38
- def export(format, location=nil)
39
- check_procfile!
40
-
41
- formatter = case format
42
- when "inittab" then Foreman::Export::Inittab
43
- when "upstart" then Foreman::Export::Upstart
44
- else error "Unknown export format: #{format}."
45
- end
46
-
47
- formatter.new(engine).export(location, options)
48
-
49
- rescue Foreman::Export::Exception => ex
50
- error ex.message
51
- end
52
-
53
28
  desc "check", "Validate your application's Procfile"
54
29
 
55
30
  def check
@@ -65,7 +40,7 @@ private ######################################################################
65
40
  end
66
41
 
67
42
  def engine
68
- @engine ||= Foreman::Engine.new(procfile)
43
+ @engine ||= Foreman::Engine.new(procfile, options)
69
44
  end
70
45
 
71
46
  def procfile
@@ -16,10 +16,10 @@ class Foreman::Engine
16
16
 
17
17
  COLORS = [ cyan, yellow, green, magenta, red ]
18
18
 
19
- def initialize(procfile)
19
+ def initialize(procfile, options={})
20
20
  @procfile =
21
21
  if procfile.end_with? ".rb"
22
- eval_procfile(procfile)
22
+ eval_procfile(procfile, options)
23
23
  else
24
24
  read_procfile(procfile)
25
25
  end
@@ -175,8 +175,8 @@ private ######################################################################
175
175
  $0 = title
176
176
  end
177
177
 
178
- def eval_procfile(procfile)
179
- eval(read_procfile(procfile))
178
+ def eval_procfile(procfile, options)
179
+ eval(read_procfile(procfile), binding)
180
180
  end
181
181
 
182
182
  def read_procfile(procfile)
@@ -7,7 +7,7 @@ class Foreman::Utils
7
7
  pairs = concurrency.to_s.gsub(/\s/, "").split(",")
8
8
  pairs.inject(Hash.new(min)) do |hash, pair|
9
9
  process, amount = pair.split("=")
10
- hash.update(process => amount.to_i)
10
+ hash.update(process => (amount || 1).to_i)
11
11
  end
12
12
  end
13
13
  end
@@ -1,5 +1,5 @@
1
1
  module Foreman
2
2
 
3
- VERSION = "0.20.0.3"
3
+ VERSION = "0.20.0.4"
4
4
 
5
5
  end
@@ -25,39 +25,6 @@ describe "Foreman::CLI" do
25
25
  end
26
26
  end
27
27
 
28
- describe "export" do
29
- describe "with a non-existent Procfile" do
30
- it "prints an error" do
31
- mock_error(subject, "Procfile does not exist.") do
32
- dont_allow.instance_of(Foreman::Engine).export
33
- subject.export("testapp")
34
- end
35
- end
36
- end
37
-
38
- describe "with a Procfile" do
39
- before(:each) { write_procfile }
40
-
41
- describe "with an invalid formatter" do
42
- it "prints an error" do
43
- mock_error(subject, "Unknown export format: invalidformatter.") do
44
- subject.export("invalidformatter")
45
- end
46
- end
47
- end
48
-
49
- describe "with a valid config" do
50
- before(:each) { write_foreman_config("testapp") }
51
-
52
- it "runs successfully" do
53
- dont_allow(subject).error
54
- mock.instance_of(Foreman::Export::Upstart).export("/tmp/foo", {})
55
- subject.export("upstart", "/tmp/foo")
56
- end
57
- end
58
- end
59
- end
60
-
61
28
  describe "check" do
62
29
  describe "with a valid Procfile" do
63
30
  before { write_procfile }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HeSYINUvSBZfxqA-foreman
3
3
  version: !ruby/object:Gem::Version
4
- hash: 233
4
+ hash: 231
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 20
9
9
  - 0
10
- - 3
11
- version: 0.20.0.3
10
+ - 4
11
+ version: 0.20.0.4
12
12
  platform: ruby
13
13
  authors:
14
14
  - David Dollar
@@ -178,10 +178,6 @@ files:
178
178
  - data/export/upstart/process_master.conf.erb
179
179
  - lib/foreman/cli.rb
180
180
  - lib/foreman/engine.rb
181
- - lib/foreman/export/base.rb
182
- - lib/foreman/export/inittab.rb
183
- - lib/foreman/export/upstart.rb
184
- - lib/foreman/export.rb
185
181
  - lib/foreman/process.rb
186
182
  - lib/foreman/utils.rb
187
183
  - lib/foreman/version.rb
@@ -189,8 +185,6 @@ files:
189
185
  - README.markdown
190
186
  - spec/foreman/cli_spec.rb
191
187
  - spec/foreman/engine_spec.rb
192
- - spec/foreman/export/upstart_spec.rb
193
- - spec/foreman/export_spec.rb
194
188
  - spec/foreman/process_spec.rb
195
189
  - spec/foreman_spec.rb
196
190
  - spec/resources/export/upstart/app-alpha-1.conf
@@ -1,9 +0,0 @@
1
- require "foreman"
2
-
3
- module Foreman::Export
4
- class Exception < ::Exception; end
5
- end
6
-
7
- require "foreman/export/base"
8
- require "foreman/export/inittab"
9
- require "foreman/export/upstart"
@@ -1,44 +0,0 @@
1
- require "foreman/export"
2
- require "foreman/utils"
3
-
4
- class Foreman::Export::Base
5
-
6
- attr_reader :engine
7
-
8
- def initialize(engine)
9
- @engine = engine
10
- end
11
-
12
- def export
13
- raise "export method must be overridden"
14
- end
15
-
16
- private ######################################################################
17
-
18
- def error(message)
19
- raise Foreman::Export::Exception.new(message)
20
- end
21
-
22
- def say(message)
23
- puts "[foreman export] %s" % message
24
- end
25
-
26
- def export_template(exporter, file, template_root)
27
- if template_root && File.exist?(file_path = File.join(template_root, file))
28
- File.read(file_path)
29
- elsif File.exist?(file_path = File.join("~/.foreman/templates", file))
30
- File.read(file_path)
31
- else
32
- File.read(File.expand_path("../../../../data/export/#{exporter}/#{file}", __FILE__))
33
- end
34
- end
35
-
36
- def write_file(filename, contents)
37
- say "writing: #{filename}"
38
-
39
- File.open(filename, "w") do |file|
40
- file.puts contents
41
- end
42
- end
43
-
44
- end
@@ -1,38 +0,0 @@
1
- require "foreman/export"
2
-
3
- class Foreman::Export::Inittab < Foreman::Export::Base
4
-
5
- def export(fname=nil, options={})
6
- app = options[:app] || File.basename(engine.directory)
7
- user = options[:user] || app
8
- log_root = options[:log] || "/var/log/#{app}"
9
-
10
- concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
11
-
12
- inittab = []
13
- inittab << "# ----- foreman #{app} processes -----"
14
-
15
- engine.processes.values.inject(1) do |index, process|
16
- 1.upto(concurrency[process.name]) do |num|
17
- id = app.slice(0, 2).upcase + sprintf("%02d", index)
18
- port = engine.port_for(process, num, options[:port])
19
- inittab << "#{id}:4:respawn:/bin/su - #{user} -c 'PORT=#{port} #{process.command} >> #{log_root}/#{process.name}-#{num}.log 2>&1'"
20
- index += 1
21
- end
22
- index
23
- end
24
-
25
- inittab << "# ----- end foreman #{app} processes -----"
26
-
27
- inittab = inittab.join("\n") + "\n"
28
-
29
- if fname
30
- FileUtils.mkdir_p(log_root) rescue error "could not create #{log_root}"
31
- FileUtils.chown(user, nil, log_root) rescue error "could not chown #{log_root} to #{user}"
32
- write_file(fname, inittab)
33
- else
34
- puts inittab
35
- end
36
- end
37
-
38
- end
@@ -1,42 +0,0 @@
1
- require "erb"
2
- require "foreman/export"
3
-
4
- class Foreman::Export::Upstart < Foreman::Export::Base
5
-
6
- def export(location, options={})
7
- error("Must specify a location") unless location
8
-
9
- FileUtils.mkdir_p location
10
-
11
- app = options[:app] || File.basename(engine.directory)
12
- user = options[:user] || app
13
- log_root = options[:log] || "/var/log/#{app}"
14
- template_root = options[:template]
15
-
16
- Dir["#{location}/#{app}*.conf"].each do |file|
17
- say "cleaning up: #{file}"
18
- FileUtils.rm(file)
19
- end
20
-
21
- concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
22
-
23
- master_template = export_template("upstart", "master.conf.erb", template_root)
24
- master_config = ERB.new(master_template).result(binding)
25
- write_file "#{location}/#{app}.conf", master_config
26
-
27
- process_template = export_template("upstart", "process.conf.erb", template_root)
28
-
29
- engine.processes.values.each do |process|
30
- process_master_template = export_template("upstart", "process_master.conf.erb", template_root)
31
- process_master_config = ERB.new(process_master_template).result(binding)
32
- write_file "#{location}/#{app}-#{process.name}.conf", process_master_config
33
-
34
- 1.upto(concurrency[process.name]) do |num|
35
- port = engine.port_for(process, num, options[:port])
36
- process_config = ERB.new(process_template).result(binding)
37
- write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config
38
- end
39
- end
40
- end
41
-
42
- end
@@ -1,55 +0,0 @@
1
- require "spec_helper"
2
- require "foreman/engine"
3
- require "foreman/export/upstart"
4
- require "tmpdir"
5
-
6
- describe Foreman::Export::Upstart do
7
- let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
- let(:engine) { Foreman::Engine.new(procfile) }
9
- let(:upstart) { Foreman::Export::Upstart.new(engine) }
10
-
11
- before(:each) { load_export_templates_into_fakefs("upstart") }
12
- before(:each) { stub(upstart).say }
13
-
14
- it "exports to the filesystem" do
15
- upstart.export("/tmp/init")
16
-
17
- File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf")
18
- File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf")
19
- File.read("/tmp/init/app-alpha-1.conf").should == example_export_file("upstart/app-alpha-1.conf")
20
- File.read("/tmp/init/app-alpha-2.conf").should == example_export_file("upstart/app-alpha-2.conf")
21
- File.read("/tmp/init/app-bravo.conf").should == example_export_file("upstart/app-bravo.conf")
22
- File.read("/tmp/init/app-bravo-1.conf").should == example_export_file("upstart/app-bravo-1.conf")
23
- end
24
-
25
- context "with alternate templates" do
26
- let(:template_root) { "/tmp/alternate" }
27
-
28
- before do
29
- FileUtils.mkdir_p template_root
30
- File.open("#{template_root}/master.conf.erb", "w") { |f| f.puts "alternate_template" }
31
- end
32
-
33
- it "can export with alternate template files" do
34
- upstart.export("/tmp/init", :template => template_root)
35
-
36
- File.read("/tmp/init/app.conf").should == "alternate_template\n"
37
- end
38
- end
39
-
40
- context "with alternate templates from home dir" do
41
- let(:default_template_root) {File.expand_path("~/.foreman/templates")}
42
-
43
- before do
44
- FileUtils.mkdir_p default_template_root
45
- File.open("#{default_template_root}/master.conf.erb", "w") { |f| f.puts "default_alternate_template" }
46
- end
47
-
48
- it "can export with alternate template files" do
49
- upstart.export("/tmp/init")
50
-
51
- File.read("/tmp/init/app.conf").should == "default_alternate_template\n"
52
- end
53
- end
54
-
55
- end
@@ -1,2 +0,0 @@
1
- require "spec_helper"
2
- require "foreman/export"