Class: Argus::Image
- Inherits:
-
Object
- Object
- Argus::Image
- Defined in:
- lib/argus/docker.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#build_time ⇒ Object
readonly
Returns the value of attribute build_time.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#push_time ⇒ Object
readonly
Returns the value of attribute push_time.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
-
#build!(options = {}) ⇒ Object
build docker image, with optional API /build params.
-
#initialize(name) ⇒ Image
constructor
A new instance of Image.
-
#is_ok? ⇒ Boolean
check if image built ok.
-
#pull ⇒ Object
make a heroic attempt to pre-load as many layers as we can.
-
#push(sha) ⇒ Object
push image and all tags to registry.
-
#tag!(sha) ⇒ Object
tag with both sha and branch.
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Image
Returns a new instance of Image.
8 9 10 |
# File 'lib/argus/docker.rb', line 8 def initialize(name) @repo, @branch = name.split(':') end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
6 7 8 |
# File 'lib/argus/docker.rb', line 6 def branch @branch end |
#build_time ⇒ Object (readonly)
Returns the value of attribute build_time.
6 7 8 |
# File 'lib/argus/docker.rb', line 6 def build_time @build_time end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
6 7 8 |
# File 'lib/argus/docker.rb', line 6 def image @image end |
#push_time ⇒ Object (readonly)
Returns the value of attribute push_time.
6 7 8 |
# File 'lib/argus/docker.rb', line 6 def push_time @push_time end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
6 7 8 |
# File 'lib/argus/docker.rb', line 6 def repo @repo end |
Instance Method Details
#build!(options = {}) ⇒ Object
build docker image, with optional API /build params
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/argus/docker.rb', line 32 def build!( = {}) puts "building #{self}" @build_time = Benchmark.realtime do @image = Docker::Image.build_from_dir('.', ) do |chunk| chunk.split(/[\r\n]+/).each do |line| # latest docker jams multiple streams into chunk begin stream = JSON.parse(line)['stream'] unless (stream.nil? || stream.match(/^[\s\.]+$/)) # very verbose about build progress puts stream.chomp end rescue => e # be robust to json parse errors puts e. end end end end end |
#is_ok? ⇒ Boolean
check if image built ok
52 53 54 |
# File 'lib/argus/docker.rb', line 52 def is_ok? image.is_a?(Docker::Image) end |
#pull ⇒ Object
make a heroic attempt to pre-load as many layers as we can
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/argus/docker.rb', line 17 def pull [branch, :master, :latest].each do |tag| puts "Attempting to pull #{repo}:#{tag}" begin attempt = Docker::Image.create(fromImage: "#{repo}:#{tag}") rescue Docker::Error::ArgumentError puts "failed pull" rescue Docker::Error::NotFoundError puts "image not found" end break if attempt.is_a?(Docker::Image) end end |
#push(sha) ⇒ Object
push image and all tags to registry
65 66 67 68 69 70 71 72 |
# File 'lib/argus/docker.rb', line 65 def push(sha) @push_time = Benchmark.realtime do [sha, branch].each do |tag| puts "pushing #{repo}:#{tag}" image.push(nil, tag: tag) end end end |
#tag!(sha) ⇒ Object
tag with both sha and branch
57 58 59 60 61 62 |
# File 'lib/argus/docker.rb', line 57 def tag!(sha) [sha, branch].map do |tag| puts "tagging #{repo}:#{tag}" image.tag(repo: repo, tag: tag, force: true) end end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/argus/docker.rb', line 12 def to_s "#{repo}:#{branch}" end |