Skip to content

Commit

Permalink
archive endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Sep 26, 2015
1 parent da233b2 commit deab4d2
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 6 deletions.
88 changes: 86 additions & 2 deletions lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ var Container = function(modem, id) {
exec: {},
rename: {},
log: {},
stats: {}
stats: {},
getArchive: {},
infoArchive: {},
putArchive: {}
};
};

Expand Down Expand Up @@ -453,7 +456,7 @@ Container.prototype.remove = function(opts, callback) {
};

/**
* Copy
* Copy (WARNING: DEPRECATED)
* @param {Object} opts Copy options, like 'Resource' (optional)
* @param {Function} callback Callback with stream.
*/
Expand All @@ -477,6 +480,87 @@ Container.prototype.copy = function(opts, callback) {
});
};

/**
* getArchive
* @param {Object} opts Archive options, like 'path'
* @param {Function} callback Callback with stream.
*/
Container.prototype.getArchive = function(opts, callback) {
var args = util.processArgs(opts, callback, this.defaultOptions.getArchive);

var optsf = {
path: '/containers/' + this.id + '/archive?',
method: 'GET',
isStream: true,
statusCodes: {
200: true,
400: 'client error, bad parameters',
404: 'no such container',
500: 'server error'
},
options: args.opts
};

this.modem.dial(optsf, function(err, data) {
args.callback(err, data);
});
};

/**
* infoArchive
* @param {Object} opts Archive options, like 'path'
* @param {Function} callback Callback with stream.
*/
Container.prototype.infoArchive = function(opts, callback) {
var args = util.processArgs(opts, callback, this.defaultOptions.infoArchive);

var optsf = {
path: '/containers/' + this.id + '/archive?',
method: 'HEAD',
isStream: true,
statusCodes: {
200: true,
400: 'client error, bad parameters',
404: 'no such container',
500: 'server error'
},
options: args.opts
};

this.modem.dial(optsf, function(err, data) {
args.callback(err, data);
});
};

/**
* putArchive
* @param {Object} opts Archive options, like 'path'
* @param {Function} callback Callback with stream.
*/
Container.prototype.putArchive = function(file, opts, callback) {
var args = util.processArgs(opts, callback, this.defaultOptions.putArchive);

var optsf = {
path: '/containers/' + this.id + '/archive?',
method: 'PUT',
file: file,
isStream: true,
statusCodes: {
200: true,
400: 'client error, bad parameters',
403: 'client error, permission denied',
404: 'no such container',
500: 'server error'
},
options: args.opts
};

this.modem.dial(optsf, function(err, data) {
args.callback(err, data);
});
};


/**
* Container logs
* @param {Object} opts Logs options. (optional)
Expand Down
52 changes: 49 additions & 3 deletions test/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,50 @@ describe("#container", function() {
});
});

describe("#archive", function() {
it("should get an archive inside the container", function(done) {
var container = docker.getContainer(testContainer);

function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
done();
}

container.getArchive({
'path': '/var/log/dmesg'
}, handler);
});

it("should put an archive inside the container", function(done) {
var container = docker.getContainer(testContainer);

function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
done();
}

container.putArchive('./test/test.tar', {
'path': '/root'
}, handler);
});

it("should inspect an archive inside the container", function(done) {
var container = docker.getContainer(testContainer);

function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
done();
}

container.infoArchive({
'path': '/root/Dockerfile'
}, handler);
});
});

describe("#start", function() {
it("should start a container", function(done) {
this.timeout(60000);
Expand Down Expand Up @@ -198,7 +242,7 @@ describe("#container", function() {
container.wait(function(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
expect(parseInt(output.replace(/\D/g,''))).to.equal(size);
expect(parseInt(output.replace(/\D/g, ''))).to.equal(size);
done();
});
});
Expand Down Expand Up @@ -463,7 +507,9 @@ describe("#container", function() {
done();
}

container.commit({comment: 'dockerode commit test'}, handler);
container.commit({
comment: 'dockerode commit test'
}, handler);
});
});

Expand Down Expand Up @@ -534,4 +580,4 @@ describe("#non-responsive container", function() {
});
});

});
});
2 changes: 1 addition & 1 deletion test/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ describe("#docker", function() {
}

function onProgress(event) {
stream.destroy();
expect(event).to.be.ok;
done();
stream.destroy();
}
});
});
Expand Down

0 comments on commit deab4d2

Please sign in to comment.