Skip to content

Commit

Permalink
check that image exists if we don't think it needs rebuilding (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcranston committed Sep 18, 2020
1 parent d4c01e4 commit ebc45da
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def get_previous_image_spec(chartname, image_dir):


def image_requires_build(image_dir, commit_range=None):
"""Check whether the commit range includes any changes to the image_dir."""
if commit_range is None:
return False
image_touched = subprocess.check_output([
Expand All @@ -116,6 +117,13 @@ def image_requires_build(image_dir, commit_range=None):

return image_touched

def image_exists(image_spec):
try:
docker('pull', image_spec)
return True

except subprocess.CalledProcessError:
return False

# def build_hub_image(hubname, commit_range, push=False):
# # Build and push to Docker Hub the hub(!) images that need updating
Expand Down Expand Up @@ -159,12 +167,22 @@ def build_user_image(chartname, commit_range, push=False):
# Build and push to Docker Hub singleuser images that need updating
# from `user-images/`
image_dir = "user-images/" + chartname

# get the image_spec based on the git commit that last modified image_dir
image_spec = get_next_image_spec(chartname, image_dir)
if image_spec is None:
return

needs_rebuilding = image_requires_build(image_dir, commit_range)

# if the image does not appear to need re-building, test that it
# actually exists
if not needs_rebuilding:
print("Commits do not affect {}, but checking for image".format(image_dir))
if not image_exists(image_spec):
print("Image {} does not exist; rebuilding".format(image_spec))
needs_rebuilding = True

if needs_rebuilding:
previous_image_spec = get_previous_image_spec(chartname, image_dir)

Expand Down

0 comments on commit ebc45da

Please sign in to comment.