From d4177e6e33541fc51ef7352cfb1ed9eb044988e5 Mon Sep 17 00:00:00 2001 From: Charlton Austin Date: Thu, 30 Mar 2017 13:24:35 -0400 Subject: [PATCH] fix(endpoints): appending dockerfile to api call ### Description of Changes this was not passing back the correct path for the dockerfile --- endpoints/api/build.py | 16 +++++++++++----- endpoints/api/test/test_build.py | 7 ++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/endpoints/api/build.py b/endpoints/api/build.py index 3abca20a3..620e01e75 100644 --- a/endpoints/api/build.py +++ b/endpoints/api/build.py @@ -4,9 +4,9 @@ import hashlib import json import logging import os -from urlparse import urlparse from flask import request +from urlparse import urlparse from app import userfiles as user_files, build_logs, log_archive, dockerfile_build_queue from auth.permissions import (ReadRepositoryPermission, ModifyRepositoryPermission, @@ -24,7 +24,6 @@ from endpoints.building import start_build, PreparedBuild, MaximumBuildsQueuedEx from endpoints.exception import Unauthorized, NotFound, InvalidRequest from util.names import parse_robot_username - logger = logging.getLogger(__name__) @@ -312,12 +311,19 @@ class RepositoryBuildList(RepositoryParamResource): def get_dockerfile_context(request_json): context = request_json['context'] if 'context' in request_json else os.path.sep if 'subdirectory' in request_json: - subdir = request_json["subdirectory"] + subdir = request_json['subdirectory'] + + context = subdir + if not subdir.endswith(os.path.sep): + subdir += os.path.sep + + subdir += 'Dockerfile' else: if context.endswith(os.path.sep): - subdir = context + "Dockerfile" + subdir = context + 'Dockerfile' else: - subdir = context + os.path.sep + "Dockerfile" + subdir = context + os.path.sep + 'Dockerfile' + return context, subdir @resource('/v1/repository//build/') diff --git a/endpoints/api/test/test_build.py b/endpoints/api/test/test_build.py index 27592193e..35227a580 100644 --- a/endpoints/api/test/test_build.py +++ b/endpoints/api/test/test_build.py @@ -4,9 +4,10 @@ from endpoints.api.build import RepositoryBuildList @pytest.mark.parametrize('request_json,subdir,context', [ - ({}, "/Dockerfile", "/"), - ({"context": "/some_context"}, "/some_context/Dockerfile", "/some_context"), - ({"subdirectory": "/some_subdir/Dockerfile"}, "/some_subdir/Dockerfile", "/"), + ({}, '/Dockerfile', '/'), + ({'context': '/some_context'}, '/some_context/Dockerfile', '/some_context'), + ({'subdirectory': 'some_context'}, 'some_context/Dockerfile', 'some_context'), + ({'subdirectory': 'some_context/'}, 'some_context/Dockerfile', 'some_context/'), ]) def test_extract_dockerfile_args(request_json, subdir, context): actual_context, actual_subdir = RepositoryBuildList.get_dockerfile_context(request_json)