Class: Construi::Image
- Inherits:
-
Object
- Object
- Construi::Image
- Defined in:
- lib/construi/image.rb
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #chmod(file, permissions) ⇒ Object
- #delete ⇒ Object
- #docker_image ⇒ Object
- #id ⇒ Object
-
#initialize(image) ⇒ Image
constructor
A new instance of Image.
- #insert_local(file) ⇒ Object
- #insert_locals(files) ⇒ Object
- #run(cmd, env = []) ⇒ 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
92 93 94 95 96 97 98 |
# File 'lib/construi/image.rb', line 92 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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/construi/image.rb', line 76 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? or progress.empty? print "#{id}: " unless id.nil? puts "#{status['status']}" end } end |
.from(config) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/construi/image.rb', line 67 def self.from(config) image = create(config.image) unless config.image.nil? image = build(config.build) unless config.build.nil? raise Error, "Invalid image configuration: #{config}" unless image image.insert_locals config.files end |
.wrap(image) ⇒ Object
100 101 102 |
# File 'lib/construi/image.rb', line 100 def self.wrap(image) new image end |
Instance Method Details
#==(other) ⇒ Object
63 64 65 |
# File 'lib/construi/image.rb', line 63 def ==(other) other.is_a? Image and id == other.id end |
#chmod(file, permissions) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/construi/image.rb', line 52 def chmod(file, ) chmod = "chmod -R #{permissions} #{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) ⇒ 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) ⇒ Object
48 49 50 |
# File 'lib/construi/image.rb', line 48 def insert_locals(files) IntermediateImage.seed(self).reduce(files) { |i, f| i.insert_local f }.image end |
#run(cmd, env = []) ⇒ Object
59 60 61 |
# File 'lib/construi/image.rb', line 59 def run(cmd, env = []) Container.run(self, cmd, env) end |
#tagged? ⇒ Boolean
27 28 29 |
# File 'lib/construi/image.rb', line 27 def tagged? @image.info['RepoTags'] != '<none>:<none>' end |