Class: Linecook::Baker::Baker
- Inherits:
-
Object
- Object
- Linecook::Baker::Baker
- Defined in:
- lib/linecook-gem/baker.rb
Instance Method Summary collapse
- #bake(snapshot: nil, upload: nil, keep: nil) ⇒ Object
- #clean_kitchen ⇒ Object
-
#initialize(image, directory: nil) ⇒ Baker
constructor
A new instance of Baker.
- #save ⇒ Object
Constructor Details
#initialize(image, directory: nil) ⇒ Baker
Returns a new instance of Baker.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/linecook-gem/baker.rb', line 14 def initialize(image, directory: nil) @directory = File.(directory || Dir.pwd) @image = image Dir.chdir(@directory) do @config = load_config(@directory) munge_config @driver = driver end end |
Instance Method Details
#bake(snapshot: nil, upload: nil, keep: nil) ⇒ Object
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 |
# File 'lib/linecook-gem/baker.rb', line 25 def bake(snapshot: nil, upload: nil, keep: nil) FileUtils.mkdir_p(File.join(Dir.pwd, '.kitchen')) Dir.chdir(@directory) { @driver.converge } snapshot ||= upload if snapshot puts 'Convergence complete, generating snapshot' save @image.upload if upload end rescue => e if e.cause puts "Original cause of exception:" puts e.cause. puts e.cause.backtrace end puts e. puts e.backtrace raise ensure if keep puts "Preserving build #{@image.id}, you will need to clean it up manually." else puts "Cleaning up build #{@image.id}" @driver.destroy end end |
#clean_kitchen ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/linecook-gem/baker.rb', line 57 def clean_kitchen Dir.chdir(@directory) do @config.instances.each do |instance| instance.destroy end end end |
#save ⇒ Object
65 66 67 68 69 |
# File 'lib/linecook-gem/baker.rb', line 65 def save puts "Saving image to #{@image.path}..." clean @driver.save end |