github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/compilers/firecracker/firecracker-go.go (about) 1 package firecracker 2 3 import ( 4 "os" 5 "path/filepath" 6 7 "github.com/sirupsen/logrus" 8 "github.com/solo-io/unik/pkg/compilers" 9 "github.com/solo-io/unik/pkg/types" 10 unikutil "github.com/solo-io/unik/pkg/util" 11 ) 12 13 type FirecrackerCompiler struct{} 14 15 func (f *FirecrackerCompiler) CompileRawImage(params types.CompileImageParams) (*types.RawImage, error) { 16 sourcesDir := params.SourcesDir 17 18 // run dep ensure and go build 19 if err := unikutil.NewContainer("compilers-firecracker").Privileged(true).WithVolume(sourcesDir, "/opt/code").Run(); err != nil { 20 return nil, err 21 } 22 res := &types.RawImage{} 23 localImageFile, err := f.getImagefile(sourcesDir) 24 if err != nil { 25 logrus.Errorf("error getting local image file name") 26 } 27 res.LocalImagePath = localImageFile 28 res.StageSpec.ImageFormat = types.ImageFormat_RAW 29 res.RunSpec.DefaultInstanceMemory = 256 30 return res, nil 31 } 32 33 func (f *FirecrackerCompiler) getImagefile(directory string) (string, error) { 34 35 rootfs := filepath.Join(directory, "rootfs") 36 37 _, err := os.Stat(rootfs) 38 return rootfs, err 39 } 40 41 func (f *FirecrackerCompiler) Usage() *compilers.CompilerUsage { 42 return nil 43 }