diff --git a/api/http/handler/customtemplates/customtemplate_create.go b/api/http/handler/customtemplates/customtemplate_create.go index f79aac9e9..c4e375b43 100644 --- a/api/http/handler/customtemplates/customtemplate_create.go +++ b/api/http/handler/customtemplates/customtemplate_create.go @@ -2,6 +2,7 @@ package customtemplates import ( "errors" + "log" "net/http" "regexp" "strconv" @@ -270,6 +271,23 @@ func (handler *Handler) createCustomTemplateFromGitRepository(r *http.Request) ( return nil, err } + entryPath := filesystem.JoinPaths(projectPath, customTemplate.EntryPoint) + + exists, err := handler.FileService.FileExists(entryPath) + if err != nil || !exists { + if err := handler.FileService.RemoveDirectory(projectPath); err != nil { + log.Printf("[WARN] [http,customtemplate,git] [error: %s] [message: unable to remove git repository directory]", err) + } + } + + if err != nil { + return nil, err + } + + if !exists { + return nil, errors.New("Invalid Compose file, ensure that the Compose file path is correct") + } + return customTemplate, nil }