Class: Wildcloud::Keeper::Deployers::Aufs

Inherits:
Object
  • Object
show all
Defined in:
lib/wildcloud/keeper/deployers/aufs.rb

Instance Method Summary collapse

Instance Method Details

#deploy(options = {}) ⇒ 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
# File 'lib/wildcloud/keeper/deployers/aufs.rb', line 25

def deploy(options = {})
  options[:base_image] ||= 'base'

  @id = options[:id]
  @appid = options[:appid]

  @temp_file    = File.join(config['paths']['tmp'],     "#{@id}.tar.gz")
  @image_path   = File.join(config['paths']['images'],  "#{@id}")
  @target_path  = File.join(config['paths']['mounts'],  "#{@id}")
  @temp_path    = File.join(config['paths']['temp'],    "#{@id}")

  FileUtils.mkdir_p(@image_path)
  FileUtils.mkdir_p(@target_path)
  FileUtils.mkdir_p(@temp_path)

  @branches = "br=#{@image_path}=rw:#{File.join(config['paths']['images'], 'base')}=ro"
  options[:root_path] = @image_path

  unless options[:build]
    run("curl -v -o #{@temp_file} -H 'X-Appid: #{config['storage']['id']}' #{config['storage']['url']}/#{@appid}.tar.gz")
    run("tar -xf #{@temp_file} -C #{@image_path}")
    @branches = "br=#{@temp_path}=rw:#{@image_path}=ro:#{File.join(config['paths']['images'], options[:base_image])}=ro"
    options[:root_path] = @temp_path
  end

  run("mount -t aufs -o #{@branches} none #{@target_path}")
end

#undeploy(options) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/wildcloud/keeper/deployers/aufs.rb', line 53

def undeploy(options)

  @id ||= options[:id]
  @appid ||= options[:appid]

  @temp_file    ||= File.join(config['paths']['tmp'],     "#{@id}.tar.gz")
  @image_path   ||= File.join(config['paths']['images'],  "#{@id}")
  @target_path  ||= File.join(config['paths']['mounts'],  "#{@id}")
  @temp_path    ||= File.join(config['paths']['temp'],    "#{@id}")

  run("umount #{@target_path}")

  if options[:persistent]
    run("tar -zcf #{@temp_file} -C #{@image_path} .")
    run("curl -v -X PUT -H 'X-Appid: #{config['storage']['id']}' -T #{@temp_file} #{config['storage']['url']}/#{@appid}.tar.gz")
  end

  FileUtils.rm_rf(@image_path)
  FileUtils.rm_rf(@target_path)
  FileUtils.rm_rf(@temp_path)

  FileUtils.rm(@temp_file)
end