From 4fb0bbfb3546edf5f8b8e1874e88c0264c708f16 Mon Sep 17 00:00:00 2001 From: "Martin Dekov (VMware)" Date: Mon, 30 Jul 2018 04:02:25 -0700 Subject: [PATCH] Add build folder to dockerfile when shrinkwrap With this commit I am adding build folder when we use --shrinkwrap tag Signed-off-by: Martin Dekov (VMware) --- builder/build.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/builder/build.go b/builder/build.go index e5a26c58b..6e3a18bed 100644 --- a/builder/build.go +++ b/builder/build.go @@ -56,12 +56,13 @@ func BuildImage(image string, handler string, functionName string, language stri if strings.ToLower(language) == "dockerfile" { + tempPath = handler if shrinkwrap { - fmt.Printf("Nothing to do for: %s.\n", functionName) + tempPath = dockerBuildFolder(functionName, handler, language) + fmt.Printf("%s shrink-wrapped to %s\n", functionName, tempPath) return nil } - tempPath = handler if err := ensureHandlerPath(handler); err != nil { return fmt.Errorf("building %s, %s is an invalid path", imageName, handler) @@ -152,14 +153,31 @@ func createBuildTemplate(functionName string, handler string, language string) s fmt.Printf("Error creating path %s - %s.\n", functionPath, mkdirErr.Error()) } + CopyFiles("./template/"+language, tempPath) + + // Overlay in user-function + CopyFiles(handler, functionPath) + + return tempPath +} + +func dockerBuildFolder(functionName string, handler string, language string) string { + tempPath := fmt.Sprintf("./build/%s/", functionName) + fmt.Printf("Clearing temporary build folder: %s\n", tempPath) + + clearErr := os.RemoveAll(tempPath) + if clearErr != nil { + fmt.Printf("Error clearing temporary build folder %s\n", tempPath) + } + + fmt.Printf("Preparing %s %s\n", handler+"/", tempPath) + // Both Dockerfile and dockerfile are accepted if language == "Dockerfile" { language = "dockerfile" } - CopyFiles("./template/"+language, tempPath) - // Overlay in user-function - CopyFiles(handler, functionPath) + CopyFiles(handler, tempPath) return tempPath }