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.
@@ -1,3 +1,14 @@
1
+ - commits:
2
+ - subject: Convert to Javascript
3
+ hash: 9600706c47334a800636a97dc5e367e57f46d637
4
+ body: ""
5
+ footer:
6
+ Change-type: major
7
+ change-type: major
8
+ author: Akis Kesoglou
9
+ version: 3.0.0
10
+ title: ""
11
+ date: 2023-06-06T16:35:43.491Z
1
12
  - commits:
2
13
  - subject: Use Flowzone
3
14
  hash: 304293989d99a867a67a7167300ee36e318dbb03
@@ -8,7 +19,7 @@
8
19
  author: Akis Kesoglou
9
20
  version: 2.2.12
10
21
  title: ""
11
- date: 2023-06-06T14:05:16.070Z
22
+ date: 2023-06-06T15:03:34.741Z
12
23
  - commits:
13
24
  - subject: Add .versionbot/CHANGELOG.yml for nested changelogs
14
25
  hash: b0f552f9a21d350cb9fdca77d4f7c309f88bf68b
package/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file
4
4
  automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
5
5
  This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ # v3.0.0
8
+ ## (2023-06-06)
9
+
10
+ * Convert to Javascript [Akis Kesoglou]
11
+
7
12
  # v2.2.12
8
13
  ## (2023-06-06)
9
14
 
package/Dockerfile.test CHANGED
@@ -12,4 +12,3 @@ COPY package.json /usr/src/app/
12
12
  RUN npm install --unsafe-perm && npm cache clean --force
13
13
 
14
14
  COPY . /usr/src/app/
15
- RUN npm run build
package/lib/btrfs.js CHANGED
@@ -1,15 +1,11 @@
1
- // Generated by CoffeeScript 1.12.7
2
- (function() {
3
- var spawn;
1
+ 'use strict';
4
2
 
5
- spawn = require('./utils').spawn;
3
+ const { spawn } = require('./utils');
6
4
 
7
- exports.deleteSubvolAsync = function(subvol) {
8
- return spawn('btrfs', ['subvolume', 'delete', subvol]).waitAsync();
9
- };
5
+ exports.deleteSubvolAsync = function (subvol) {
6
+ return spawn('btrfs', ['subvolume', 'delete', subvol]).waitAsync();
7
+ };
10
8
 
11
- exports.snapshotSubvolAsync = function(src, dest) {
12
- return spawn('btrfs', ['subvolume', 'snapshot', src, dest]).waitAsync();
13
- };
14
-
15
- }).call(this);
9
+ exports.snapshotSubvolAsync = function (src, dest) {
10
+ return spawn('btrfs', ['subvolume', 'snapshot', src, dest]).waitAsync();
11
+ };
@@ -1,255 +1,306 @@
1
- // Generated by CoffeeScript 1.12.7
2
- (function() {
3
- var DELTA_OUT_OF_SYNC_CODES, Docker, OutOfSyncError, Promise, RSYNC_EXIT_TIMEOUT, TypedError, applyBatch, btrfs, bufIndexOfByte, docker, hardlinkCopy, nullDisposer, parseDeltaStream, path, rsync, spawn, stream,
4
- extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5
- hasProp = {}.hasOwnProperty,
6
- indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
7
-
8
- path = require('path');
9
-
10
- Promise = require('bluebird');
11
-
12
- stream = require('readable-stream');
13
-
14
- TypedError = require('typed-error');
15
-
16
- rsync = require('./rsync');
17
-
18
- btrfs = require('./btrfs');
19
-
20
- spawn = require('./utils').spawn;
21
-
22
- Docker = require('docker-toolbelt');
23
-
24
- docker = new Docker();
25
-
26
- DELTA_OUT_OF_SYNC_CODES = [19, 23, 24];
27
-
28
- RSYNC_EXIT_TIMEOUT = 10 * 60 * 1000;
29
-
30
- exports.OutOfSyncError = OutOfSyncError = (function(superClass) {
31
- extend(OutOfSyncError, superClass);
32
-
33
- function OutOfSyncError() {
34
- return OutOfSyncError.__super__.constructor.apply(this, arguments);
35
- }
36
-
37
- return OutOfSyncError;
38
-
39
- })(TypedError);
40
-
41
- exports.createDelta = function(srcImage, destImage, v2, arg) {
42
- var config, deltaStream, ioTimeout, log, ref, ref1, rootDirDisposers, rootDirFunc;
43
- if (v2 == null) {
44
- v2 = true;
45
- }
46
- ref = arg != null ? arg : {}, log = ref.log, ioTimeout = (ref1 = ref.ioTimeout) != null ? ref1 : 0;
47
- if (log == null) {
48
- log = function() {};
49
- }
50
- deltaStream = new stream.PassThrough();
51
- config = docker.getImage(destImage).inspect().get('Config');
52
- rootDirFunc = docker.imageRootDirMounted.bind(docker);
53
- rootDirDisposers = [srcImage, destImage].map(rootDirFunc);
54
- Promise.using(rootDirDisposers, function(rootDirs) {
55
- var destDir, ref2, rsyncPromise, srcDir;
56
- ref2 = rootDirs.map(function(rootDir) {
57
- return path.join(rootDir, path.sep);
58
- }), srcDir = ref2[0], destDir = ref2[1];
59
- rsyncPromise = rsync.createRsyncStream(srcDir, destDir, ioTimeout, log);
60
- return Promise.join(config, rsyncPromise, function(config, arg1) {
61
- var metadata, rsyncExit, rsyncStream;
62
- rsyncExit = arg1[0], rsyncStream = arg1[1];
63
- if (v2) {
64
- metadata = {
65
- version: 2,
66
- dockerConfig: config
67
- };
68
- deltaStream.write(JSON.stringify(metadata));
69
- deltaStream.write(new Buffer([0x00]));
70
- }
71
- return new Promise(function(resolve, reject) {
72
- return rsyncStream.on('error', reject).on('close', resolve).pipe(deltaStream);
73
- })["finally"](function() {
74
- return rsyncExit.waitAsync();
75
- });
76
- });
77
- })["catch"](function(e) {
78
- return deltaStream.emit('error', e);
79
- })["finally"](function() {
80
- log('rsync exited');
81
- return deltaStream.emit('close');
82
- });
83
- return deltaStream;
84
- };
85
-
86
- bufIndexOfByte = function(buf, byte) {
87
- var b, i, j, len;
88
- for (i = j = 0, len = buf.length; j < len; i = ++j) {
89
- b = buf[i];
90
- if (b === byte) {
91
- return i;
92
- }
93
- }
94
- return -1;
95
- };
96
-
97
- parseDeltaStream = function(input) {
98
- return new Promise(function(resolve, reject) {
99
- var buf, parser;
100
- buf = new Buffer(0);
101
- parser = function() {
102
- var chunk, chunks, e, metadata, sep;
103
- chunks = [buf];
104
- while (chunk = input.read()) {
105
- chunks.push(chunk);
106
- }
107
- buf = Buffer.concat(chunks);
108
- sep = bufIndexOfByte(buf, 0x00);
109
- if (sep !== -1) {
110
- input.removeListener('readable', parser);
111
- input.unshift(buf.slice(sep + 1));
112
- try {
113
- metadata = JSON.parse(buf.slice(0, sep));
114
- } catch (error) {
115
- e = error;
116
- return reject(e);
117
- }
118
- if (metadata.version === 2) {
119
- return resolve(metadata);
120
- } else {
121
- return reject(new Error('Uknown version: ' + metadata.version));
122
- }
123
- }
124
- };
125
- return input.on('readable', parser);
126
- });
127
- };
128
-
129
- nullDisposer = function() {
130
- return Promise.resolve(null);
131
- };
132
-
133
- hardlinkCopy = function(srcRoot, dstRoot, linkDests) {
134
- var dest, j, len, rsyncArgs;
135
- rsyncArgs = ['--archive', '--delete'];
136
- for (j = 0, len = linkDests.length; j < len; j++) {
137
- dest = linkDests[j];
138
- rsyncArgs.push('--link-dest', dest);
139
- }
140
- rsyncArgs.push(srcRoot, dstRoot);
141
- rsync = spawn('rsync', rsyncArgs);
142
- return rsync.waitAsync();
143
- };
144
-
145
- applyBatch = function(rsync, batch, timeout, log) {
146
- var p;
147
- p = new Promise(function(resolve, reject) {
148
- return batch.on('error', reject).on('finish', function() {
149
- rsync.stdin.end();
150
- return resolve();
151
- }).pipe(rsync.stdin).on('error', reject).on('finish', resolve);
152
- });
153
- if (timeout !== 0) {
154
- p = p.timeout(timeout);
155
- }
156
- return p.then(function() {
157
- log('Batch input stream ended; waiting for rsync...');
158
- return rsync.waitAsync().timeout(RSYNC_EXIT_TIMEOUT).tap(function() {
159
- return log('rsync exited cleanly');
160
- }).tapCatch(function(err) {
161
- return log("Error waiting for rsync to exit: " + err);
162
- });
163
- })["catch"](function(err) {
164
- log("Killing rsync with force due to error: " + err);
165
- rsync.kill('SIGUSR1');
166
- log('Waiting for rsync to exit...');
167
- return rsync.waitAsync()["throw"](err);
168
- });
169
- };
170
-
171
- exports.applyDelta = function(srcImage, arg) {
172
- var deltaStream, dstIdPromise, log, ref, ref1, rootDirFunc, timeout;
173
- ref = arg != null ? arg : {}, timeout = (ref1 = ref.timeout) != null ? ref1 : 0, log = ref.log;
174
- if (log == null) {
175
- log = function() {};
176
- }
177
- deltaStream = new stream.PassThrough();
178
- rootDirFunc = nullDisposer;
179
- if (srcImage != null) {
180
- rootDirFunc = docker.imageRootDirMounted.bind(docker);
181
- }
182
- dstIdPromise = parseDeltaStream(deltaStream).get('dockerConfig').tap(function() {
183
- return log('Extracted image config');
184
- }).bind(docker).then(docker.createEmptyImage).tap(function(id) {
185
- return log("Created empty image " + id);
186
- });
187
- Promise.using(rootDirFunc(srcImage), function(srcRoot) {
188
- if (srcRoot != null) {
189
- srcRoot = path.join(srcRoot, '/');
190
- }
191
- return Promise.join(docker.info().get('Driver'), dstIdPromise, dstIdPromise.then(docker.imageRootDir), function(dockerDriver, dstId, dstRoot) {
192
- dstRoot = path.join(dstRoot, '/');
193
- return Promise["try"](function() {
194
- switch (dockerDriver) {
195
- case 'btrfs':
196
- if (srcRoot != null) {
197
- return btrfs.deleteSubvolAsync(dstRoot).then(function() {
198
- return btrfs.snapshotSubvolAsync(srcRoot, dstRoot);
199
- });
200
- }
201
- break;
202
- case 'overlay':
203
- if (srcRoot != null) {
204
- return hardlinkCopy(srcRoot, dstRoot, [srcRoot]);
205
- }
206
- break;
207
- case 'aufs':
208
- case 'overlay2':
209
- if (srcRoot != null) {
210
- return docker.diffPaths(srcImage).then(function(diffPaths) {
211
- return hardlinkCopy(srcRoot, dstRoot, diffPaths);
212
- });
213
- }
214
- break;
215
- default:
216
- throw new Error("Unsupported driver " + dockerDriver);
217
- }
218
- }).then(function() {
219
- var opts, rsyncArgs;
220
- log("Hard-linked files from '" + srcRoot + "' to '" + dstRoot + "'");
221
- rsyncArgs = ['--archive', '--delete', '--read-batch', '-', dstRoot];
222
- opts = {
223
- stdio: ['pipe', 'ignore', 'ignore']
224
- };
225
- log("Spawning rsync with arguments " + (rsyncArgs.join(' ')));
226
- rsync = spawn('rsync', rsyncArgs, opts);
227
- return applyBatch(rsync, deltaStream, timeout, log).tap(function() {
228
- return log('rsync exited successfully');
229
- });
230
- }).then(function() {
231
- log('fsync\'ing...');
232
- return spawn('sync').waitAsync();
233
- }).then(function() {
234
- log("All done. Image ID: " + dstId);
235
- return deltaStream.emit('id', dstId);
236
- });
237
- });
238
- })["catch"](function(e) {
239
- var ref2;
240
- log("Error: " + e);
241
- if (ref2 = e != null ? e.code : void 0, indexOf.call(DELTA_OUT_OF_SYNC_CODES, ref2) >= 0) {
242
- deltaStream.emit('error', new OutOfSyncError('Incompatible image'));
243
- } else {
244
- deltaStream.emit('error', e);
245
- }
246
- return dstIdPromise.then(function(dstId) {
247
- return docker.getImage(dstId).remove()["catch"](function(e) {
248
- return deltaStream.emit('error', e);
249
- });
250
- });
251
- });
252
- return deltaStream;
253
- };
254
-
255
- }).call(this);
1
+ 'use strict';
2
+
3
+ // FIXME: For some reason lint complains each of the following lines shadow a variable.
4
+ // tslint:disable:no-shadowed-variable
5
+ const path = require('path');
6
+ const Bluebird = require('bluebird');
7
+ const stream = require('readable-stream');
8
+ const TypedError = require('typed-error');
9
+ const rsync = require('./rsync');
10
+ const btrfs = require('./btrfs');
11
+ const { spawn } = require('./utils');
12
+ const Docker = require('docker-toolbelt');
13
+
14
+ const docker = new Docker();
15
+
16
+ const DELTA_OUT_OF_SYNC_CODES = [19, 23, 24];
17
+
18
+ const RSYNC_EXIT_TIMEOUT = 10 * 60 * 1000;
19
+
20
+ class OutOfSyncError extends TypedError {
21
+ // noop
22
+ }
23
+ // tslint:enable:no-shadowed-variable
24
+
25
+ exports.createDelta = function (srcImage, destImage, v2, opts) {
26
+ if (v2 == null) {
27
+ v2 = true;
28
+ }
29
+ if (opts == null) {
30
+ opts = {};
31
+ }
32
+ var { log, ioTimeout } = opts;
33
+ if (log == null) {
34
+ log = function () {
35
+ // noop
36
+ };
37
+ }
38
+ if (ioTimeout == null) {
39
+ ioTimeout = 0;
40
+ }
41
+
42
+ const deltaStream = new stream.PassThrough();
43
+ const config = docker.getImage(destImage).inspect().get('Config');
44
+ const rootDirFunc = docker.imageRootDirMounted.bind(docker);
45
+ const rootDirDisposers = [srcImage, destImage].map(rootDirFunc);
46
+
47
+ Bluebird.using(rootDirDisposers, function (rootDirs) {
48
+ const [srcDir, destDir] = rootDirs.map(function (rootDir) {
49
+ return path.join(rootDir, path.sep);
50
+ });
51
+ const rsyncPromise = rsync.createRsyncStream(
52
+ srcDir,
53
+ destDir,
54
+ ioTimeout,
55
+ log,
56
+ );
57
+ return Bluebird.join(
58
+ config,
59
+ rsyncPromise,
60
+ function (dockerConfig, rsyncResult) {
61
+ const [rsyncExit, rsyncStream] = rsyncResult;
62
+ if (v2) {
63
+ const metadata = {
64
+ version: 2,
65
+ dockerConfig,
66
+ };
67
+ deltaStream.write(JSON.stringify(metadata));
68
+ deltaStream.write(new Buffer([0x00]));
69
+ }
70
+ return new Bluebird(function (resolve, reject) {
71
+ return rsyncStream
72
+ .on('error', reject)
73
+ .on('close', resolve)
74
+ .pipe(deltaStream);
75
+ }).finally(function () {
76
+ return rsyncExit.waitAsync();
77
+ });
78
+ },
79
+ );
80
+ })
81
+ .catch(function (e) {
82
+ deltaStream.emit('error', e);
83
+ })
84
+ .finally(function () {
85
+ log('rsync exited');
86
+ deltaStream.emit('close');
87
+ });
88
+
89
+ return deltaStream;
90
+ };
91
+
92
+ function bufIndexOfByte(buf, byte) {
93
+ for (var i = 0, len = buf.length; i < len; i++) {
94
+ if (buf[i] === byte) {
95
+ return i;
96
+ }
97
+ }
98
+ return -1;
99
+ }
100
+
101
+ function parseDeltaStream(input) {
102
+ return new Bluebird(function (resolve, reject) {
103
+ var buf = new Buffer(0);
104
+ const parser = function () {
105
+ const chunks = [buf];
106
+
107
+ while (true) {
108
+ const chunk = input.read();
109
+ if (chunk != null) {
110
+ chunks.push(chunk);
111
+ } else {
112
+ break;
113
+ }
114
+ }
115
+
116
+ buf = Buffer.concat(chunks);
117
+
118
+ const sep = bufIndexOfByte(buf, 0x00);
119
+ if (sep !== -1) {
120
+ input.removeListener('readable', parser);
121
+ input.unshift(buf.slice(sep + 1));
122
+
123
+ try {
124
+ const metadata = JSON.parse(buf.slice(0, sep));
125
+ if (metadata.version === 2) {
126
+ return resolve(metadata);
127
+ } else {
128
+ return reject(new Error('Uknown version: ' + metadata.version));
129
+ }
130
+ } catch (error) {
131
+ return reject(error);
132
+ }
133
+ }
134
+ };
135
+
136
+ return input.on('readable', parser);
137
+ });
138
+ }
139
+
140
+ function nullDisposer() {
141
+ return Bluebird.resolve(null);
142
+ }
143
+
144
+ function hardlinkCopy(srcRoot, dstRoot, linkDests) {
145
+ const rsyncArgs = ['--archive', '--delete'];
146
+
147
+ for (var j = 0, len = linkDests.length; j < len; j++) {
148
+ const dest = linkDests[j];
149
+ rsyncArgs.push('--link-dest', dest);
150
+ }
151
+ rsyncArgs.push(srcRoot, dstRoot);
152
+
153
+ return spawn('rsync', rsyncArgs).waitAsync();
154
+ }
155
+
156
+ function applyBatch(rsyncProcess, batch, timeout, log) {
157
+ var p = new Bluebird(function (resolve, reject) {
158
+ return batch
159
+ .on('error', reject)
160
+ .on('finish', function () {
161
+ rsyncProcess.stdin.end();
162
+ return resolve();
163
+ })
164
+ .pipe(rsyncProcess.stdin)
165
+ .on('error', reject)
166
+ .on('finish', resolve);
167
+ });
168
+
169
+ if (timeout !== 0) {
170
+ p = p.timeout(timeout);
171
+ }
172
+
173
+ return p
174
+ .then(function () {
175
+ log('Batch input stream ended; waiting for rsync...');
176
+ return rsyncProcess
177
+ .waitAsync()
178
+ .timeout(RSYNC_EXIT_TIMEOUT)
179
+ .tap(function () {
180
+ return log('rsync exited cleanly');
181
+ })
182
+ .tapCatch(function (err) {
183
+ return log('Error waiting for rsync to exit: ' + err);
184
+ });
185
+ })
186
+ .catch(function (err) {
187
+ log('Killing rsync with force due to error: ' + err);
188
+ rsyncProcess.kill('SIGUSR1');
189
+ log('Waiting for rsync to exit...');
190
+ return rsyncProcess.waitAsync().throw(err);
191
+ });
192
+ }
193
+
194
+ exports.applyDelta = function (srcImage, opts) {
195
+ if (opts == null) {
196
+ opts = {};
197
+ }
198
+ var { log, timeout } = opts;
199
+ if (log == null) {
200
+ log = function () {
201
+ // noop
202
+ };
203
+ }
204
+ if (timeout == null) {
205
+ timeout = 0;
206
+ }
207
+
208
+ const deltaStream = new stream.PassThrough();
209
+ const rootDirFunc =
210
+ srcImage != null ? docker.imageRootDirMounted.bind(docker) : nullDisposer;
211
+
212
+ const dstIdPromise = parseDeltaStream(deltaStream)
213
+ .get('dockerConfig')
214
+ .tap(function () {
215
+ return log('Extracted image config');
216
+ })
217
+ .bind(docker)
218
+ .then(docker.createEmptyImage)
219
+ .tap(function (id) {
220
+ return log('Created empty image ' + id);
221
+ });
222
+
223
+ Bluebird.using(rootDirFunc(srcImage), function (srcRoot) {
224
+ if (srcRoot != null) {
225
+ srcRoot = path.join(srcRoot, '/');
226
+ }
227
+
228
+ return Bluebird.join(
229
+ docker.info().get('Driver'),
230
+ dstIdPromise,
231
+ dstIdPromise.then(docker.imageRootDir),
232
+ function (dockerDriver, dstId, dstRoot) {
233
+ dstRoot = path.join(dstRoot, '/');
234
+ return Bluebird.try(function () {
235
+ switch (dockerDriver) {
236
+ case 'btrfs':
237
+ if (srcRoot != null) {
238
+ return btrfs.deleteSubvolAsync(dstRoot).then(function () {
239
+ return btrfs.snapshotSubvolAsync(srcRoot, dstRoot);
240
+ });
241
+ }
242
+ break;
243
+ case 'overlay':
244
+ if (srcRoot != null) {
245
+ return hardlinkCopy(srcRoot, dstRoot, [srcRoot]);
246
+ }
247
+ break;
248
+ case 'aufs':
249
+ case 'overlay2':
250
+ if (srcRoot != null) {
251
+ return docker.diffPaths(srcImage).then(function (diffPaths) {
252
+ return hardlinkCopy(srcRoot, dstRoot, diffPaths);
253
+ });
254
+ }
255
+ break;
256
+ default:
257
+ throw new Error('Unsupported driver ' + dockerDriver);
258
+ }
259
+ })
260
+ .then(function () {
261
+ log(
262
+ "Hard-linked files from '" + srcRoot + "' to '" + dstRoot + "'",
263
+ );
264
+ const rsyncArgs = [
265
+ '--archive',
266
+ '--delete',
267
+ '--read-batch',
268
+ '-',
269
+ dstRoot,
270
+ ];
271
+ log('Spawning rsync with arguments ' + rsyncArgs.join(' '));
272
+ const ps = spawn('rsync', rsyncArgs, {
273
+ stdio: ['pipe', 'ignore', 'ignore'],
274
+ });
275
+ return applyBatch(ps, deltaStream, timeout, log).tap(function () {
276
+ return log('rsync exited successfully');
277
+ });
278
+ })
279
+ .then(function () {
280
+ log("fsync'ing...");
281
+ return spawn('sync').waitAsync();
282
+ })
283
+ .then(function () {
284
+ log('All done. Image ID: ' + dstId);
285
+ return deltaStream.emit('id', dstId);
286
+ });
287
+ },
288
+ );
289
+ }).catch(function (e) {
290
+ log('Error: ' + e);
291
+ if (e.code != null && DELTA_OUT_OF_SYNC_CODES.indexOf(e.code) >= 0) {
292
+ deltaStream.emit('error', new OutOfSyncError('Incompatible image'));
293
+ } else {
294
+ deltaStream.emit('error', e);
295
+ }
296
+ return dstIdPromise.then(function (dstId) {
297
+ return docker
298
+ .getImage(dstId)
299
+ .remove()
300
+ .catch(function (e2) {
301
+ return deltaStream.emit('error', e2);
302
+ });
303
+ });
304
+ });
305
+ return deltaStream;
306
+ };