Class: FPM::Fry::DockerFile::Source

Inherits:
Struct
  • Object
show all
Defined in:
lib/fpm/fry/docker_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variables, cache = Source::Null::Cache) ⇒ Source

Returns a new instance of Source.



14
15
16
17
18
19
20
21
# File 'lib/fpm/fry/docker_file.rb', line 14

def initialize(variables, cache = Source::Null::Cache)
  variables = variables.dup
  if variables[:distribution] && !variables[:flavour] && OsDb[variables[:distribution]]
    variables[:flavour] = OsDb[variables[:distribution]][:flavour]
  end
  variables.freeze
  super(variables, cache)
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache

Returns:

  • (Object)

    the current value of cache



12
13
14
# File 'lib/fpm/fry/docker_file.rb', line 12

def cache
  @cache
end

#variablesObject

Returns the value of attribute variables

Returns:

  • (Object)

    the current value of variables



12
13
14
# File 'lib/fpm/fry/docker_file.rb', line 12

def variables
  @variables
end

Instance Method Details

#dockerfileObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fpm/fry/docker_file.rb', line 23

def dockerfile
  df = []
  df << "FROM #{variables[:image]}"

  df << "RUN mkdir /tmp/build"

  cache.file_map.each do |from, to|
    df << "ADD #{map_from(from)} #{map_to(to)}"
  end

  df << ""
  return df.join("\n")
end

#map_from(dir) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/fpm/fry/docker_file.rb', line 63

def map_from(dir)
  if dir == ''
    return '.'
  else
    return dir
  end
end

#map_to(dir) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/fpm/fry/docker_file.rb', line 55

def map_to(dir)
  if ['','.'].include? dir
    return '/tmp/build'
  else
    return File.join('/tmp/build',dir)
  end
end

#self_tar_ioObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/fpm/fry/docker_file.rb', line 44

def self_tar_io
  sio = StringIO.new
  tar = Gem::Package::TarWriter.new(sio)
  tar.add_file(NAME,'0777') do |io|
    io.write(dockerfile)
  end
  #tar.close
  sio.rewind
  return sio
end

#tar_ioObject



37
38
39
40
41
42
# File 'lib/fpm/fry/docker_file.rb', line 37

def tar_io
  JoinedIO.new(
    self_tar_io,
    cache.tar_io
  )
end