fn: add support for python (#328)

This commit is contained in:
C Cirello
2016-11-21 23:12:30 +01:00
committed by Seif Lotfy سيف لطفي
parent 8935c26951
commit d13c8fba8c
4 changed files with 48 additions and 1 deletions

View File

@@ -232,7 +232,7 @@ var acceptableFnRuntimes = map[string]string{
"node": "iron/node",
"perl": "iron/perl",
"php": "iron/php",
"python": "iron/python",
"python": "iron/python:2",
"ruby": "iron/ruby",
"scala": "iron/scala",
}

View File

@@ -26,6 +26,7 @@ var (
".go": "go",
".js": "node",
".rb": "ruby",
".py": "python",
}
fnInitRuntimes []string

View File

@@ -11,6 +11,8 @@ func GetLangHelper(lang string) (LangHelper, error) {
return &NodeLangHelper{}, nil
case "ruby":
return &RubyLangHelper{}, nil
case "python":
return &PythonHelper{}, nil
}
return nil, fmt.Errorf("No language helper found for %v", lang)
}

44
fn/langs/python.go Normal file
View 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
}