Class: Anvil::Manifest

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/anvil/manifest.rb

Constant Summary collapse

PUSH_THREAD_COUNT =
40

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#anvil_metadata_dir, #json_decode, #json_encode, #read_anvil_metadata, #write_anvil_metadata

Constructor Details

#initialize(dir = nil, cache_url = nil) ⇒ Manifest

Returns a new instance of Manifest.



18
19
20
21
22
# File 'lib/anvil/manifest.rb', line 18

def initialize(dir=nil, cache_url=nil)
  @dir = dir
  @manifest = @dir ? directory_manifest(@dir) : {}
  @cache_url = cache_url
end

Instance Attribute Details

#cache_urlObject (readonly)

Returns the value of attribute cache_url.



14
15
16
# File 'lib/anvil/manifest.rb', line 14

def cache_url
  @cache_url
end

#dirObject (readonly)

Returns the value of attribute dir.



15
16
17
# File 'lib/anvil/manifest.rb', line 15

def dir
  @dir
end

#manifestObject (readonly)

Returns the value of attribute manifest.



16
17
18
# File 'lib/anvil/manifest.rb', line 16

def manifest
  @manifest
end

Instance Method Details

#add(filename) ⇒ Object



87
88
89
# File 'lib/anvil/manifest.rb', line 87

def add(filename)
  @manifest[filename] = file_manifest(filename)
end

#build(options = {}) ⇒ Object



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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/anvil/manifest.rb', line 24

def build(options={})
  uri  = URI.parse("#{anvil_host}/manifest/build")
  http = Net::HTTP.new(uri.host, uri.port)

  if uri.scheme == "https"
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

  req = Net::HTTP::Post.new uri.request_uri

  env = options[:env] || {}

  req.set_form_data({
    "buildpack" => options[:buildpack],
    "cache"     => @cache_url,
    "env"       => json_encode(options[:env] || {}),
    "manifest"  => self.to_json
  })

  slug_url = nil

  http.request(req) do |res|
    slug_url = res["x-slug-url"]
    @cache_url = res["x-cache-url"]

    begin
      res.read_body do |chunk|
        yield chunk
      end
    rescue EOFError
      puts
      raise Heroku::Builder::BuildError, "terminated unexpectedly"
    end

    code = if res["x-exit-code"].nil?
      manifest_id = Array(res["x-manifest-id"]).first
      Integer(String.new(anvil["/exit/#{manifest_id}"].get.to_s))
    else
      res["x-exit-code"].first.to_i
    end

    raise Heroku::Builder::BuildError, "exited #{code}" unless code.zero?
  end

  slug_url
end

#saveObject



72
73
74
75
# File 'lib/anvil/manifest.rb', line 72

def save
  res = anvil["/manifest"].post(:manifest => self.to_json)
  res.headers[:location]
end

#to_jsonObject



83
84
85
# File 'lib/anvil/manifest.rb', line 83

def to_json
  json_encode(@manifest)
end

#uploadObject



77
78
79
80
81
# File 'lib/anvil/manifest.rb', line 77

def upload
  missing = json_decode(anvil["/manifest/diff"].post(:manifest => self.to_json).to_s)
  upload_hashes missing
  missing.length
end