diff --git a/hubploy/config.py b/hubploy/config.py index cc9c33e..fddf893 100644 --- a/hubploy/config.py +++ b/hubploy/config.py @@ -6,7 +6,8 @@ from repo2docker.app import Repo2Docker import docker -from . import gitutils + +from . import utils yaml = YAML(typ='safe') class DeploymentNotFoundError(Exception): @@ -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}' @@ -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): """ @@ -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): """ @@ -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): diff --git a/hubploy/gitutils.py b/hubploy/utils.py similarity index 97% rename from hubploy/gitutils.py rename to hubploy/utils.py index 55bcead..b72ee25 100644 --- a/hubploy/gitutils.py +++ b/hubploy/utils.py @@ -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() != '' \ No newline at end of file diff --git a/tests/test_imagebuilder.py b/tests/test_imagebuilder.py index 3de8019..6752baf 100644 --- a/tests/test_imagebuilder.py +++ b/tests/test_imagebuilder.py @@ -9,7 +9,7 @@ import time import docker.errors -from hubploy import config, gitutils +from hubploy import config, utils @pytest.fixture @@ -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