Repository: docker/docker-py

Issue:
Build Image Missing Arguments
The build image function is missing some arguments that are present in the v1.24 api.
- shmsize - Size of /dev/shm in bytes. The size must be greater than 0. If omitted the system uses 64MB.
- labels – JSON map of string pairs for labels to set on the image.

See: https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/build-image-from-a-dockerfile



Discussion:

Resolving patch:
diff --git a/docker/api/build.py b/docker/api/build.py
--- a/docker/api/build.py
+++ b/docker/api/build.py
@@ -17,7 +17,8 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
               nocache=False, rm=False, stream=False, timeout=None,
               custom_context=False, encoding=None, pull=False,
               forcerm=False, dockerfile=None, container_limits=None,
-              decode=False, buildargs=None, gzip=False):
+              decode=False, buildargs=None, gzip=False, shmsize=None,
+              labels=None):
         remote = context = None
         headers = {}
         container_limits = container_limits or {}
@@ -88,6 +89,22 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
                     'buildargs was only introduced in API version 1.21'
                 )
 
+        if shmsize:
+            if utils.version_gte(self._version, '1.22'):
+                params.update({'shmsize': shmsize})
+            else:
+                raise errors.InvalidVersion(
+                    'shmsize was only introduced in API version 1.22'
+                )
+
+        if labels:
+            if utils.version_gte(self._version, '1.23'):
+                params.update({'labels': json.dumps(labels)})
+            else:
+                raise errors.InvalidVersion(
+                    'labels was only introduced in API version 1.23'
+                )
+
         if context is not None:
             headers = {'Content-Type': 'application/tar'}
             if encoding:


Test patch:
diff --git a/tests/integration/build_test.py b/tests/integration/build_test.py
--- a/tests/integration/build_test.py
+++ b/tests/integration/build_test.py
@@ -118,6 +118,44 @@ def test_build_with_buildargs(self):
         info = self.client.inspect_image('buildargs')
         self.assertEqual(info['Config']['User'], 'OK')
 
+    @requires_api_version('1.22')
+    def test_build_shmsize(self):
+        script = io.BytesIO('\n'.join([
+            'FROM scratch',
+            'CMD sh -c "echo \'Hello, World!\'"',
+        ]).encode('ascii'))
+
+        tag = 'shmsize'
+        shmsize = 134217728
+
+        stream = self.client.build(
+            fileobj=script, tag=tag, shmsize=shmsize
+        )
+        self.tmp_imgs.append(tag)
+        for chunk in stream:
+            pass
+
+        # There is currently no way to get the shmsize
+        # that was used to build the image
+
+    @requires_api_version('1.23')
+    def test_build_labels(self):
+        script = io.BytesIO('\n'.join([
+            'FROM scratch',
+        ]).encode('ascii'))
+
+        labels = {'test': 'OK'}
+
+        stream = self.client.build(
+            fileobj=script, tag='labels', labels=labels
+        )
+        self.tmp_imgs.append('labels')
+        for chunk in stream:
+            pass
+
+        info = self.client.inspect_image('labels')
+        self.assertEqual(info['Config']['Labels'], labels)
+
     def test_build_stderr_data(self):
         control_chars = ['\x1b[91m', '\x1b[0m']
         snippet = 'Ancient Temple (Mystic Oriental Dream ~ Ancient Temple)'