def generate_build(self, image, targetname, rebuilds=None, cache_repo='<STR_LIT>', cache_tag='<STR_LIT>',<EOL>buildargs=None, **kwargs):
from_image = self.get_external_base_image(image)<EOL>if cache_repo or cache_tag:<EOL><INDENT>cache_from = utils.generate_name(image, cache_repo, cache_tag)<EOL><DEDENT>else:<EOL><INDENT>cache_from = None<EOL><DEDENT>if from_image is None:<EOL><INDENT>raise errors.NoBaseError("<STR_LIT>" % image)<EOL><DEDENT>if isinstance(from_image, ExternalDockerfile):<EOL><INDENT>build_first = from_image<EOL>base_image = from_image.tag<EOL><DEDENT>else:<EOL><INDENT>base_image = from_image<EOL>build_first = None<EOL><DEDENT>build_steps = []<EOL>istep = <NUM_LIT:0><EOL>sourceimages = set()<EOL>if rebuilds is None:<EOL><INDENT>rebuilds = []<EOL><DEDENT>else:<EOL><INDENT>rebuilds = set(rebuilds)<EOL><DEDENT>for base_name in self.sort_dependencies(image):<EOL><INDENT>istep += <NUM_LIT:1><EOL>buildname = '<STR_LIT>' % (image, istep)<EOL>secret_files = self.ymldefs[base_name].get('<STR_LIT>', None)<EOL>squash = self.ymldefs[base_name].get('<STR_LIT>', bool(secret_files))<EOL>build_steps.append(<EOL>dockermake.step.BuildStep(<EOL>base_name,<EOL>base_image,<EOL>self.ymldefs[base_name],<EOL>buildname,<EOL>bust_cache=base_name in rebuilds,<EOL>build_first=build_first, cache_from=cache_from,<EOL>buildargs=buildargs,<EOL>squash=squash,<EOL>secret_files=secret_files))<EOL>base_image = buildname<EOL>build_first = None<EOL>for sourceimage, files in iteritems(self.ymldefs[base_name].get('<STR_LIT>', {})):<EOL><INDENT>sourceimages.add(sourceimage)<EOL>for sourcepath, destpath in iteritems(files):<EOL><INDENT>istep += <NUM_LIT:1><EOL>buildname = '<STR_LIT>' % (image, istep)<EOL>build_steps.append(<EOL>dockermake.step.FileCopyStep(<EOL>sourceimage, sourcepath, destpath,<EOL>base_name, base_image, self.ymldefs[base_name],<EOL>buildname, bust_cache=base_name in rebuilds,<EOL>build_first=build_first, cache_from=cache_from))<EOL>base_image = buildname<EOL><DEDENT><DEDENT><DEDENT>sourcebuilds = [self.generate_build(img,<EOL>img,<EOL>cache_repo=cache_repo,<EOL>cache_tag=cache_tag,<EOL>**kwargs)<EOL>for img in sourceimages]<EOL>return builds.BuildTarget(imagename=image,<EOL>targetname=targetname,<EOL>steps=build_steps,<EOL>sourcebuilds=sourcebuilds,<EOL>from_image=from_image,<EOL>**kwargs)<EOL>
Separate the build into a series of one or more intermediate steps.
Each specified build directory gets its own step

Args:
    image (str): name of the image as defined in the dockermake.py file
    targetname (str): name to tag the final built image with
    rebuilds (List[str]): list of image layers to rebuild (i.e., without docker's cache)
    cache_repo (str): repository to get images for caches in builds
    cache_tag (str): tags to use from repository for caches in builds
    buildargs (dict): build-time dockerfile arugments
    **kwargs (dict): extra keyword arguments for the BuildTarget object