Class: Construi::Image
- Inherits:
-
Object
- Object
- Construi::Image
- Defined in:
- lib/construi/image.rb
Overview
A Docker Image
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #chmod(file, permissions, options = {}) ⇒ Object
- #delete ⇒ Object
- #docker_image ⇒ Object
- #id ⇒ Object
-
#initialize(image) ⇒ Image
constructor
A new instance of Image.
- #insert_local(file, options = {}) ⇒ Object
- #insert_locals(files, options = {}) ⇒ Object
- #run(cmd, options = {}) ⇒ Object
- #tagged? ⇒ Boolean
Constructor Details
#initialize(image) ⇒ Image
Returns a new instance of Image.
11 12 13 |
# File 'lib/construi/image.rb', line 11 def initialize(image) @image = image.refresh! end |
Class Method Details
.build(build) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/construi/image.rb', line 95 def self.build(build) puts puts "Building image: '#{build}'...".green wrap Docker::Image.build_from_dir(build, rm: 0) { |s| puts JSON.parse(s)['stream'] } end |
.create(image) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/construi/image.rb', line 79 def self.create(image) puts puts "Creating image: '#{image}'...".green wrap Docker::Image.create('fromImage' => image) { |s| status = JSON.parse(s) id = status['id'] progress = status['progressDetail'] if progress.nil? || progress.empty? print "#{id}: " unless id.nil? puts "#{status['status']}" end } end |
.from(config) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/construi/image.rb', line 70 def self.from(config) image = create(config.image) unless config.image.nil? image = build(config.build) unless config.build.nil? fail Error, "Invalid image configuration: #{config}" unless image image.insert_locals config.files, privileged: config.privileged? end |
.wrap(image) ⇒ Object
103 104 105 |
# File 'lib/construi/image.rb', line 103 def self.wrap(image) new image end |
Instance Method Details
#==(other) ⇒ Object
66 67 68 |
# File 'lib/construi/image.rb', line 66 def ==(other) other.is_a?(Image) && id == other.id end |
#chmod(file, permissions, options = {}) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/construi/image.rb', line 55 def chmod(file, , = {}) chmod = "chmod -R #{} #{file}" puts " > #{chmod}" run chmod, end |
#delete ⇒ Object
19 20 21 |
# File 'lib/construi/image.rb', line 19 def delete @image.delete end |
#docker_image ⇒ Object
23 24 25 |
# File 'lib/construi/image.rb', line 23 def docker_image @image end |
#id ⇒ Object
15 16 17 |
# File 'lib/construi/image.rb', line 15 def id @image.id end |
#insert_local(file, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/construi/image.rb', line 31 def insert_local(file, = {}) puts "\nCopying #{file.host} to #{file.container}...".green img = IntermediateImage.seed(self) img.map do |i| Image.wrap i.docker_image .insert_local 'localPath' => file.host, 'outputPath' => file.container end img.map { |i| i.chmod file.container, file., } if file. img.run "ls -l #{file.container}", img.image end |
#insert_locals(files, options = {}) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/construi/image.rb', line 48 def insert_locals(files, = {}) IntermediateImage .seed(self) .reduce(files) { |a, e| a.insert_local e, } .image end |
#run(cmd, options = {}) ⇒ Object
62 63 64 |
# File 'lib/construi/image.rb', line 62 def run(cmd, = {}) Container.run self, cmd, end |
#tagged? ⇒ Boolean
27 28 29 |
# File 'lib/construi/image.rb', line 27 def tagged? @image.info['RepoTags'] != '<none>:<none>' end |