mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Build project/func on host machine for java-maven
This change introduces a local build step as opposed to the prebuild step which happens inside a dev container.
This commit is contained in:
@@ -1,59 +1,31 @@
|
|||||||
package langs
|
package langs
|
||||||
|
|
||||||
import (
|
import "fmt"
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// JavaMavenLangHelper provides a set of helper methods for the build lifecycle of Java Maven projects
|
// JavaMavenLangHelper provides a set of helper methods for the build lifecycle of Java Maven projects
|
||||||
type JavaMavenLangHelper struct {
|
type JavaMavenLangHelper struct {
|
||||||
BaseHelper
|
BaseHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Entrypoint returns the Java runtime Docker entrypoint that will be executed when the function is run
|
// Entrypoint returns the Java runtime Docker entrypoint that will be executed when the function is run
|
||||||
func (lh *JavaMavenLangHelper) Entrypoint() string {
|
func (lh *JavaMavenLangHelper) Entrypoint() string {
|
||||||
return fmt.Sprintf("java -jar /function/target/function.jar com.example.faas.ExampleFunction::itsOn")
|
// TODO need mechanism to determine the java user function dynamically
|
||||||
|
userFunction := "com.example.faas.ExampleFunction::itsOn"
|
||||||
|
return fmt.Sprintf("java -jar /function/target/function.jar %s", userFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasPreBuild returns whether the Java runtime has a pre-build step
|
func (lh *JavaMavenLangHelper) HasLocalBuildCmd() bool {
|
||||||
func (lh *JavaMavenLangHelper) HasPreBuild() bool {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreBuild runs "mvn clean package" in the root of the project and by default expects a jar at `target/function.jar` as the
|
func (lh *JavaMavenLangHelper) LocalBuildCmd() []string {
|
||||||
// output. We mount `$HOME/.m2` in order to get maven the proxy config specified in .m2/settings.xml, but it has the nice
|
return []string{
|
||||||
// side effect of making the users .m2/repository available. Any new deps downloaded will be owned by root :(
|
"mvn clean package",
|
||||||
func (lh *JavaMavenLangHelper) PreBuild() error {
|
|
||||||
wd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists(filepath.Join(wd, "pom.xml")) {
|
|
||||||
return fmt.Errorf("Could not find pom.xml - are you sure this is a maven project?")
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(
|
|
||||||
"docker", "run",
|
|
||||||
"--rm",
|
|
||||||
"-v", wd+":/java", "-w", "/java",
|
|
||||||
"-v", os.Getenv("HOME")+"/.m2:/.m2",
|
|
||||||
"maven:3.5-jdk-8-alpine",
|
|
||||||
"/bin/sh", "-c", "mvn -gs /.m2/settings.xml clean package",
|
|
||||||
)
|
|
||||||
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return dockerBuildError(err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AfterBuild should remove the (root-owned) target dir.
|
func (lh *JavaMavenLangHelper) HasPreBuild() bool { return false }
|
||||||
func (lh *JavaMavenLangHelper) AfterBuild() error {
|
|
||||||
return nil
|
func (lh *JavaMavenLangHelper) PreBuild() error { return nil }
|
||||||
}
|
|
||||||
|
func (lh *JavaMavenLangHelper) AfterBuild() error { return nil }
|
||||||
|
|||||||
Reference in New Issue
Block a user