diff --git a/buildman/component/buildcomponent.py b/buildman/component/buildcomponent.py index 075285334..16887d439 100644 --- a/buildman/component/buildcomponent.py +++ b/buildman/component/buildcomponent.py @@ -124,15 +124,7 @@ class BuildComponent(BaseComponent): # username: The username for pulling the base image (if any). # password: The password for pulling the base image (if any). - subdir, dockerfile_name = os.path.split(build_config.get('build_subdir', '/Dockerfile')) - - # HACK HACK HACK HACK HACK HACK HACK - # TODO: FIX THIS in the database and then turn the split back on. - if dockerfile_name.find('Dockerfile') < 0: - # This is a *HACK* for the broken path handling. To be fixed ASAP. - subdir = build_config.get('build_subdir') or '/' - dockerfile_name = 'Dockerfile' - # /HACK HACK HACK HACK HACK HACK HACK + subdir, dockerfile_name = self.name_and_path(build_config.get('build_subdir')) build_arguments = { 'build_package': build_job.get_build_package_url(self.user_files), @@ -188,6 +180,14 @@ class BuildComponent(BaseComponent): old_commit_sha = build_config['trigger_metadata'].get('commit_sha', '') return commit_sha or old_commit_sha + @staticmethod + def name_and_path(subdir): + """ Returns the dockerfile path and name """ + if subdir.endswith("/"): + subdir += "Dockerfile" + elif not subdir.endswith("Dockerfile"): + subdir += "/Dockerfile" + return os.path.split(subdir) @staticmethod def _total_completion(statuses, total_images): diff --git a/buildman/component/test/test_buildcomponent.py b/buildman/component/test/test_buildcomponent.py new file mode 100644 index 000000000..2fad4dfe7 --- /dev/null +++ b/buildman/component/test/test_buildcomponent.py @@ -0,0 +1,23 @@ +import pytest + +from buildman.component.buildcomponent import BuildComponent + + +@pytest.mark.parametrize('input,expected_path,expected_file', [ + ("", "/", "Dockerfile"), + ("/", "/", "Dockerfile"), + ("/Dockerfile", "/", "Dockerfile"), + ("/server.Dockerfile", "/", "server.Dockerfile"), + ("/somepath", "/somepath", "Dockerfile"), + ("/somepath/", "/somepath", "Dockerfile"), + ("/somepath/Dockerfile", "/somepath", "Dockerfile"), + ("/somepath/server.Dockerfile", "/somepath", "server.Dockerfile"), + ("/somepath/some_other_path", "/somepath/some_other_path", "Dockerfile"), + ("/somepath/some_other_path/", "/somepath/some_other_path", "Dockerfile"), + ("/somepath/some_other_path/Dockerfile", "/somepath/some_other_path", "Dockerfile"), + ("/somepath/some_other_path/server.Dockerfile", "/somepath/some_other_path", "server.Dockerfile"), +]) +def test_path_is_dockerfile(input, expected_path, expected_file): + actual_path, actual_file = BuildComponent.name_and_path(input) + assert actual_path == expected_path + assert actual_file == expected_file