Skip to content

Warn if function conditions are not met #224

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

Merged
merged 2 commits into from
Apr 15, 2020
Merged
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
28 changes: 25 additions & 3 deletions go/porcelain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ type DeployObserver interface {
OnFailedUpload(*FileBundle)
}

type DeployWarner interface {
OnWalkWarning(path, msg string)
}

// DeployOptions holds the option for creating a new deploy
type DeployOptions struct {
SiteID string
Expand Down Expand Up @@ -579,12 +583,16 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, error) {
return nil, err
}
functions.Add(file.Name, file)
case goFile(filePath, i):
case goFile(filePath, i, observer):
file, err := newFunctionFile(filePath, i, goRuntime, observer)
if err != nil {
return nil, err
}
functions.Add(file.Name, file)
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious if there is a case that function directory could have some files that are not zip nor js nor go legitimately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think this walks the temporary dir from zisi, therefore only files that zisi picked up should be there

if warner, ok := observer.(DeployWarner); ok {
warner.OnWalkWarning(filePath, "Function is not valid for deployment. Please check that it matches the format for the runtime.")
}
}
}

Expand Down Expand Up @@ -653,17 +661,31 @@ func jsFile(i os.FileInfo) bool {
return filepath.Ext(i.Name()) == ".js"
}

func goFile(filePath string, i os.FileInfo) bool {
func goFile(filePath string, i os.FileInfo, observer DeployObserver) bool {
warner, hasWarner := observer.(DeployWarner)

if m := i.Mode(); m&0111 == 0 { // check if it's an executable file
if hasWarner {
warner.OnWalkWarning(filePath, "Go binary does not have executable permissions")
}
return false
}

if _, err := elf.Open(filePath); err != nil { // check if it's a linux executable
if hasWarner {
warner.OnWalkWarning(filePath, "Go binary is not a linux executable")
}
return false
}

v, err := version.ReadExe(filePath)
return err == nil && strings.HasPrefix(v.Release, "go1.")
if err != nil || !strings.HasPrefix(v.Release, "go1.") {
if hasWarner {
warner.OnWalkWarning(filePath, "Unable to detect Go version 1.x")
}
}

return true
}

func ignoreFile(rel string) bool {
Expand Down