Class: Sle2Docker::RootFSImage
- Inherits:
-
Image
- Object
- Image
- Sle2Docker::RootFSImage
show all
- Defined in:
- lib/sle2docker/rootfs_image.rb
Overview
This class takes care of handling the pre-build images for SUSE Linux Enterprise
Constant Summary
collapse
- IMAGES_DIR =
'/usr/share/suse-docker-images'.freeze
- DOCKERFILE_TEMPLATE =
File.join(
File.expand_path('../../templates/docker_build', __FILE__),
'dockerfile.erb'
)
Instance Attribute Summary
Attributes inherited from Image
#image_id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Image
#activated?, #check_image_exists, #rpm_package_name, #verify_image
Constructor Details
#initialize(image_name, options) ⇒ RootFSImage
Returns a new instance of RootFSImage.
21
22
23
24
25
|
# File 'lib/sle2docker/rootfs_image.rb', line 21
def initialize(image_name, options)
@image_name = image_name
@options = options
compute_repository_and_tag
end
|
Class Method Details
.list ⇒ Object
11
12
13
14
15
16
17
18
19
|
# 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
|
Instance Method Details
#activate ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
|
# 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) ⇒ Object
57
58
59
60
61
|
# 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) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# 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 ⇒ Object
39
40
41
42
43
44
45
|
# 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
|