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 2 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.
12 changes: 10 additions & 2 deletions go/porcelain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import (
)

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

preProcessingTimeout = time.Minute * 5

Expand Down Expand Up @@ -965,6 +966,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 @@ -444,24 +444,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 @@ -491,10 +494,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 @@ -507,11 +516,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