Class: FPM::Fry::DockerFile::Build
- Inherits:
-
Struct
- Object
- Struct
- FPM::Fry::DockerFile::Build
- Defined in:
- lib/fpm/fry/docker_file.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#recipe ⇒ Object
Returns the value of attribute recipe.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
- #build_sh ⇒ Object
- #dockerfile ⇒ Object
-
#initialize(base, variables, recipe, options = {}) ⇒ Build
constructor
A new instance of Build.
- #tar_io ⇒ Object
Constructor Details
#initialize(base, variables, recipe, options = {}) ⇒ Build
Returns a new instance of Build.
78 79 80 81 82 83 84 85 86 |
# File 'lib/fpm/fry/docker_file.rb', line 78 def initialize(base, variables, recipe, = {}) variables = variables.dup if variables[:distribution] && !variables[:flavour] && OsDb[variables[:distribution]] variables[:flavour] = OsDb[variables[:distribution]][:flavour] end variables.freeze = .dup.freeze super(base, variables, recipe) end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base
73 74 75 |
# File 'lib/fpm/fry/docker_file.rb', line 73 def base @base end |
#recipe ⇒ Object
Returns the value of attribute recipe
73 74 75 |
# File 'lib/fpm/fry/docker_file.rb', line 73 def recipe @recipe end |
#variables ⇒ Object
Returns the value of attribute variables
73 74 75 |
# File 'lib/fpm/fry/docker_file.rb', line 73 def variables @variables end |
Instance Method Details
#build_sh ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/fpm/fry/docker_file.rb', line 118 def build_sh df = ['#!/bin/bash'] df << 'set -e' recipe.steps.each do |v| if v.respond_to? :name df << "echo -e '\\e[1;32m====> #{Shellwords.escape v.name}\\e[0m'" end df << v.to_s end df << '' return df.join("\n") end |
#dockerfile ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fpm/fry/docker_file.rb', line 88 def dockerfile df = [] df << "FROM #{base}" df << "WORKDIR /tmp/build" if build_dependencies.any? case(variables[:flavour]) when 'debian' update = '' if [:update] update = 'apt-get update && ' end df << "RUN #{update}apt-get install --yes #{Shellwords.join(build_dependencies)}" when 'redhat' df << "RUN yum -y install #{Shellwords.join(build_dependencies)}" else raise "Unknown flavour: #{variables[:flavour]}" end end recipe.before_build_steps.each do |step| df << "RUN #{step.to_s}" end df << "ADD .build.sh /tmp/build/" df << "ENTRYPOINT /tmp/build/.build.sh" df << '' return df.join("\n") end |
#tar_io ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/fpm/fry/docker_file.rb', line 131 def tar_io sio = StringIO.new tar = Gem::Package::TarWriter.new(sio) tar.add_file('.build.sh','0777') do |io| io.write(build_sh) end tar.add_file(NAME,'0777') do |io| io.write(dockerfile) end #tar.close sio.rewind return sio end |