forked from solo-io/unik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
osv_java.go
65 lines (55 loc) · 1.86 KB
/
osv_java.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package osv
import (
"github.com/Sirupsen/logrus"
"github.com/emc-advanced-dev/pkg/errors"
"github.com/emc-advanced-dev/unik/pkg/types"
unikutil "github.com/emc-advanced-dev/unik/pkg/util"
"gopkg.in/yaml.v2"
"io/ioutil"
"path/filepath"
)
type OSvJavaCompiler struct {
ImageFinisher ImageFinisher
}
// javaProjectConfig defines available inputs
type javaProjectConfig struct {
MainFile string `yaml:"main_file"`
RuntimeArgs string `yaml:"runtime_args"`
BuildCmd string `yaml:"build_command"`
}
func (r *OSvJavaCompiler) CompileRawImage(params types.CompileImageParams) (*types.RawImage, error) {
sourcesDir := params.SourcesDir
var config javaProjectConfig
data, err := ioutil.ReadFile(filepath.Join(sourcesDir, "manifest.yaml"))
if err != nil {
return nil, errors.New("failed to read manifest.yaml file", err)
}
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, errors.New("failed to parse yaml manifest.yaml file", err)
}
container := unikutil.NewContainer("compilers-osv-java").WithVolume("/dev", "/dev").WithVolume(sourcesDir+"/", "/project_directory")
var args []string
if r.ImageFinisher.UseEc2() {
args = append(args, "-ec2")
}
args = append(args, "-main_file", config.MainFile)
args = append(args, "-args", params.Args)
if config.BuildCmd != "" {
args = append(args, "-buildCmd", config.BuildCmd)
}
if len(config.RuntimeArgs) > 0 {
args = append(args, "-runtime", config.RuntimeArgs)
}
logrus.WithFields(logrus.Fields{
"args": args,
}).Debugf("running compilers-osv-java container")
if err := container.Run(args...); err != nil {
return nil, errors.New("failed running compilers-osv-java on "+sourcesDir, err)
}
// And finally bootstrap.
convertParams := FinishParams{
CompileParams: params,
CapstanImagePath: filepath.Join(sourcesDir, "boot.qcow2"),
}
return r.ImageFinisher.FinishImage(convertParams)
}