mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
php langhelper (needs funcy/php), tutorial
This commit is contained in:
@@ -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
49
fn/langs/php.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user