prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN 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
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `docker/api/build.py`
  Content:
  ```
  1 import logging
  2 import os
  3 import re
  4 import json
  5 
  6 from .. import constants
  7 from .. import errors
  8 from .. import auth
  9 from .. import utils
  10 
  11 
  12 log = logging.getLogger(__name__)
  13 
  14 
  15 class BuildApiMixin(object):
  16     def build(self, path=None, tag=None, quiet=False, fileobj=None,
  17               nocache=False, rm=False, stream=False, timeout=None,
  18               custom_context=False, encoding=None, pull=False,
  19               forcerm=False, dockerfile=None, container_limits=None,
  20               decode=False, buildargs=None, gzip=False):
  21         remote = context = None
  22         headers = {}
  23         container_limits = container_limits or {}
  24         if path is None and fileobj is None:
  25             raise TypeError("Either path or fileobj needs to be provided.")
  26         if gzip and encoding is not None:
  27             raise errors.DockerException(
  28                 'Can not use custom encoding if gzip is enabled'
  29             )
  30 
  31         for key in container_limits.keys():
  32             if key not in constants.CONTAINER_LIMITS_KEYS:
  33                 raise errors.DockerException(
  34                     'Invalid container_limits key {0}'.format(key)
  35                 )
  36 
  37         if custom_context:
  38             if not fileobj:
  39                 raise TypeError("You must specify fileobj with custom_context")
  40             context = fileobj
  41         elif fileobj is not None:
  42             context = utils.mkbuildcontext(fileobj)
  43         elif path.startswith(('http://', 'https://',
  44                               'git://', 'github.com/', 'git@')):
  45             remote = path
  46         elif not os.path.isdir(path):
  47             raise TypeError("You must specify a directory to build in path")
  48         else:
  49             dockerignore = os.path.join(path, '.dockerignore')
  50             exclude = None
  51             if os.path.exists(dockerignore):
  52                 with open(dockerignore, 'r') as f:
  53                     exclude = list(filter(bool, f.read().splitlines()))
  54             context = utils.tar(
  55                 path, exclude=exclude, dockerfile=dockerfile, gzip=gzip
  56             )
  57             encoding = 'gzip' if gzip else encoding
  58 
  59         if utils.compare_version('1.8', self._version) >= 0:
  60             stream = True
  61 
  62         if dockerfile and utils.compare_version('1.17', self._version) < 0:
  63             raise errors.InvalidVersion(
  64                 'dockerfile was only introduced in API version 1.17'
  65             )
  66 
  67         if utils.compare_version('1.19', self._version) < 0:
  68             pull = 1 if pull else 0
  69 
  70         u = self._url('/build')
  71         params = {
  72             't': tag,
  73             'remote': remote,
  74             'q': quiet,
  75             'nocache': nocache,
  76             'rm': rm,
  77             'forcerm': forcerm,
  78             'pull': pull,
  79             'dockerfile': dockerfile,
  80         }
  81         params.update(container_limits)
  82 
  83         if buildargs:
  84             if utils.version_gte(self._version, '1.21'):
  85                 params.update({'buildargs': json.dumps(buildargs)})
  86             else:
  87                 raise errors.InvalidVersion(
  88                     'buildargs was only introduced in API version 1.21'
  89                 )
  90 
  91         if context is not None:
  92             headers = {'Content-Type': 'application/tar'}
  93             if encoding:
  94                 headers['Content-Encoding'] = encoding
  95 
  96         if utils.compare_version('1.9', self._version) >= 0:
  97             self._set_auth_headers(headers)
  98 
  99         response = self._post(
  100             u,
  101             data=context,
  102             params=params,
  103             headers=headers,
  104             stream=stream,
  105             timeout=timeout,
  106         )
  107 
  108         if context is not None and not custom_context:
  109             context.close()
  110 
  111         if stream:
  112             return self._stream_helper(response, decode=decode)
  113         else:
  114             output = self._result(response)
  115             srch = r'Successfully built ([0-9a-f]+)'
  116             match = re.search(srch, output)
  117             if not match:
  118                 return None, output
  119             return match.group(1), output
  120 
  121     def _set_auth_headers(self, headers):
  122         log.debug('Looking for auth config')
  123 
  124         # If we don't have any auth data so far, try reloading the config
  125         # file one more time in case anything showed up in there.
  126         if not self._auth_configs:
  127             log.debug("No auth config in memory - loading from filesystem")
  128             self._auth_configs = auth.load_config()
  129 
  130         # Send the full auth configuration (if any exists), since the build
  131         # could use any (or all) of the registries.
  132         if self._auth_configs:
  133             log.debug(
  134                 'Sending auth config ({0})'.format(
  135                     ', '.join(repr(k) for k in self._auth_configs.keys())
  136                 )
  137             )
  138 
  139             if utils.compare_version('1.19', self._version) >= 0:
  140                 headers['X-Registry-Config'] = auth.encode_header(
  141                     self._auth_configs
  142                 )
  143             else:
  144                 headers['X-Registry-Config'] = auth.encode_header({
  145                     'configs': self._auth_configs
  146                 })
  147         else:
  148             log.debug('No auth config found')
  149
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: 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 @@
                 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 @@
                       '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:
  
verification_info: {"golden_diff": "diff --git a/docker/api/build.py b/docker/api/build.py\n--- a/docker/api/build.py\n+++ b/docker/api/build.py\n@@ -17,7 +17,8 @@\n               nocache=False, rm=False, stream=False, timeout=None,\n               custom_context=False, encoding=None, pull=False,\n               forcerm=False, dockerfile=None, container_limits=None,\n-              decode=False, buildargs=None, gzip=False):\n+              decode=False, buildargs=None, gzip=False, shmsize=None,\n+              labels=None):\n         remote = context = None\n         headers = {}\n         container_limits = container_limits or {}\n@@ -88,6 +89,22 @@\n                     'buildargs was only introduced in API version 1.21'\n                 )\n \n+        if shmsize:\n+            if utils.version_gte(self._version, '1.22'):\n+                params.update({'shmsize': shmsize})\n+            else:\n+                raise errors.InvalidVersion(\n+                    'shmsize was only introduced in API version 1.22'\n+                )\n+\n+        if labels:\n+            if utils.version_gte(self._version, '1.23'):\n+                params.update({'labels': json.dumps(labels)})\n+            else:\n+                raise errors.InvalidVersion(\n+                    'labels was only introduced in API version 1.23'\n+                )\n+\n         if context is not None:\n             headers = {'Content-Type': 'application/tar'}\n             if encoding:\n", "issue": "Build Image Missing Arguments\nThe build image function is missing some arguments that are present in the v1.24 api.\n- shmsize - Size of /dev/shm in bytes. The size must be greater than 0. If omitted the system uses 64MB.\n- labels \u2013 JSON map of string pairs for labels to set on the image.\n\nSee: https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/build-image-from-a-dockerfile\n\n", "before_files": [{"content": "import logging\nimport os\nimport re\nimport json\n\nfrom .. import constants\nfrom .. import errors\nfrom .. import auth\nfrom .. import utils\n\n\nlog = logging.getLogger(__name__)\n\n\nclass BuildApiMixin(object):\n    def build(self, path=None, tag=None, quiet=False, fileobj=None,\n              nocache=False, rm=False, stream=False, timeout=None,\n              custom_context=False, encoding=None, pull=False,\n              forcerm=False, dockerfile=None, container_limits=None,\n              decode=False, buildargs=None, gzip=False):\n        remote = context = None\n        headers = {}\n        container_limits = container_limits or {}\n        if path is None and fileobj is None:\n            raise TypeError(\"Either path or fileobj needs to be provided.\")\n        if gzip and encoding is not None:\n            raise errors.DockerException(\n                'Can not use custom encoding if gzip is enabled'\n            )\n\n        for key in container_limits.keys():\n            if key not in constants.CONTAINER_LIMITS_KEYS:\n                raise errors.DockerException(\n                    'Invalid container_limits key {0}'.format(key)\n                )\n\n        if custom_context:\n            if not fileobj:\n                raise TypeError(\"You must specify fileobj with custom_context\")\n            context = fileobj\n        elif fileobj is not None:\n            context = utils.mkbuildcontext(fileobj)\n        elif path.startswith(('http://', 'https://',\n                              'git://', 'github.com/', 'git@')):\n            remote = path\n        elif not os.path.isdir(path):\n            raise TypeError(\"You must specify a directory to build in path\")\n        else:\n            dockerignore = os.path.join(path, '.dockerignore')\n            exclude = None\n            if os.path.exists(dockerignore):\n                with open(dockerignore, 'r') as f:\n                    exclude = list(filter(bool, f.read().splitlines()))\n            context = utils.tar(\n                path, exclude=exclude, dockerfile=dockerfile, gzip=gzip\n            )\n            encoding = 'gzip' if gzip else encoding\n\n        if utils.compare_version('1.8', self._version) >= 0:\n            stream = True\n\n        if dockerfile and utils.compare_version('1.17', self._version) < 0:\n            raise errors.InvalidVersion(\n                'dockerfile was only introduced in API version 1.17'\n            )\n\n        if utils.compare_version('1.19', self._version) < 0:\n            pull = 1 if pull else 0\n\n        u = self._url('/build')\n        params = {\n            't': tag,\n            'remote': remote,\n            'q': quiet,\n            'nocache': nocache,\n            'rm': rm,\n            'forcerm': forcerm,\n            'pull': pull,\n            'dockerfile': dockerfile,\n        }\n        params.update(container_limits)\n\n        if buildargs:\n            if utils.version_gte(self._version, '1.21'):\n                params.update({'buildargs': json.dumps(buildargs)})\n            else:\n                raise errors.InvalidVersion(\n                    'buildargs was only introduced in API version 1.21'\n                )\n\n        if context is not None:\n            headers = {'Content-Type': 'application/tar'}\n            if encoding:\n                headers['Content-Encoding'] = encoding\n\n        if utils.compare_version('1.9', self._version) >= 0:\n            self._set_auth_headers(headers)\n\n        response = self._post(\n            u,\n            data=context,\n            params=params,\n            headers=headers,\n            stream=stream,\n            timeout=timeout,\n        )\n\n        if context is not None and not custom_context:\n            context.close()\n\n        if stream:\n            return self._stream_helper(response, decode=decode)\n        else:\n            output = self._result(response)\n            srch = r'Successfully built ([0-9a-f]+)'\n            match = re.search(srch, output)\n            if not match:\n                return None, output\n            return match.group(1), output\n\n    def _set_auth_headers(self, headers):\n        log.debug('Looking for auth config')\n\n        # If we don't have any auth data so far, try reloading the config\n        # file one more time in case anything showed up in there.\n        if not self._auth_configs:\n            log.debug(\"No auth config in memory - loading from filesystem\")\n            self._auth_configs = auth.load_config()\n\n        # Send the full auth configuration (if any exists), since the build\n        # could use any (or all) of the registries.\n        if self._auth_configs:\n            log.debug(\n                'Sending auth config ({0})'.format(\n                    ', '.join(repr(k) for k in self._auth_configs.keys())\n                )\n            )\n\n            if utils.compare_version('1.19', self._version) >= 0:\n                headers['X-Registry-Config'] = auth.encode_header(\n                    self._auth_configs\n                )\n            else:\n                headers['X-Registry-Config'] = auth.encode_header({\n                    'configs': self._auth_configs\n                })\n        else:\n            log.debug('No auth config found')\n", "path": "docker/api/build.py"}], "after_files": [{"content": "import logging\nimport os\nimport re\nimport json\n\nfrom .. import constants\nfrom .. import errors\nfrom .. import auth\nfrom .. import utils\n\n\nlog = logging.getLogger(__name__)\n\n\nclass BuildApiMixin(object):\n    def build(self, path=None, tag=None, quiet=False, fileobj=None,\n              nocache=False, rm=False, stream=False, timeout=None,\n              custom_context=False, encoding=None, pull=False,\n              forcerm=False, dockerfile=None, container_limits=None,\n              decode=False, buildargs=None, gzip=False, shmsize=None,\n              labels=None):\n        remote = context = None\n        headers = {}\n        container_limits = container_limits or {}\n        if path is None and fileobj is None:\n            raise TypeError(\"Either path or fileobj needs to be provided.\")\n        if gzip and encoding is not None:\n            raise errors.DockerException(\n                'Can not use custom encoding if gzip is enabled'\n            )\n\n        for key in container_limits.keys():\n            if key not in constants.CONTAINER_LIMITS_KEYS:\n                raise errors.DockerException(\n                    'Invalid container_limits key {0}'.format(key)\n                )\n\n        if custom_context:\n            if not fileobj:\n                raise TypeError(\"You must specify fileobj with custom_context\")\n            context = fileobj\n        elif fileobj is not None:\n            context = utils.mkbuildcontext(fileobj)\n        elif path.startswith(('http://', 'https://',\n                              'git://', 'github.com/', 'git@')):\n            remote = path\n        elif not os.path.isdir(path):\n            raise TypeError(\"You must specify a directory to build in path\")\n        else:\n            dockerignore = os.path.join(path, '.dockerignore')\n            exclude = None\n            if os.path.exists(dockerignore):\n                with open(dockerignore, 'r') as f:\n                    exclude = list(filter(bool, f.read().splitlines()))\n            context = utils.tar(\n                path, exclude=exclude, dockerfile=dockerfile, gzip=gzip\n            )\n            encoding = 'gzip' if gzip else encoding\n\n        if utils.compare_version('1.8', self._version) >= 0:\n            stream = True\n\n        if dockerfile and utils.compare_version('1.17', self._version) < 0:\n            raise errors.InvalidVersion(\n                'dockerfile was only introduced in API version 1.17'\n            )\n\n        if utils.compare_version('1.19', self._version) < 0:\n            pull = 1 if pull else 0\n\n        u = self._url('/build')\n        params = {\n            't': tag,\n            'remote': remote,\n            'q': quiet,\n            'nocache': nocache,\n            'rm': rm,\n            'forcerm': forcerm,\n            'pull': pull,\n            'dockerfile': dockerfile,\n        }\n        params.update(container_limits)\n\n        if buildargs:\n            if utils.version_gte(self._version, '1.21'):\n                params.update({'buildargs': json.dumps(buildargs)})\n            else:\n                raise errors.InvalidVersion(\n                    'buildargs was only introduced in API version 1.21'\n                )\n\n        if shmsize:\n            if utils.version_gte(self._version, '1.22'):\n                params.update({'shmsize': shmsize})\n            else:\n                raise errors.InvalidVersion(\n                    'shmsize was only introduced in API version 1.22'\n                )\n\n        if labels:\n            if utils.version_gte(self._version, '1.23'):\n                params.update({'labels': json.dumps(labels)})\n            else:\n                raise errors.InvalidVersion(\n                    'labels was only introduced in API version 1.23'\n                )\n\n        if context is not None:\n            headers = {'Content-Type': 'application/tar'}\n            if encoding:\n                headers['Content-Encoding'] = encoding\n\n        if utils.compare_version('1.9', self._version) >= 0:\n            self._set_auth_headers(headers)\n\n        response = self._post(\n            u,\n            data=context,\n            params=params,\n            headers=headers,\n            stream=stream,\n            timeout=timeout,\n        )\n\n        if context is not None and not custom_context:\n            context.close()\n\n        if stream:\n            return self._stream_helper(response, decode=decode)\n        else:\n            output = self._result(response)\n            srch = r'Successfully built ([0-9a-f]+)'\n            match = re.search(srch, output)\n            if not match:\n                return None, output\n            return match.group(1), output\n\n    def _set_auth_headers(self, headers):\n        log.debug('Looking for auth config')\n\n        # If we don't have any auth data so far, try reloading the config\n        # file one more time in case anything showed up in there.\n        if not self._auth_configs:\n            log.debug(\"No auth config in memory - loading from filesystem\")\n            self._auth_configs = auth.load_config()\n\n        # Send the full auth configuration (if any exists), since the build\n        # could use any (or all) of the registries.\n        if self._auth_configs:\n            log.debug(\n                'Sending auth config ({0})'.format(\n                    ', '.join(repr(k) for k in self._auth_configs.keys())\n                )\n            )\n\n            if utils.compare_version('1.19', self._version) >= 0:\n                headers['X-Registry-Config'] = auth.encode_header(\n                    self._auth_configs\n                )\n            else:\n                headers['X-Registry-Config'] = auth.encode_header({\n                    'configs': self._auth_configs\n                })\n        else:\n            log.debug('No auth config found')\n", "path": "docker/api/build.py"}]}