php langhelper (needs funcy/php), tutorial

This commit is contained in:
Chad Arimura
2017-05-26 12:36:38 -07:00
parent 98e05eec63
commit b49337d4e0
10 changed files with 188 additions and 57 deletions

View File

@@ -11,6 +11,8 @@ func GetLangHelper(lang string) LangHelper {
return &RubyLangHelper{}
case "python":
return &PythonHelper{}
case "php":
return &PhpLangHelper{}
case "rust":
return &RustLangHelper{}
case "dotnet":

49
fn/langs/php.go Normal file
View File

@@ -0,0 +1,49 @@
package langs
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)
type PhpLangHelper struct {
BaseHelper
}
func (lh *PhpLangHelper) Entrypoint() string {
return "php func.php"
}
func (lh *PhpLangHelper) HasPreBuild() bool {
return true
}
func (lh *PhpLangHelper) PreBuild() error {
wd, err := os.Getwd()
if err != nil {
return err
}
if !exists(filepath.Join(wd, "composer.json")) {
return nil
}
pbcmd := fmt.Sprintf("docker run --rm -v %s:/worker -w /worker funcy/php:dev composer install", 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 *PhpLangHelper) AfterBuild() error {
return nil
}