class Sle2Docker::RootFSImage

This class takes care of handling the pre-build images for SUSE Linux Enterprise

Constants

DOCKERFILE_TEMPLATE
IMAGES_DIR

Public Class Methods

list() click to toggle source
# File lib/sle2docker/rootfs_image.rb, line 11
def self.list
  if File.exist?(RootFSImage::IMAGES_DIR)
    Dir[File.join(RootFSImage::IMAGES_DIR, '*.tar.xz')].map do |image|
      File.basename(image, '.tar.xz')
    end
  else
    []
  end
end
new(image_name, options) click to toggle source
# File lib/sle2docker/rootfs_image.rb, line 21
def initialize(image_name, options)
  @image_name = image_name
  @options    = options
  compute_repository_and_tag
end

Public Instance Methods

activate() click to toggle source
# File lib/sle2docker/rootfs_image.rb, line 27
def activate
  verify_image

  tmp_dir = prepare_docker_build_root
  puts 'Activating image'
  image = Docker::Image.build_from_dir(tmp_dir)
  image.tag('repo' => @repository, 'tag' => @tag)
  image.tag('repo' => @repository, 'tag' => 'latest')
ensure
  FileUtils.rm_rf(tmp_dir) if tmp_dir && File.exist?(tmp_dir)
end
copy_prebuilt_image(tmp_dir) click to toggle source
# File lib/sle2docker/rootfs_image.rb, line 57
def copy_prebuilt_image(tmp_dir)
  prebuilt_image = File.join(IMAGES_DIR, "#{@image_name}.tar.xz")
  destination = File.join(tmp_dir, "#{@image_name}.tar.xz")
  FileUtils.cp(prebuilt_image, destination)
end
create_dockerfile(tmp_dir) click to toggle source
# File lib/sle2docker/rootfs_image.rb, line 47
def create_dockerfile(tmp_dir)
  prebuilt_image = @image_name + '.tar.xz'
  template = ERB.new(File.read(DOCKERFILE_TEMPLATE), nil, '<>')
                .result(binding)

  File.open(File.join(tmp_dir, 'Dockerfile'), 'w') do |file|
    file.write(template)
  end
end
prepare_docker_build_root() click to toggle source
# File lib/sle2docker/rootfs_image.rb, line 39
def prepare_docker_build_root
  tmp_dir = Dir.mktmpdir("sle2docker-#{@image_name}-dockerfile")

  create_dockerfile(tmp_dir)
  copy_prebuilt_image(tmp_dir)
  tmp_dir
end

Private Instance Methods

compute_repository_and_tag() click to toggle source
# File lib/sle2docker/rootfs_image.rb, line 65
def compute_repository_and_tag
  # example of image name:
  # kiwi < 8.0 :
  #      sles12-docker.x86_64-1.0.0-Build7.2
  # kiwi >= 8.0
  #      obs-source-service.x86_64-1.0.0-Build3.1.docker
  regexp = /\A(?<name>.*)(-docker)?\..*-(?<version>\d+\.\d+\.\d+)
   (-Build(?<build>\d+\.\d+)?)?/x
  match = regexp.match(@image_name)
  match.nil? &&
    raise(DockerTagError,
          "Docker image #{@image_name} not found. \
           Run sle2docker list to check which docker images are available.")

  @repository = "suse/#{match['name']}"
  @tag        = match['version']
  @options['tag_with_build'] && @tag << '-' + (match['build'] || '0.0')
  @image_id = "#{@repository}:#{@tag}"
end