class Argus::Image

Attributes

branch[R]
build_time[R]
image[R]
push_time[R]
repo[R]

Public Class Methods

new(name) click to toggle source
# File lib/argus/docker.rb, line 8
def initialize(name)
  @repo, @branch = name.split(':')
end

Public Instance Methods

build!(options = {}) click to toggle source

build docker image, with optional API /build params

# File lib/argus/docker.rb, line 32
def build!(options = {})
  puts "building #{self}"

  @build_time = Benchmark.realtime do
    @image = Docker::Image.build_from_dir('.', options) 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.message
        end
      end
    end
  end
end
is_ok?() click to toggle source

check if image built ok

# File lib/argus/docker.rb, line 52
def is_ok?
  image.is_a?(Docker::Image)
end
pull() click to toggle source

make a heroic attempt to pre-load as many layers as we can

# 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) click to toggle source

push image and all tags to registry

# 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) click to toggle source

tag with both sha and branch

# 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() click to toggle source
# File lib/argus/docker.rb, line 12
def to_s
  "#{repo}:#{branch}"
end