Class: Nomade::JobBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/nomade/job_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ JobBuilder

Returns a new instance of JobBuilder.



6
7
8
# File 'lib/nomade/job_builder.rb', line 6

def initialize(http)
  @http = http
end

Instance Method Details

#build(template_file, image_full_name, template_variables = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/nomade/job_builder.rb', line 10

def build(template_file, image_full_name, template_variables = {})
  # image_full_name should be in the form of:
  # redis:4.0.1
  # kaspergrubbe/secretimage:latest
  # billetto/billetto-rails:4.2.24
  unless image_full_name.match(/\A[a-zA-Z0-9\/\-\_]+\:[a-zA-Z0-9\.\-\_]+\z/)
    raise Nomade::FormattingError.new("Image-format wrong: #{image_full_name}")
  end

  job_hcl = render_erb(template_file, image_full_name, template_variables)
  job_json = @http.convert_hcl_to_json(job_hcl)
  job_hash = JSON.parse(job_json)

  Nomade::Job.new(image_full_name, job_hcl, job_json, job_hash)
end