github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/compilers/osv/osv_java.go (about) 1 package osv 2 3 import ( 4 "github.com/sirupsen/logrus" 5 "github.com/emc-advanced-dev/pkg/errors" 6 "github.com/solo-io/unik/pkg/compilers" 7 "github.com/solo-io/unik/pkg/types" 8 unikutil "github.com/solo-io/unik/pkg/util" 9 "gopkg.in/yaml.v2" 10 "io/ioutil" 11 "path/filepath" 12 ) 13 14 type OSvJavaCompiler struct { 15 ImageFinisher ImageFinisher 16 } 17 18 // javaProjectConfig defines available inputs 19 type javaProjectConfig struct { 20 MainFile string `yaml:"main_file"` 21 RuntimeArgs string `yaml:"runtime_args"` 22 BuildCmd string `yaml:"build_command"` 23 } 24 25 func (r *OSvJavaCompiler) CompileRawImage(params types.CompileImageParams) (*types.RawImage, error) { 26 sourcesDir := params.SourcesDir 27 28 var config javaProjectConfig 29 data, err := ioutil.ReadFile(filepath.Join(sourcesDir, "manifest.yaml")) 30 if err != nil { 31 return nil, errors.New("failed to read manifest.yaml file", err) 32 } 33 if err := yaml.Unmarshal(data, &config); err != nil { 34 return nil, errors.New("failed to parse yaml manifest.yaml file", err) 35 } 36 37 container := unikutil.NewContainer("compilers-osv-java").WithVolume("/dev", "/dev").WithVolume(sourcesDir+"/", "/project_directory") 38 var args []string 39 if r.ImageFinisher.UseEc2() { 40 args = append(args, "-ec2") 41 } 42 43 args = append(args, "-main_file", config.MainFile) 44 args = append(args, "-args", params.Args) 45 if config.BuildCmd != "" { 46 args = append(args, "-buildCmd", config.BuildCmd) 47 } 48 if len(config.RuntimeArgs) > 0 { 49 args = append(args, "-runtime", config.RuntimeArgs) 50 } 51 52 logrus.WithFields(logrus.Fields{ 53 "args": args, 54 }).Debugf("running compilers-osv-java container") 55 56 if err := container.Run(args...); err != nil { 57 return nil, errors.New("failed running compilers-osv-java on "+sourcesDir, err) 58 } 59 60 // And finally bootstrap. 61 convertParams := FinishParams{ 62 CompileParams: params, 63 CapstanImagePath: filepath.Join(sourcesDir, "boot.qcow2"), 64 } 65 return r.ImageFinisher.FinishImage(convertParams) 66 } 67 68 func (r *OSvJavaCompiler) Usage() *compilers.CompilerUsage { 69 return &compilers.CompilerUsage{ 70 PrepareApplication: "Compile your Java application into a fat jar.", 71 ConfigurationFiles: map[string]string{ 72 "/manifest.yaml": "main_file: <relative-path-to-your-fat-jar>", 73 }, 74 } 75 }