mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Inital work on Rust support (#333)
* Inital work on Rust support * update accepted runtimes * fn: fix rust build * Last tweaks and README.md * fix typo * update comment on rust.go
This commit is contained in:
committed by
C Cirello
parent
3788c968eb
commit
237ab3e21b
@@ -235,6 +235,7 @@ var acceptableFnRuntimes = map[string]string{
|
||||
"python": "iron/python:2",
|
||||
"ruby": "iron/ruby",
|
||||
"scala": "iron/scala",
|
||||
"rust": "corey/rust-alpine",
|
||||
}
|
||||
|
||||
const tplDockerfile = `FROM {{ .BaseImage }}
|
||||
|
||||
@@ -27,6 +27,7 @@ var (
|
||||
".js": "node",
|
||||
".rb": "ruby",
|
||||
".py": "python",
|
||||
".rs": "rust",
|
||||
}
|
||||
|
||||
fnInitRuntimes []string
|
||||
|
||||
@@ -13,6 +13,8 @@ func GetLangHelper(lang string) (LangHelper, error) {
|
||||
return &RubyLangHelper{}, nil
|
||||
case "python":
|
||||
return &PythonHelper{}, nil
|
||||
case "rust":
|
||||
return &RustLangHelper{}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("No language helper found for %v", lang)
|
||||
}
|
||||
|
||||
42
fn/langs/rust.go
Normal file
42
fn/langs/rust.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package langs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type RustLangHelper struct{}
|
||||
|
||||
func (lh *RustLangHelper) Entrypoint() string {
|
||||
return "/function/target/release/func"
|
||||
}
|
||||
|
||||
func (lh *RustLangHelper) HasPreBuild() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// PreBuild for rust builds the binary so the final image can be as small as possible
|
||||
func (lh *RustLangHelper) PreBuild() error {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := exec.Command(
|
||||
"docker", "run",
|
||||
"--rm", "-v",
|
||||
wd+":/app", "-w", "/app", "corey/rust-alpine",
|
||||
"/bin/sh", "-c", "cargo build --release",
|
||||
)
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("error running docker build: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lh *RustLangHelper) AfterBuild() error {
|
||||
return os.RemoveAll("target")
|
||||
}
|
||||
Reference in New Issue
Block a user