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

feat: upload go binaries as al2-compatible zip #490

Merged
merged 4 commits into from
Oct 13, 2023
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
Binary file added go/internal/data/hello-go-binary-function
Binary file not shown.
15 changes: 12 additions & 3 deletions go/porcelain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
Expand All @@ -31,8 +32,9 @@ import (
)

const (
jsRuntime = "js"
goRuntime = "go"
jsRuntime = "js"
goRuntime = "go"
amazonLinux2 = "provided.al2"

preProcessingTimeout = time.Minute * 5

Expand Down Expand Up @@ -933,7 +935,7 @@ func jsFile(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 m := i.Mode(); m&0111 == 0 && runtime.GOOS != "windows" { // check if it's an executable file. skip on windows, since it doesn't have that mode
if hasWarner {
warner.OnWalkWarning(filePath, "Go binary does not have executable permissions")
}
Expand Down Expand Up @@ -980,6 +982,13 @@ func createHeader(archive *zip.Writer, i os.FileInfo, runtime string) (io.Writer
Name: i.Name(),
Method: zip.Deflate,
})
} else if runtime == amazonLinux2 {
return archive.CreateHeader(&zip.FileHeader{
CreatorVersion: 3 << 8, // indicates Unix
ExternalAttrs: 0777 << 16, // -rwxrwxrwx file permissions
Name: "bootstrap",
Method: zip.Deflate,
})
}
return archive.Create(i.Name())
}
Expand Down
17 changes: 14 additions & 3 deletions go/porcelain/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,24 +612,27 @@ func TestBundle(t *testing.T) {
functions, schedules, functionsConfig, err := bundle(gocontext.Background(), "../internal/data", mockObserver{})

assert.Nil(t, err)
assert.Equal(t, 3, len(functions.Files))
assert.Equal(t, 4, len(functions.Files))
assert.Empty(t, schedules)
assert.Nil(t, functionsConfig)

jsFunction := functions.Files["hello-js-function-test"]
pyFunction := functions.Files["hello-py-function-test"]
rsFunction := functions.Files["hello-rs-function-test"]
goFunction := functions.Files["hello-go-binary-function"]

assert.Equal(t, "js", jsFunction.Runtime)
assert.Equal(t, "py", pyFunction.Runtime)
assert.Equal(t, "rs", rsFunction.Runtime)
assert.Equal(t, "go", goFunction.Runtime)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there's no manifest file, there's no change. We're still uploading stuff as go, for now.

}

func TestBundleWithManifest(t *testing.T) {
cwd, _ := os.Getwd()
basePath := path.Join(filepath.Dir(cwd), "internal", "data")
jsFunctionPath := strings.Replace(filepath.Join(basePath, "hello-js-function-test.zip"), "\\", "/", -1)
pyFunctionPath := strings.Replace(filepath.Join(basePath, "hello-py-function-test.zip"), "\\", "/", -1)
goFunctionPath := strings.Replace(filepath.Join(basePath, "hello-go-binary-function"), "\\", "/", -1)
manifestPath := path.Join(basePath, "manifest.json")
manifestFile := fmt.Sprintf(`{
"functions": [
Expand Down Expand Up @@ -660,10 +663,16 @@ func TestBundleWithManifest(t *testing.T) {
"mainFile": "/some/path/hello-py-function-test",
"name": "hello-py-function-test",
"invocationMode": "stream"
},
{
"path": "%s",
"runtime": "go",
"runtimeVersion": "provided.al2",
"name": "hello-go-binary-function"
}
],
"version": 1
}`, jsFunctionPath, pyFunctionPath)
}`, jsFunctionPath, pyFunctionPath, goFunctionPath)

err := ioutil.WriteFile(manifestPath, []byte(manifestFile), 0644)
defer os.Remove(manifestPath)
Expand All @@ -676,11 +685,13 @@ func TestBundleWithManifest(t *testing.T) {
assert.Equal(t, "hello-js-function-test", schedules[0].Name)
assert.Equal(t, "* * * * *", schedules[0].Cron)

assert.Equal(t, 2, len(functions.Files))
assert.Equal(t, 3, len(functions.Files))
assert.Equal(t, "a-runtime", functions.Files["hello-js-function-test"].Runtime)
assert.Empty(t, functions.Files["hello-js-function-test"].FunctionMetadata.InvocationMode)
assert.Equal(t, "some-other-runtime", functions.Files["hello-py-function-test"].Runtime)
assert.Equal(t, "stream", functions.Files["hello-py-function-test"].FunctionMetadata.InvocationMode)
assert.Equal(t, "provided.al2", functions.Files["hello-go-binary-function"].Runtime)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there's a runtimeVersion: "provided.al2" in the manifest, we now pick that up and send it to the API as the runtime.

assert.Empty(t, functions.Files["hello-go-binary-function"].FunctionMetadata.InvocationMode)

helloJSConfig := functionsConfig["hello-js-function-test"]

Expand Down
Loading