Class: Dockdev::DockdevConfig
- Inherits:
-
Object
- Object
- Dockdev::DockdevConfig
- Includes:
- TR::CondUtils
- Defined in:
- lib/dockdev/dockdev_config.rb
Overview
Managing the config
Constant Summary collapse
- DOCDEV_CONFIG_FILE =
"dockdev-config"
Class Method Summary collapse
Instance Method Summary collapse
-
#build_image(image, dockerfile_path, opts = { root: Dir.getwd }, &block) ⇒ Object
Build the docker image by embedding additional entries into the Dockerfile.
-
#initialize(conf = nil) ⇒ DockdevConfig
constructor
A new instance of DockdevConfig.
- #save(root = Dir.getwd) ⇒ Object
Constructor Details
#initialize(conf = nil) ⇒ DockdevConfig
Returns a new instance of DockdevConfig.
207 208 209 210 211 212 213 214 |
# File 'lib/dockdev/dockdev_config.rb', line 207 def initialize(conf = nil) logger.debug "Given to initialize : #{conf}" if not_empty?(conf) @config = parse(conf) else @config = Config.new end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mtd, *args, &block) ⇒ Object (private)
289 290 291 292 |
# File 'lib/dockdev/dockdev_config.rb', line 289 def method_missing(mtd, *args, &block) logger.debug "method_missing '#{mtd}' / #{args}" @config.send(mtd, *args, &block) end |
Class Method Details
.load(root = Dir.getwd, &block) ⇒ Object
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/dockdev/dockdev_config.rb', line 196 def self.load(root = Dir.getwd, &block) confFile = Dir.glob(File.join(root,"#{DOCDEV_CONFIG_FILE}.*")).grep(/.yml|.yaml$/) if confFile.length > 1 block.call(:found_more, contFile) elsif confFile.length == 0 block.call(:not_found) else block.call(:found, confFile.first) end end |
Instance Method Details
#build_image(image, dockerfile_path, opts = { root: Dir.getwd }, &block) ⇒ Object
Build the docker image by embedding additional entries into the Dockerfile.
This likely will need a temporary file to be created and it should be managed by
this operation.
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/dockdev/dockdev_config.rb', line 232 def build_image(image, dockerfile_path, opts = { root: Dir.getwd }, &block) if has_additional_entries? logger.debug "dockdev_config has additional entry for Dockerfile. Merging additional entries into Dockerfile" root = opts[:root] || Dir.getwd # make it static name so: # 1. No file removal is required # 2. Allow debug on generated Dockerfile # 3. Replace Dockerfile on each run and only single Dockerfile is left on system # 4. Allow this temporary to be added to .gitignore tmpFile = File.join(root, "#{File.basename(dockerfile_path)}-dockdev") File.open(tmpFile,"w") do |f| found = false File.open(dockerfile_path,"r").each_line do |line| # detecting the CMD line if there is any if line =~ /^CMD/ found = true # here we append the lines dockerfile_entries.each do |al| f.puts al end f.write line else f.write line end end if not found @dockerfile_entries.each do |al| f.puts al end end end image.build(tmpFile) else logger.debug "dockdev_config has no additional entry for Dockerfile. Proceed to build found Dockerfile" image.build(dockerfile_path) end end |
#save(root = Dir.getwd) ⇒ Object
217 218 219 220 221 222 223 |
# File 'lib/dockdev/dockdev_config.rb', line 217 def save(root = Dir.getwd) path = File.join(root,"#{DOCDEV_CONFIG_FILE}.yml") File.open(path,"w") do |f| f.write YAML.dump(@config.to_storage) end path end |