diff --git a/endpoints/api/build.py b/endpoints/api/build.py index 620e01e75..7a20c2872 100644 --- a/endpoints/api/build.py +++ b/endpoints/api/build.py @@ -175,7 +175,15 @@ class RepositoryBuildList(RepositoryParamResource): }, 'subdirectory': { 'type': 'string', - 'description': 'Subdirectory in which the Dockerfile can be found', + 'description': 'Subdirectory in which the Dockerfile can be found. You can only specify this or dockerfile_path', + }, + 'dockerfile_path': { + 'type': 'string', + 'description': 'Path to a dockerfile. You can only specify this or subdirectory.', + }, + 'context': { + 'type': 'string', + 'description': 'Pass in the context for the dockerfile. This is optional.', }, 'pull_robot': { 'type': 'string', @@ -310,9 +318,14 @@ class RepositoryBuildList(RepositoryParamResource): @staticmethod def get_dockerfile_context(request_json): context = request_json['context'] if 'context' in request_json else os.path.sep + if 'dockerfile_path' in request_json: + subdir = request_json['dockerfile_path'] + if 'context' not in request_json: + context = os.path.dirname(subdir) + return context, subdir + if 'subdirectory' in request_json: subdir = request_json['subdirectory'] - context = subdir if not subdir.endswith(os.path.sep): subdir += os.path.sep diff --git a/endpoints/api/test/test_build.py b/endpoints/api/test/test_build.py index 35227a580..bf98ad4eb 100644 --- a/endpoints/api/test/test_build.py +++ b/endpoints/api/test/test_build.py @@ -8,6 +8,11 @@ from endpoints.api.build import RepositoryBuildList ({'context': '/some_context'}, '/some_context/Dockerfile', '/some_context'), ({'subdirectory': 'some_context'}, 'some_context/Dockerfile', 'some_context'), ({'subdirectory': 'some_context/'}, 'some_context/Dockerfile', 'some_context/'), + ({'dockerfile_path': 'some_context/Dockerfile'}, 'some_context/Dockerfile', 'some_context'), + ({'dockerfile_path': 'some_context/Dockerfile', 'context': '/'}, 'some_context/Dockerfile', '/'), + ({'dockerfile_path': 'some_context/Dockerfile', + 'context': '/', + 'subdirectory': 'slime'}, 'some_context/Dockerfile', '/'), ]) def test_extract_dockerfile_args(request_json, subdir, context): actual_context, actual_subdir = RepositoryBuildList.get_dockerfile_context(request_json)