code: def build(client, repository_tag, docker_file, tag=None, use_cache=False):
          if not isinstance(client, docker.Client):
              raise TypeError("client needs to be of type docker.Client.")
          if not isinstance(docker_file, six.string_types) or not os.path.exists(docker_file):
              raise Exception("docker file path doesn't exist: {0}".format(docker_file))
          if not isinstance(repository_tag, six.string_types):
              raise TypeError('repository must be a string')
          if not tag:
              tag = 'latest'
          if not isinstance(use_cache, bool):
              raise TypeError("use_cache must be a bool. {0} was passed.".format(use_cache))
          no_cache = not use_cache
          if ':' not in repository_tag:
              repository_tag = "{0}:{1}".format(repository_tag, tag)
          file_obj = None
          try:
              if os.path.isfile(docker_file):
                  path = os.getcwd()
                  docker_file = "./{0}".format(os.path.relpath(docker_file))
                  response = client.build(
                      path=path,
                      nocache=no_cache,
                      dockerfile=docker_file,
                      tag=repository_tag,
                      rm=True,
                      stream=True
                  )
              else:
                  response = client.build(path=docker_file, tag=repository_tag, rm=True, nocache=no_cache, stream=True)
          except Exception as e:
              raise e
          finally:
              if file_obj:
                  file_obj.close()
          parse_stream(response)
          client.close()
          return Image(client, repository_tag)