Class: Sle2Docker::Image

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

Overview

This class is the base class of native and prebulid images for SUSE Linux Enterprise

Direct Known Subclasses

NativeImage, RootFSImage

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#image_idObject (readonly)

Returns the value of attribute image_id.



5
6
7
# File 'lib/sle2docker/image.rb', line 5

def image_id
  @image_id
end

Instance Method Details

#activated?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/sle2docker/image.rb', line 7

def activated?
  Docker::Image.exist?(image_id)
end

#check_image_existsObject

Raises:



36
37
38
39
40
41
# File 'lib/sle2docker/image.rb', line 36

def check_image_exists
  msg = "Cannot find pre-built image #{@image_name}"
  raise(ImageNotFoundError, msg) unless File.exist? File.join(
    self.class::IMAGES_DIR, "#{@image_name}.tar.xz"
  )
end

#rpm_package_nameObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sle2docker/image.rb', line 24

def rpm_package_name
  image_file = File.join(self.class::IMAGES_DIR, "#{@image_name}.tar.xz")
  package_name = `rpm -qf #{image_file}`
  if $CHILD_STATUS.exitstatus.nonzero?
    raise(
      ImageVerificationError,
      "Cannot find rpm package providing #{file}: #{package_name}"
    )
  end
  package_name
end

#verify_imageObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sle2docker/image.rb', line 11

def verify_image
  check_image_exists

  puts 'Verifying integrity of the pre-built image'
  package_name = rpm_package_name
  verification = `rpm --verify #{package_name}`
  if $CHILD_STATUS.exitstatus.nonzero?
    raise(ImageVerificationError,
          "Verification of #{package_name} failed: #{verification}")
  end
  true
end