fix(buildcomponent): fix dockerfile cases

some errors were introduced with file paths of the form "/some_path/some_other_path" as "some_other_path" would be the dockerfile name
This commit is contained in:
Charlton Austin 2017-03-08 09:44:31 -05:00
parent b05f235114
commit afbd6fb19b
2 changed files with 32 additions and 9 deletions

View file

@ -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):

View file

@ -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