Repository: apocas/dockerode

Issue:
The `cachefrom` option in `Docker.buildImage` is not JSON serialized
A recent change in https://github.com/apocas/docker-modem/pull/181/ defaults to query string serialization of array options passed to `Modem.dial`. 

While this change goes in the right direction as using query string arrays seems to be the approach used for many of the routes in the [Docker API](https://docs.docker.com/reference/api/engine/version/v1.48), there are a few exceptions, one of which is the `cachefrom` option in [ImageBuild](https://docs.docker.com/reference/api/engine/version/v1.48/#tag/Image/operation/ImageBuild), which expects "JSON array of images used for build cache resolution.". 

The update of `docker-modem` to 5.0.6 caused a breaking change in the `buildImage` operation, as providing a `cachefrom` array argument now will result in the following error 

```
Error: (HTTP code 400) unexpected - error reading cache-from: invalid character 'a' looking for beginning of value
``` 

Discussion:

Solution patch:
diff --git a/lib/docker.js b/lib/docker.js
index 502513a..e3739dd 100644
--- a/lib/docker.js
+++ b/lib/docker.js
@@ -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) {



Test patch:
diff --git a/test/docker.js b/test/docker.js
index 3308037..b7f3921 100644
--- a/test/docker.js
+++ b/test/docker.js
@@ -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', 'cachefrom': ['ubuntu:latest'] }, handler);
+    });
+
     it("should build image from multiple files while respecting the .dockerignore file", function(done) {
       this.timeout(60000);