Skip to content

Commit

Permalink
OS-4690 #428 imgadm xz compression support for images
Browse files Browse the repository at this point in the history
  • Loading branch information
xen0l authored and trentm committed Sep 1, 2015
1 parent 0187807 commit f2cb5fe
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/img/lib/common.js
Expand Up @@ -53,7 +53,7 @@ var DEFAULT_SOURCE = {type: 'imgapi', url: 'https://images.joyent.com'};

var DB_DIR = '/var/imgadm';

var VALID_COMPRESSIONS = ['none', 'bzip2', 'gzip'];
var VALID_COMPRESSIONS = ['none', 'bzip2', 'gzip', 'xz'];

var VALID_SOURCE_TYPES = ['imgapi', 'dsapi', 'docker'];

Expand Down
7 changes: 7 additions & 0 deletions src/img/lib/imgadm.js
Expand Up @@ -2605,6 +2605,9 @@ IMGADM.prototype._installZfsImage = function _installZfsImage(ctx, cb) {
} else if (compression === 'gzip') {
uncompressor = spawn('/usr/bin/gzip', ['-cdfq']);
numToFinish++;
} else if (compression === 'xz') {
uncompressor = spawn('/usr/bin/xz', ['-cdfq']);
numToFinish++;
} else {
assert.equal(compression, 'none',
format('image %s file compression: %s', uuid, compression));
Expand Down Expand Up @@ -3808,6 +3811,10 @@ IMGADM.prototype.createImage = function createImage(options, callback) {
compressor = spawn('/usr/bin/gzip', ['-cfq']);
imageInfo.filePath += '.gz';
numToFinish++;
} else if (compression === 'xz') {
compressor = spawn('/usr/bin/xz', ['-cfq']);
imageInfo.filePath += '.xz';
numToFinish++;
} else {
finish(new errors.UsageError(format(
'unknown compression "%s"', compression)));
Expand Down
2 changes: 1 addition & 1 deletion src/img/man/imgadm.1m.md
Expand Up @@ -354,7 +354,7 @@ UUID.
then "PATH.imgmanifest" and "PATH.zfs[.EXT]" are
created.
-c <comp>, --compression=<comp>
One of "none", "gz" or "bzip2" for the compression
One of "none", "gz", "bzip2" or "xz" for the compression
to use on the image file, if any. Default is "none".
-i Build an incremental image (based on the "@final"
snapshot of the source image for the VM).
Expand Down
2 changes: 1 addition & 1 deletion src/img/node_modules/imgmanifest/lib/imgmanifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/img/node_modules/imgmanifest/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/img/package.json
Expand Up @@ -13,7 +13,7 @@
"docker-registry-client": "git://github.com/joyent/node-docker-registry-client.git#765e74c",
"extsprintf": "1.2.0",
"findit": "2.0.0",
"imgmanifest": "git://github.com/joyent/node-imgmanifest.git#91e5d80",
"imgmanifest": "git://github.com/joyent/node-imgmanifest.git#4f80d8c",
"mkdirp": "0.5.0",
"node-uuid": "1.4.1",
"once": "1.3.1",
Expand Down
37 changes: 37 additions & 0 deletions src/img/test/create.test.js
Expand Up @@ -179,3 +179,40 @@ test('custom image (incremental, compression=bzip2)', function (t) {
});
});

test('custom image (compression=xz)', function (t) {
var cmd = format('%s/mk-custom-image %s %s/4 xz >%s/mk-custom-image.4.log 2>&1',
TESTDIR, BASE_UUID, WRKDIR, WRKDIR);
exec(cmd, {env: envWithTrace}, function (err, stdout, stderr) {
t.ifError(err, format('error running "%s": %s', cmd, err));
var logfile = WRKDIR + '/try-custom-image.4.log';
var cmd = format('%s/try-custom-image %s/4.imgmanifest %s/4.zfs.xz >%s 2>&1',
TESTDIR, WRKDIR, WRKDIR, logfile);
exec(cmd, function (err) {
t.ifError(err, format('error running "%s": %s', cmd, err));
var output = fs.readFileSync(logfile, 'utf8');
t.ok(output.indexOf('hi from mk-custom-image') !== -1,
format('could not find expected marker in output:\n--\n%s\n--\n',
output));
t.end();
});
});
});

test('custom image (incremental, compression=xz)', function (t) {
var cmd = format('%s/mk-custom-image %s %s/4i xz -i >%s/mk-custom-image.4i.log 2>&1',
TESTDIR, BASE_UUID, WRKDIR, WRKDIR);
exec(cmd, {env: envWithTrace}, function (err, stdout, stderr) {
t.ifError(err, format('error running "%s": %s', cmd, err));
var logfile = WRKDIR + '/try-custom-image.4i.log';
var cmd = format('%s/try-custom-image %s/4i.imgmanifest %s/4i.zfs.xz >%s 2>&1',
TESTDIR, WRKDIR, WRKDIR, logfile);
exec(cmd, function (err) {
t.ifError(err, format('error running "%s": %s', cmd, err));
var output = fs.readFileSync(logfile, 'utf8');
t.ok(output.indexOf('hi from mk-custom-image') !== -1,
format('could not find expected marker in output:\n--\n%s\n--\n',
output));
t.end();
});
});
});

0 comments on commit f2cb5fe

Please sign in to comment.