Class: Longshoreman::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/longshoreman/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeImage

Returns a new instance of Image.



3
4
5
# File 'lib/longshoreman/image.rb', line 3

def initialize
  @raw = nil
end

Instance Attribute Details

#rawObject

Returns the value of attribute raw.



41
42
43
# File 'lib/longshoreman/image.rb', line 41

def raw
  @raw
end

Instance Method Details

#build(dockerfile_path) ⇒ Object

Build an image from a Dockerfile



8
9
10
11
12
# File 'lib/longshoreman/image.rb', line 8

def build(dockerfile_path)
  dockerfile = IO.read(dockerfile_path)
  @raw = Docker::Image.build(dockerfile)
  @raw # Return the image without having to add .raw
end

#exist?(id, opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/longshoreman/image.rb', line 22

def exist?(id, opts = {})
  @raw.exist?(id, opts)
end

#get(repository, tag) ⇒ Object

Return the image object identified by repository:tag



27
28
29
30
31
32
33
34
# File 'lib/longshoreman/image.rb', line 27

def get(repository, tag)
  images = Docker::Image.all.select { |i|
    i.info["RepoTags"].include? "#{repository}:#{tag}"
  }
  # I don't think it's possible to have multiple images from the same
  # repository with the same tag, so this shouldn't be an issue.
  @raw = images[0]
end

#idObject

Return the id



37
38
39
# File 'lib/longshoreman/image.rb', line 37

def id
  @raw.id
end

#removeObject Also known as: cleanup

This is useful if you’re building from Dockerfiles each run



15
16
17
18
19
# File 'lib/longshoreman/image.rb', line 15

def remove
  if @raw
    @raw.remove(:force => true) if @raw.exist?(@raw.id)
  end
end