docker-delta 2.2.12 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.versionbot/CHANGELOG.yml +12 -1
- package/CHANGELOG.md +5 -0
- package/Dockerfile.test +0 -1
- package/lib/btrfs.js +8 -12
- package/lib/docker-delta.js +306 -255
- package/lib/rsync.js +69 -54
- package/lib/utils.js +50 -55
- package/package.json +7 -11
- package/test/docker-delta.spec.js +88 -0
- package/test.sh +1 -1
- package/lib/btrfs.coffee +0 -11
- package/lib/docker-delta.coffee +0 -261
- package/lib/rsync.coffee +0 -56
- package/lib/utils.coffee +0 -43
- package/test/docker-delta.spec.coffee +0 -55
package/lib/rsync.coffee
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
Promise = require 'bluebird'
|
|
2
|
-
fs = require 'fs'
|
|
3
|
-
tmp = require 'tmp'
|
|
4
|
-
path = require 'path'
|
|
5
|
-
{ spawn, mkfifoSync } = require './utils'
|
|
6
|
-
|
|
7
|
-
exports.createRsyncStream = (src, dest, ioTimeout, log) ->
|
|
8
|
-
new Promise (resolve, reject) ->
|
|
9
|
-
tmp.dir unsafeCleanup: true, (err, tmpDirPath, cleanup) ->
|
|
10
|
-
if err
|
|
11
|
-
log('Failed to create temporary directory')
|
|
12
|
-
return reject(err)
|
|
13
|
-
|
|
14
|
-
pipePath = path.join(tmpDirPath, 'rsync.pipe')
|
|
15
|
-
|
|
16
|
-
mkfifoSync(pipePath)
|
|
17
|
-
|
|
18
|
-
# To produce the delta that takes us from `src` to `dest`
|
|
19
|
-
# we have to tell rsync to copy `dest` to `src`
|
|
20
|
-
rsyncArgs = [
|
|
21
|
-
'--archive'
|
|
22
|
-
'--compress'
|
|
23
|
-
'--checksum'
|
|
24
|
-
'--no-i-r'
|
|
25
|
-
'--delete'
|
|
26
|
-
'--hard-links'
|
|
27
|
-
|
|
28
|
-
'--timeout', ioTimeout # in seconds
|
|
29
|
-
|
|
30
|
-
'--compress-level=9'
|
|
31
|
-
'--one-file-system'
|
|
32
|
-
'--only-write-batch', pipePath
|
|
33
|
-
dest, src
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
log('Invoking rsync:', 'rsync ' + rsyncArgs.join(' '))
|
|
37
|
-
ps = spawn('rsync', rsyncArgs, stdio: 'ignore')
|
|
38
|
-
|
|
39
|
-
# Early Node 8 versions have a bug that force a seek upon creation of
|
|
40
|
-
# a read stream. The workaround is to pass the file descriptor directly.
|
|
41
|
-
# See: https://github.com/nodejs/node/issues/19240
|
|
42
|
-
fs.open pipePath, 'r', (err, fd) ->
|
|
43
|
-
if err
|
|
44
|
-
log('Failed to open pipe for reading. Killing rsync...')
|
|
45
|
-
ps.kill('SIGUSR1')
|
|
46
|
-
ps.waitAsync()
|
|
47
|
-
.tap ->
|
|
48
|
-
log('rsync exited')
|
|
49
|
-
.tapCatch (e) ->
|
|
50
|
-
log("rsync exited with error: #{e}")
|
|
51
|
-
.finally ->
|
|
52
|
-
cleanup()
|
|
53
|
-
reject(err)
|
|
54
|
-
else
|
|
55
|
-
stream = fs.createReadStream(undefined, fd: fd).on('close', cleanup)
|
|
56
|
-
resolve([ ps, stream ])
|
package/lib/utils.coffee
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{ spawn, execSync } = require 'child_process'
|
|
2
|
-
Promise = require 'bluebird'
|
|
3
|
-
|
|
4
|
-
# Similar to waitpid(), it gets an instance of ChildProcess and returns a
|
|
5
|
-
# promise that settles after the process has stopped or errored
|
|
6
|
-
waitPidAsync = (cmd, ps, status) ->
|
|
7
|
-
new Promise (resolve, reject) ->
|
|
8
|
-
handleExit = (code, signal) ->
|
|
9
|
-
if code isnt 0
|
|
10
|
-
error = new Error("#{cmd} exited. code: #{code} signal: #{signal}")
|
|
11
|
-
error.code = code
|
|
12
|
-
error.signal = signal
|
|
13
|
-
reject(error)
|
|
14
|
-
else
|
|
15
|
-
resolve()
|
|
16
|
-
if status.exited
|
|
17
|
-
handleExit(status.code, status.signal)
|
|
18
|
-
else if status.error?
|
|
19
|
-
reject(status.error)
|
|
20
|
-
else
|
|
21
|
-
ps
|
|
22
|
-
.on('error', reject)
|
|
23
|
-
.on('exit', handleExit)
|
|
24
|
-
|
|
25
|
-
exports.spawn = (cmd, args, opts) ->
|
|
26
|
-
ps = spawn(cmd, args, opts)
|
|
27
|
-
processStatus = {
|
|
28
|
-
exited: false
|
|
29
|
-
code: null
|
|
30
|
-
signal: null
|
|
31
|
-
error: null
|
|
32
|
-
}
|
|
33
|
-
ps.on('error', (e) -> processStatus.error = e)
|
|
34
|
-
ps.on 'exit', (code, signal) ->
|
|
35
|
-
processStatus.exited = true
|
|
36
|
-
processStatus.code = code
|
|
37
|
-
processStatus.signal = signal
|
|
38
|
-
ps.waitAsync = ->
|
|
39
|
-
waitPidAsync(cmd, ps, processStatus)
|
|
40
|
-
return ps
|
|
41
|
-
|
|
42
|
-
exports.mkfifoSync = (fifoPath) ->
|
|
43
|
-
execSync("mkfifo -m 0600 #{fifoPath}")
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
m = require 'mochainon'
|
|
2
|
-
m.chai.use(require('chai-events'))
|
|
3
|
-
m.chai.use(require('chai-stream'))
|
|
4
|
-
|
|
5
|
-
es = require 'event-stream'
|
|
6
|
-
JSONStream = require 'JSONStream'
|
|
7
|
-
|
|
8
|
-
Promise = require 'bluebird'
|
|
9
|
-
stream = require 'stream'
|
|
10
|
-
Docker = require 'dockerode'
|
|
11
|
-
docker = new Docker()
|
|
12
|
-
|
|
13
|
-
dockerDelta = require '../lib/docker-delta'
|
|
14
|
-
|
|
15
|
-
{ expect } = m.chai
|
|
16
|
-
|
|
17
|
-
buildImg = (name, dockerfile) ->
|
|
18
|
-
docker.buildImage({
|
|
19
|
-
context: './test',
|
|
20
|
-
src: [ dockerfile ]
|
|
21
|
-
}, { t: name, dockerfile })
|
|
22
|
-
.then (res) ->
|
|
23
|
-
new Promise (resolve, reject) ->
|
|
24
|
-
outputStream = res
|
|
25
|
-
.pipe(JSONStream.parse())
|
|
26
|
-
.pipe es.through (data) ->
|
|
27
|
-
if data.error
|
|
28
|
-
reject(data.error)
|
|
29
|
-
else
|
|
30
|
-
console.log(data)
|
|
31
|
-
.on('end', resolve)
|
|
32
|
-
.on('error', reject)
|
|
33
|
-
|
|
34
|
-
describe 'docker-delta', ->
|
|
35
|
-
@timeout(120000)
|
|
36
|
-
before ->
|
|
37
|
-
buildImg('source-image', 'Dockerfile.src')
|
|
38
|
-
.then ->
|
|
39
|
-
buildImg('dest-image', 'Dockerfile.dst')
|
|
40
|
-
|
|
41
|
-
it 'creates a delta between two images and applies it', ->
|
|
42
|
-
deltaStream = dockerDelta.createDelta('source-image', 'dest-image', true)
|
|
43
|
-
expect(deltaStream).to.be.a.Stream
|
|
44
|
-
str = deltaStream.pipe(dockerDelta.applyDelta('source-image'))
|
|
45
|
-
.on 'id', (id) =>
|
|
46
|
-
@imageId = id
|
|
47
|
-
expect(str).to.emit('id')
|
|
48
|
-
|
|
49
|
-
it 'produces a valid docker image', ->
|
|
50
|
-
expect(@imageId).to.be.a.string
|
|
51
|
-
pt = new stream.PassThrough()
|
|
52
|
-
pt.setEncoding('utf8')
|
|
53
|
-
docker.run(@imageId, undefined, pt).then (container) ->
|
|
54
|
-
expect(container.output.StatusCode).to.equal(0)
|
|
55
|
-
expect(pt.read()).to.equal("HeXXo from the image\r\n")
|