Skip to content

Commit

Permalink
Make --keep-build-tags apply globally
Browse files Browse the repository at this point in the history
  • Loading branch information
avirshup committed Nov 8, 2017
1 parent 65c6cf7 commit af4d2b5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
12 changes: 6 additions & 6 deletions dockermake/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ class BuildTarget(object):
steps (List[BuildStep]): list of steps required to build this image
stagedfiles (List[StagedFile]): list of files to stage into this image from other images
from_image (str): External base image name
keepbuildtags (bool): Keep intermediate build tags (dmkbuild_[target]_[stepnum])
"""
def __init__(self, imagename, targetname, steps, sourcebuilds, from_image):
def __init__(self, imagename, targetname, steps, sourcebuilds, from_image, keepbuildtags=False):
self.imagename = imagename
self.steps = steps
self.sourcebuilds = sourcebuilds
self.targetname = targetname
self.from_image = from_image
self.keepbuildtags = keepbuildtags

def write_dockerfile(self, output_dir):
""" Used only to write a Dockerfile that will NOT be built by docker-make
Expand All @@ -61,7 +63,6 @@ def write_dockerfile(self, output_dir):

def build(self, client,
nobuild=False,
keepbuildtags=False,
usecache=True,
pull=False):
"""
Expand All @@ -70,7 +71,6 @@ def build(self, client,
Args:
client (docker.Client): docker client object that will build the image
nobuild (bool): just create dockerfiles, don't actually build the image
keepbuildtags (bool): keep tags on intermediate images
usecache (bool): use docker cache, or rebuild everything from scratch?
pull (bool): try to pull new versions of repository images?
"""
Expand Down Expand Up @@ -111,7 +111,7 @@ def build(self, client,
finalimage = step.buildname

if not nobuild:
self.finalizenames(client, finalimage, keepbuildtags)
self.finalizenames(client, finalimage)
line = 'FINISHED BUILDING "%s" (image definition "%s" from %s)'%(
self.targetname, self.imagename, self.steps[-1].sourcefile)
cprint(_centered(line, width),
Expand Down Expand Up @@ -139,13 +139,13 @@ def update_source_images(self, client, usecache, pull):
cprint('Finished with build image "%s"\n' % build.targetname,
color='green')

def finalizenames(self, client, finalimage, keepbuildtags):
def finalizenames(self, client, finalimage):
""" Tag the built image with its final name and untag intermediate containers
"""
client.api.tag(finalimage, *self.targetname.split(':'))
cprint('Tagged final image as "%s"' % self.targetname,
'green')
if not keepbuildtags:
if not self.keepbuildtags:
print('Untagging intermediate containers:', end='')
for step in self.steps:
client.api.remove_image(step.buildname, force=True)
Expand Down
13 changes: 10 additions & 3 deletions dockermake/imagedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def _check_yaml_and_paths(ymlfilepath, yamldefs):
'Field "%s" in image "%s" in file "%s" not recognized' %
(key, imagename, relpath))

def generate_build(self, image, targetname, rebuilds=None, cache_repo='', cache_tag=''):
def generate_build(self, image, targetname, rebuilds=None, cache_repo='', cache_tag='',
**kwargs):
"""
Separate the build into a series of one or more intermediate steps.
Each specified build directory gets its own step
Expand All @@ -132,6 +133,7 @@ def generate_build(self, image, targetname, rebuilds=None, cache_repo='', cache_
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
**kwargs (dict): extra keyword arguments for the BuildTarget object
"""
from_image = self.get_external_base_image(image)
if cache_repo or cache_tag:
Expand Down Expand Up @@ -179,14 +181,19 @@ def generate_build(self, image, targetname, rebuilds=None, cache_repo='', cache_
build_first=build_first, cache_from=cache_from))
base_image = buildname

sourcebuilds = [self.generate_build(img, img, cache_repo=cache_repo, cache_tag=cache_tag)
sourcebuilds = [self.generate_build(img,
img,
cache_repo=cache_repo,
cache_tag=cache_tag,
**kwargs)
for img in sourceimages]

return builds.BuildTarget(imagename=image,
targetname=targetname,
steps=build_steps,
sourcebuilds=sourcebuilds,
from_image=from_image)
from_image=from_image,
**kwargs)

def sort_dependencies(self, image, dependencies=None):
"""
Expand Down
6 changes: 3 additions & 3 deletions dockermake/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ def build_targets(args, defs, targets):
generate_name(t, args.repository, args.tag),
rebuilds=args.bust_cache,
cache_repo=args.cache_repo,
cache_tag=args.cache_tag)
cache_tag=args.cache_tag,
keepbuildtags=args.keep_build_tags)
for t in targets]
for b in builders:
b.build(client,
nobuild=args.no_build,
usecache=not args.no_cache,
pull=args.pull,
keepbuildtags=args.keep_build_tags)
pull=args.pull)
if not args.no_build:
print(' docker-make built:', b.targetname)

Expand Down

0 comments on commit af4d2b5

Please sign in to comment.