github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/compilers/rump/rump-gcloud.go (about)

     1  package rump
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/sirupsen/logrus"
     8  	"github.com/solo-io/unik/pkg/compilers"
     9  	"github.com/solo-io/unik/pkg/types"
    10  )
    11  
    12  func CreateImageGCloud(kernel string, args string, mntPoints, bakedEnv []string, noCleanup bool) (*types.RawImage, error) {
    13  	return createImageGCloud(kernel, args, mntPoints, bakedEnv, noCleanup, false)
    14  }
    15  
    16  func CreateImageGCloudAddStub(kernel string, args string, mntPoints, bakedEnv []string, noCleanup bool) (*types.RawImage, error) {
    17  	return createImageGCloud(kernel, args, mntPoints, bakedEnv, noCleanup, true)
    18  }
    19  
    20  func createImageGCloud(kernel string, args string, mntPoints, bakedEnv []string, noCleanup, addStub bool) (*types.RawImage, error) {
    21  	// create rump config
    22  	var c rumpConfig
    23  	if bakedEnv != nil {
    24  		c.Env = make(map[string]string)
    25  		for i, pair := range bakedEnv {
    26  			c.Env[fmt.Sprintf("env%d", i)] = pair
    27  		}
    28  	}
    29  
    30  	argv := []string{}
    31  	if args != "" {
    32  		argv = strings.Split(args, " ")
    33  	}
    34  	c = setRumpCmdLine(c, "program.bin", argv, addStub)
    35  
    36  	res := &types.RawImage{}
    37  	// add root -> sd0 mapping
    38  	res.RunSpec.DeviceMappings = append(res.RunSpec.DeviceMappings,
    39  		types.DeviceMapping{MountPoint: "/", DeviceName: "sd0"})
    40  
    41  	bootBlk := blk{
    42  		Source:     "dev",
    43  		Path:       "/dev/sd0e", // no disk label on the boot partition; so partition e is used.
    44  		FSType:     "blk",
    45  		MountPoint: "/bootpart",
    46  	}
    47  
    48  	c.Blk = append(c.Blk, bootBlk)
    49  
    50  	for i, mntPoint := range mntPoints {
    51  		deviceMapped := fmt.Sprintf("sd%ca", '1'+i)
    52  		blk := blk{
    53  			Source:     "dev",
    54  			Path:       "/dev/" + deviceMapped,
    55  			FSType:     "blk",
    56  			MountPoint: mntPoint,
    57  		}
    58  
    59  		c.Blk = append(c.Blk, blk)
    60  		logrus.Debugf("adding mount point to image: %s:%s", mntPoint, deviceMapped)
    61  		res.RunSpec.DeviceMappings = append(res.RunSpec.DeviceMappings,
    62  			types.DeviceMapping{MountPoint: mntPoint, DeviceName: deviceMapped})
    63  	}
    64  
    65  	// virtualbox network
    66  	c.Net = &net{
    67  		If:     "vioif0",
    68  		Type:   "inet",
    69  		Method: DHCP,
    70  	}
    71  
    72  	cmdline, err := toRumpJson(c)
    73  	if err != nil {
    74  		return nil, err
    75  	}
    76  
    77  	logrus.Debugf("writing rump json config: %s", cmdline)
    78  
    79  	imgFile, err := compilers.BuildBootableImage(kernel, cmdline, true, noCleanup)
    80  	if err != nil {
    81  		return nil, err
    82  	}
    83  
    84  	res.LocalImagePath = imgFile
    85  	res.StageSpec.ImageFormat = types.ImageFormat_RAW
    86  	res.RunSpec.DefaultInstanceMemory = 256
    87  	return res, nil
    88  }