Skip to content

Commit

Permalink
Use JSON serialization for cachefrom option
Browse files Browse the repository at this point in the history
Docker [ImageBuild](https://docs.docker.com/reference/api/engine/version/v1.48/#tag/Image/operation/ImageBuild) endpoint requires
that the `cachefrom` option is a "JSON serialized array". This
requirement seems to be an exception to the way arrays are consumed by
the API (usually querystring serialized).

This change is needed after apocas/docker-modem#181 that makes querystring serialized arrays the default.

This commit adds an exception for this option on `Docker.buildImage`.

Change-type: patch
  • Loading branch information
pipex committed Feb 24, 2025
1 parent 6ec9f25 commit b9b66ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ Docker.prototype.buildImage = function(file, opts, callback) {
optsf.authconfig = optsf.options.authconfig;
delete optsf.options.authconfig;
}

if (opts.cachefrom && Array.isArray(opts.cachefrom)) {
optsf.options.cachefrom = JSON.stringify(opts.cachefrom);
}
}

function dial(callback) {
Expand Down
22 changes: 22 additions & 0 deletions test/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,28 @@ describe("#docker", function() {
}, { t: 'multiple-files' }, handler);
});

it("should build image from multiple files using cache", function(done) {
this.timeout(60000);

function handler(err, stream) {
expect(err).to.be.null;
expect(stream).to.be.ok;

stream.pipe(process.stdout, {
end: true
});

stream.on('end', function() {
done();
});
}

docker.buildImage({
context: __dirname,
src: ['Dockerfile']
}, { t: 'multiple-files', 'cachefrom': ['ubuntu:latest'] }, handler);
});

it("should build image from multiple files while respecting the .dockerignore file", function(done) {
this.timeout(60000);

Expand Down

0 comments on commit b9b66ef

Please sign in to comment.