Skip to content

Commit

Permalink
Add build folder to dockerfile when shrinkwrap
Browse files Browse the repository at this point in the history
With this commit I am adding build folder when we use
--shrinkwrap tag

Signed-off-by: Martin Dekov (VMware) <[email protected]>
  • Loading branch information
martindekov authored and alexellis committed Aug 17, 2018
1 parent e730b6b commit 4fb0bbf
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 4fb0bbf

Please sign in to comment.