anvil-cli 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/anvil/cli.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "anvil"
2
2
  require "anvil/builder"
3
+ require "anvil/engine"
3
4
  require "anvil/manifest"
4
5
  require "anvil/version"
5
6
  require "progress"
@@ -16,41 +17,7 @@ class Anvil::CLI < Thor
16
17
  method_option :pipeline, :type => :boolean, :aliases => "-p", :desc => "Pipe compile output to stderr and put the slug url on stdout"
17
18
 
18
19
  def build(source=nil)
19
- if options[:pipeline]
20
- old_stdout = $stdout.dup
21
- $stdout = $stderr
22
- end
23
-
24
- source ||= "."
25
-
26
- build_options = {
27
- :buildpack => prepare_buildpack(options[:buildpack].to_s)
28
- }
29
-
30
- builder = if is_url?(source)
31
- Anvil::Builder.new(source)
32
- else
33
- manifest = Anvil::Manifest.new(File.expand_path(source))
34
- print "Checking for files to sync... "
35
- missing = manifest.missing
36
- puts "done, #{missing.length} files needed"
37
-
38
- if missing.length > 0
39
- Progress.start("Uploading", missing.map { |hash, file| file["size"].to_i }.inject(&:+))
40
- manifest.upload(missing.keys) do |file|
41
- Progress.step file["size"].to_i
42
- end
43
- puts "Uploading... done "
44
- end
45
-
46
- manifest
47
- end
48
-
49
- slug_url = builder.build(build_options) do |chunk|
50
- print chunk
51
- end
52
-
53
- old_stdout.puts slug_url if options[:pipeline]
20
+ Anvil::Engine.build(source, options)
54
21
  rescue Anvil::Builder::BuildError => ex
55
22
  error "Build Error: #{ex.message}"
56
23
  end
@@ -58,31 +25,7 @@ class Anvil::CLI < Thor
58
25
  desc "version", "Display Anvil version"
59
26
 
60
27
  def version
61
- puts Anvil::VERSION
62
- end
63
-
64
- private
65
-
66
- def is_url?(string)
67
- URI.parse(string).scheme rescue nil
68
- end
69
-
70
- def prepare_buildpack(buildpack)
71
- if buildpack == ""
72
- buildpack
73
- elsif is_url?(buildpack)
74
- buildpack
75
- elsif buildpack =~ /\A\w+\/\w+\Z/
76
- "http://buildkits-dev.s3.amazonaws.com/buildpacks/#{buildpack}.tgz"
77
- elsif File.exists?(buildpack) && File.directory?(buildpack)
78
- print "Uploading buildpack... "
79
- manifest = Anvil::Manifest.new(buildpack)
80
- manifest.upload
81
- manifest.save
82
- puts "done"
83
- else
84
- error "unrecognized buildpack specification: #{buildpack}"
85
- end
28
+ Anvil::Engine.version
86
29
  end
87
30
 
88
31
  end
@@ -0,0 +1,93 @@
1
+ require "anvil"
2
+ require "anvil/builder"
3
+ require "anvil/manifest"
4
+ require "anvil/version"
5
+ require "progress"
6
+ require "thor"
7
+ require "thread"
8
+ require "uri"
9
+
10
+ class Anvil::Engine < Thor
11
+
12
+ def self.build(source, options={})
13
+ if options[:pipeline]
14
+ old_stdout = $stdout.dup
15
+ $stdout = $stderr
16
+ end
17
+
18
+ source ||= "."
19
+
20
+ build_options = {
21
+ :buildpack => prepare_buildpack(options[:buildpack].to_s)
22
+ }
23
+
24
+ builder = if is_url?(source)
25
+ Anvil::Builder.new(source)
26
+ else
27
+ manifest = Anvil::Manifest.new(File.expand_path(source))
28
+ upload_missing manifest
29
+ manifest
30
+ end
31
+
32
+ slug_url = builder.build(build_options) do |chunk|
33
+ print chunk
34
+ end
35
+
36
+ old_stdout.puts slug_url if options[:pipeline]
37
+ end
38
+
39
+ def self.version
40
+ puts Anvil::VERSION
41
+ end
42
+
43
+ def self.is_url?(string)
44
+ URI.parse(string).scheme rescue nil
45
+ end
46
+
47
+ def self.prepare_buildpack(buildpack)
48
+ if buildpack == ""
49
+ buildpack
50
+ elsif is_url?(buildpack)
51
+ buildpack
52
+ elsif buildpack =~ /\A\w+\/\w+\Z/
53
+ "http://buildkits-dev.s3.amazonaws.com/buildpacks/#{buildpack}.tgz"
54
+ elsif File.exists?(buildpack) && File.directory?(buildpack)
55
+ manifest = Anvil::Manifest.new(buildpack)
56
+ upload_missing manifest, "buildpack"
57
+ manifest.save
58
+ else
59
+ error "unrecognized buildpack specification: #{buildpack}"
60
+ end
61
+ end
62
+
63
+ def self.upload_missing(manifest, title="app")
64
+ print "Checking for files to sync for #{title}... "
65
+ missing = manifest.missing
66
+ puts "done, #{missing.length} files needed"
67
+
68
+ return if missing.length.zero?
69
+
70
+ queue = Queue.new
71
+ total_size = missing.map { |hash, file| file["size"].to_i }.inject(&:+)
72
+
73
+ display = Thread.new do
74
+ Progress.start "Uploading", total_size
75
+ while (msg = queue.pop).first != :done
76
+ case msg.first
77
+ when :step then Progress.step msg.last.to_i
78
+ end
79
+ end
80
+ puts "Uploading... done "
81
+ end
82
+
83
+ if missing.length > 0
84
+ manifest.upload(missing.keys) do |file|
85
+ queue << [:step, file["size"].to_i]
86
+ end
87
+ queue << [:done, nil]
88
+ end
89
+
90
+ display.join
91
+ end
92
+
93
+ end
@@ -87,7 +87,7 @@ class Anvil::Manifest
87
87
  end
88
88
  end
89
89
 
90
- def upload(hashes=missing, &blk)
90
+ def upload(missing, &blk)
91
91
  upload_hashes missing, &blk
92
92
  missing.length
93
93
  end
data/lib/anvil/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Anvil
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anvil-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-27 00:00:00.000000000 Z
12
+ date: 2012-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: progress
16
- requirement: &70196229688420 !ruby/object:Gem::Requirement
16
+ requirement: &70248977317820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.4.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70196229688420
24
+ version_requirements: *70248977317820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &70196229687860 !ruby/object:Gem::Requirement
27
+ requirement: &70248977317260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.6.7
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70196229687860
35
+ version_requirements: *70248977317260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thor
38
- requirement: &70196229687260 !ruby/object:Gem::Requirement
38
+ requirement: &70248977316660 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 0.15.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70196229687260
46
+ version_requirements: *70248977316660
47
47
  description: Alternate Heroku build workflow
48
48
  email: david@dollar.io
49
49
  executables:
@@ -54,6 +54,7 @@ files:
54
54
  - bin/anvil
55
55
  - lib/anvil/builder.rb
56
56
  - lib/anvil/cli.rb
57
+ - lib/anvil/engine.rb
57
58
  - lib/anvil/helpers.rb
58
59
  - lib/anvil/manifest.rb
59
60
  - lib/anvil/okjson.rb