Ubuntu Pastebin

Paste from a at Wed, 20 May 2015 12:32:38 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Flatten the image by piping a tar export into a tar import.
# Flattening essentially destroys the history of the image. By default docker
# will however stack image revisions ontop of one another. Namely if we have
# abc and create a new image edf, edf will be an AUFS ontop of abc. While this
# is probably useful if one doesn't commit containers repeatedly for us this
# is pretty crap as we have massive turn around on images.
@log.warn 'Flattening latest image by exporting and importing it.' \
          ' This can take a while.'
require 'thwait'

rd, wr = IO.pipe
@i = nil

Thread.abort_on_exception = true
read_thread = Thread.new do
  @i = Docker::Image.import_stream do
    rd.read(1000).to_s
  end
  @log.warn 'Import complete'
  rd.close
end
write_thread = Thread.new do
  c.export do |chunk|
    wr.write(chunk)
  end
  @log.warn 'Export complete'
  wr.close
end
ThreadsWait.all_waits(read_thread, write_thread)
Download as text