Skip to content

Commit

Permalink
fn: add support for python (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccirello authored and seiflotfy committed Nov 21, 2016
1 parent 8935c26 commit d13c8fb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fn/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down
1 change: 1 addition & 0 deletions fn/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
".go": "go",
".js": "node",
".rb": "ruby",
".py": "python",
}

fnInitRuntimes []string
Expand Down
2 changes: 2 additions & 0 deletions fn/langs/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
44 changes: 44 additions & 0 deletions fn/langs/python.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit d13c8fb

Please sign in to comment.