Class: Avmtrf1::Docker::ImageRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/avmtrf1/docker/image_runner.rb

Instance Method Summary collapse

Instance Method Details

#build_image(plataform_version) ⇒ Object


63
64
65
66
67
68
# File 'lib/avmtrf1/docker/image_runner.rb', line 63

def build_image(plataform_version)
  r = docker_image_class.new(registry, plataform_version)
  r.send('version=', !parsed.no_version?)
  r.snapshot = !parsed.no_snapshot?
  r
end

#default_versionsObject


27
28
29
30
# File 'lib/avmtrf1/docker/image_runner.rb', line 27

def default_versions
  ::EacConfig::Node.context.current.entry(default_versions_config_key).value.split(',')
                   .map(&:strip).reject(&:blank?)
end

#default_versions_config_keyObject


70
71
72
# File 'lib/avmtrf1/docker/image_runner.rb', line 70

def default_versions_config_key
  "#{plataform_name.underscore}.default_versions"
end

#docker_image_classObject


74
75
76
# File 'lib/avmtrf1/docker/image_runner.rb', line 74

def docker_image_class
  "Avmtrf1::#{plataform_name}::DockerImage".constantize
end

#plataform_nameObject


78
79
80
# File 'lib/avmtrf1/docker/image_runner.rb', line 78

def plataform_name
  self.class.name.split('::')[-2]
end

#process_version(version) ⇒ Object


47
48
49
50
51
52
# File 'lib/avmtrf1/docker/image_runner.rb', line 47

def process_version(version)
  image = build_image(version)
  infom "Building Docker image \"#{image.tag}\""
  image.build
  image.push if parsed.push?
end

#registry_nameObject


54
55
56
57
# File 'lib/avmtrf1/docker/image_runner.rb', line 54

def registry_name
  parsed.registry_name || ::EacConfig::Node.context.current.entry('docker.registry.name')
                                           .value
end

#registry_uncachedObject


59
60
61
# File 'lib/avmtrf1/docker/image_runner.rb', line 59

def registry_uncached
  ::EacDocker::Registry.new(registry_name)
end

#runObject


20
21
22
23
24
25
# File 'lib/avmtrf1/docker/image_runner.rb', line 20

def run
  infov 'Versions to build', versions_to_s
  versions.each do |version|
    process_version(version)
  end
end

#versionsObject


40
41
42
43
44
45
# File 'lib/avmtrf1/docker/image_runner.rb', line 40

def versions
  (
    parsed.version +
      (parsed.default? ? default_versions : [])
  ).uniq.sort
end

#versions_to_sObject


32
33
34
35
36
37
38
# File 'lib/avmtrf1/docker/image_runner.rb', line 32

def versions_to_s
  if versions.any?
    versions.join(', ')
  else
    '-- NONE --'
  end
end