Class: Anvil::Engine

Inherits:
Object
  • Object
show all
Extended by:
Helpers
Defined in:
lib/anvil/engine.rb

Class Method Summary collapse

Methods included from Helpers

anvil_metadata_dir, is_url?, json_decode, json_encode, read_anvil_metadata, write_anvil_metadata

Class Method Details

.build(source, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/anvil/engine.rb', line 14

def self.build(source, options={})
  if options[:pipeline]
    old_stdout = $stdout.dup
    $stdout = $stderr
  end

  source ||= "."

  buildpack = options[:buildpack] || (source, "buildpack")

  build_options = {
    :buildpack => prepare_buildpack(buildpack),
    :type      => options[:type] || "tgz"
  }

  builder = if is_url?(source)
    Anvil::Builder.new(source)
  else
    manifest = Anvil::Manifest.new(File.expand_path(source),
      :cache  => (source, "cache"),
      :ignore => options[:ignore])
    upload_missing manifest

    manifest
  end

  slug_url = builder.build(build_options) do |chunk|
    print chunk
  end

  unless is_url?(source)
     source, "buildpack", buildpack
     source, "cache",     manifest.cache_url
  end

  old_stdout.puts slug_url if options[:pipeline]

  slug_url
end

.prepare_buildpack(buildpack) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/anvil/engine.rb', line 58

def self.prepare_buildpack(buildpack)
  buildpack = buildpack.to_s
  if buildpack == ""
    buildpack
  elsif is_url?(buildpack)
    buildpack
  elsif buildpack =~ /\A\w+\/\w+\Z/
    "http://codon-buildpacks.s3.amazonaws.com/buildpacks/#{buildpack}.tgz"
  elsif File.exists?(buildpack) && File.directory?(buildpack)
    manifest = Anvil::Manifest.new(buildpack)
    upload_missing manifest, "buildpack"
    manifest.save
  else
    raise Anvil::Builder::BuildError.new("unrecognized buildpack specification: #{buildpack}")
  end
end

.upload_missing(manifest, title = "app") ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/anvil/engine.rb', line 75

def self.upload_missing(manifest, title="app")
  print "Checking for #{title} files to sync... "
  missing = manifest.missing
  puts "done, #{missing.length} files needed"

  return if missing.length.zero?

  queue = Queue.new
  total_size = missing.map { |hash, file| file["size"].to_i }.inject(&:+)

  display = Thread.new do
    Progress.start "Uploading", total_size
    while (msg = queue.pop).first != :done
      case msg.first
        when :step then Progress.step msg.last.to_i
      end
    end
    Progress.stop
  end

  if missing.length > 0
    manifest.upload(missing.keys) do |file|
      queue << [:step, file["size"].to_i]
    end
    queue << [:done, nil]
  end

  display.join
end

.versionObject



54
55
56
# File 'lib/anvil/engine.rb', line 54

def self.version
  puts Anvil::VERSION
end