Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added recusion to handler copy + debugPrint fn #61

Merged
merged 1 commit into from
Sep 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func BuildImage(image string, handler string, functionName string, language stri
}
}

// createBuildTemplate creates temporary build folder to perform a Docker build with Node template
// createBuildTemplate creates temporary build folder to perform a Docker build with language template
func createBuildTemplate(functionName string, handler string, language string) string {
tempPath := fmt.Sprintf("./build/%s/", functionName)
fmt.Printf("Clearing temporary build folder: %s\n", tempPath)
Expand All @@ -72,7 +72,7 @@ func createBuildTemplate(functionName string, handler string, language string) s
copyFiles("./template/"+language, tempPath, true)

// Overlay in user-function
copyFiles(handler, tempPath+"function/", false)
copyFiles(handler, tempPath+"function/", true)

return tempPath
}
Expand All @@ -91,21 +91,22 @@ func copyFiles(src string, destination string, recursive bool) {
cp(src+"/"+file.Name(), destination+file.Name())

} else {

//make new destination dir
newDir := destination + file.Name() + "/"

if !pathExists(newDir) {

debugPrint(fmt.Sprintf("Creating directory: %s at %s", file.Name(), newDir))
newDirErr := os.Mkdir(newDir, 0700)

if err != nil {
if newDirErr != nil {
fmt.Printf("Error creating path %s - %s.\n", newDir, newDirErr.Error())
}
}

//did the call ask to recurse into sub directories?
if recursive == true {
//call copyTree to copy the contents
//call copyFiles to copy the contents
copyFiles(src+"/"+file.Name(), newDir, true)
}
}
Expand All @@ -124,9 +125,7 @@ func pathExists(path string) bool {

func cp(src string, destination string) error {

if val, exists := os.LookupEnv("debug"); exists && (val == "1" || val == "true") {
fmt.Printf("cp - %s %s\n", src, destination)
}
debugPrint(fmt.Sprintf("cp - %s %s", src, destination))

memoryBuffer, readErr := ioutil.ReadFile(src)
if readErr != nil {
Expand Down Expand Up @@ -161,3 +160,10 @@ func buildFlagString(nocache bool, squash bool, httpProxy string, httpsProxy str

return buildFlags
}

func debugPrint(message string) {

if val, exists := os.LookupEnv("debug"); exists && (val == "1" || val == "true") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add a --debug flag for turning this on across all commands, something for a seperate PR perhaps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was kind of the theory behind pulling it out. Suggest a separate PR since this one is a 'bug' fix

fmt.Println(message)
}
}
2 changes: 1 addition & 1 deletion commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func runBuild(cmd *cobra.Command, args []string) {
}

if pullErr := pullTemplates(); pullErr != nil {
log.Fatalln("Could not pull templates for FaaS.", pullErr)
log.Fatalln("Could not pull templates for OpenFaaS.", pullErr)
}

if len(services.Functions) > 0 {
Expand Down