<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_image(image_path, image_name, build_args=None, dockerfile_path=None):
 """Build an image Args: image_path (str):
 the path to the image directory image_name (str):
 image 'name:tag' to build build_args (dict, optional):
 dict of docker build arguments dockerfile_path (str, optional):
 path to dockerfile relative to image_path if not `image_path/Dockerfile`. """

    cmd = ['docker', 'build', '-t', image_name, image_path]
    if dockerfile_path:
        cmd.extend(['-f', dockerfile_path])

    for k, v in (build_args or {}).items():
        cmd += ['--build-arg', '{}={}'.format(k, v)]
    check_call(cmd)