Skip to content

Commit

Permalink
Merge pull request #60 from yuvipanda/fixes
Browse files Browse the repository at this point in the history
Throw better errors when image name is unspecified
  • Loading branch information
yuvipanda committed Mar 27, 2020
2 parents 5071b96 + ce4227f commit 405a7c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
14 changes: 9 additions & 5 deletions hubploy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from repo2docker.app import Repo2Docker
import docker

from . import gitutils

from . import utils
yaml = YAML(typ='safe')

class DeploymentNotFoundError(Exception):
Expand All @@ -33,9 +34,13 @@ def __init__(self, name, path, helm_substitution_path='jupyterhub.singleuser.ima
Expects cwd to be inside the git repo we are operating in
"""
# name must not be empty
# FIXME: Validate name to conform to docker image name guidelines
if not name or name.strip() == '':
raise ValueError("Name of image to be built is not specified. Check hubploy.yaml of your deployment")
self.name = name

self.tag = gitutils.last_modified_commit(path)
self.tag = utils.last_modified_commit(path)
self.path = path
self.helm_substitution_path = helm_substitution_path
self.image_spec = f'{self.name}:{self.tag}'
Expand All @@ -49,7 +54,6 @@ def __init__(self, name, path, helm_substitution_path='jupyterhub.singleuser.ima
self.r2d.target_repo_dir = '/srv/repo'
self.r2d.initialize()


@property
def docker(self):
"""
Expand Down Expand Up @@ -99,7 +103,7 @@ def get_possible_parent_tags(self, n=16):
# FIXME: Make this look for last modified since before beginning of commit_range
# Otherwise, if there are more than n commits in the current PR that touch this
# local image, we might not get any useful caches
yield gitutils.last_modified_commit(self.path, n=i)
yield utils.last_modified_commit(self.path, n=i)

def fetch_parent_image(self):
"""
Expand Down Expand Up @@ -136,7 +140,7 @@ def needs_building(self, check_registry=False, commit_range=None):
return not self.exists_in_registry()

if commit_range:
return gitutils.path_touched(self.path, commit_range=commit_range)
return utils.path_touched(self.path, commit_range=commit_range)


def build(self, reuse_cache=True):
Expand Down
2 changes: 1 addition & 1 deletion hubploy/gitutils.py → hubploy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def path_touched(*paths, commit_range):
"""
return subprocess.check_output([
'git', 'diff', '--name-only', commit_range, '--', *paths
]).decode('utf-8').strip() != ''
]).decode('utf-8').strip() != ''
8 changes: 4 additions & 4 deletions tests/test_imagebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import time
import docker.errors

from hubploy import config, gitutils
from hubploy import config, utils


@pytest.fixture
Expand Down Expand Up @@ -93,15 +93,15 @@ def test_tag_generation(git_repo):

with cwd(git_repo):
image = config.LocalImage('test-image', 'image')
assert image.tag == gitutils.last_modified_commit('image')
assert image.tag == utils.last_modified_commit('image')
# Make sure tag isn't influenced by changes outside of iamge dir
assert image.tag != gitutils.last_modified_commit('unrelated')
assert image.tag != utils.last_modified_commit('unrelated')


# Change the Dockerfile and see that the tag changes
commit_file(git_repo, 'image/Dockerfile', 'FROM busybox:latest')
new_image = config.LocalImage('test-image', 'image')
assert new_image.tag == gitutils.last_modified_commit('image')
assert new_image.tag == utils.last_modified_commit('image')
assert new_image.tag != image.tag


Expand Down

0 comments on commit 405a7c0

Please sign in to comment.