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
- #start(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
101 102 103 104 105 106 107 |
# File 'lib/construi/image.rb', line 101 def self.build(build) Console.progress "Building image: '#{build}'..." wrap Docker::Image.build_from_dir(build, rm: 0) { |s| Console.output build, JSON.parse(s)['stream'] } end |
.create(image) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/construi/image.rb', line 83 def self.create(image) Console.progress "Creating image: '#{image}'..." wrap Docker::Image.create('fromImage' => image) { |s| status = JSON.parse(s) id = status['id'] progress = status['progressDetail'] if progress.nil? || progress.empty? msg = '' msg << "#{id}: " unless id.nil? msg << status['status'] Console.output image, msg end } end |
.from(config) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/construi/image.rb', line 74 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
109 110 111 |
# File 'lib/construi/image.rb', line 109 def self.wrap(image) new image end |
Instance Method Details
#==(other) ⇒ Object
70 71 72 |
# File 'lib/construi/image.rb', line 70 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
66 67 68 |
# File 'lib/construi/image.rb', line 66 def run(cmd, = {}) Container.run self, .merge(cmd: cmd) end |
#start(options = {}) ⇒ Object
62 63 64 |
# File 'lib/construi/image.rb', line 62 def start( = {}) Container.create(self, ).tap(&:start) end |
#tagged? ⇒ Boolean
27 28 29 |
# File 'lib/construi/image.rb', line 27 def tagged? @image.info['RepoTags'] != '<none>:<none>' end |