mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: add support for python (#328)
This commit is contained in:
committed by
Seif Lotfy سيف لطفي
parent
8935c26951
commit
d13c8fba8c
@@ -232,7 +232,7 @@ var acceptableFnRuntimes = map[string]string{
|
|||||||
"node": "iron/node",
|
"node": "iron/node",
|
||||||
"perl": "iron/perl",
|
"perl": "iron/perl",
|
||||||
"php": "iron/php",
|
"php": "iron/php",
|
||||||
"python": "iron/python",
|
"python": "iron/python:2",
|
||||||
"ruby": "iron/ruby",
|
"ruby": "iron/ruby",
|
||||||
"scala": "iron/scala",
|
"scala": "iron/scala",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ var (
|
|||||||
".go": "go",
|
".go": "go",
|
||||||
".js": "node",
|
".js": "node",
|
||||||
".rb": "ruby",
|
".rb": "ruby",
|
||||||
|
".py": "python",
|
||||||
}
|
}
|
||||||
|
|
||||||
fnInitRuntimes []string
|
fnInitRuntimes []string
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ func GetLangHelper(lang string) (LangHelper, error) {
|
|||||||
return &NodeLangHelper{}, nil
|
return &NodeLangHelper{}, nil
|
||||||
case "ruby":
|
case "ruby":
|
||||||
return &RubyLangHelper{}, nil
|
return &RubyLangHelper{}, nil
|
||||||
|
case "python":
|
||||||
|
return &PythonHelper{}, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("No language helper found for %v", lang)
|
return nil, fmt.Errorf("No language helper found for %v", lang)
|
||||||
}
|
}
|
||||||
|
|||||||
44
fn/langs/python.go
Normal file
44
fn/langs/python.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package langs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PythonHelper struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lh *PythonHelper) Entrypoint() string {
|
||||||
|
return "python2 func.py"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lh *PythonHelper) HasPreBuild() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// PreBuild for Go builds the binary so the final image can be as small as possible
|
||||||
|
func (lh *PythonHelper) PreBuild() error {
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pbcmd := fmt.Sprintf("docker run --rm -v %s:/worker -w /worker iron/python:2-dev pip install -t packages -r requirements.txt", wd)
|
||||||
|
fmt.Println("Running prebuild command:", pbcmd)
|
||||||
|
parts := strings.Fields(pbcmd)
|
||||||
|
head := parts[0]
|
||||||
|
parts = parts[1:len(parts)]
|
||||||
|
cmd := exec.Command(head, parts...)
|
||||||
|
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 *PythonHelper) AfterBuild() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user