diff --git a/projects/demo/etcd/infrakit.json b/projects/demo/etcd/infrakit.json index 0d7cef887..b9b83e274 100644 --- a/projects/demo/etcd/infrakit.json +++ b/projects/demo/etcd/infrakit.json @@ -13,7 +13,7 @@ "Instance": { "Plugin": "instance-hyperkit", "Properties": { - "Moby": "etcd", + "kernel+initrd": "etcd", "Disk" : 1024, "CPUs" : 1, "Memory" : 1024 diff --git a/src/cmd/infrakit-instance-hyperkit/hyperkit.json b/src/cmd/infrakit-instance-hyperkit/hyperkit.json index 8521611b9..ef158bbf1 100644 --- a/src/cmd/infrakit-instance-hyperkit/hyperkit.json +++ b/src/cmd/infrakit-instance-hyperkit/hyperkit.json @@ -7,7 +7,8 @@ "Instance": { "Plugin": "instance-hyperkit", "Properties": { - "Moby": "../../moby", + "_comment" : "kernel+initrd specifies the prefix as in -bzImage and -initrd.img", + "kernel+initrd": "linux", "Disk" : 512, "CPUs" : 2, "Memory" : 1024 diff --git a/src/cmd/infrakit-instance-hyperkit/instance.go b/src/cmd/infrakit-instance-hyperkit/instance.go index 79039a129..46a4bb3b8 100644 --- a/src/cmd/infrakit-instance-hyperkit/instance.go +++ b/src/cmd/infrakit-instance-hyperkit/instance.go @@ -9,11 +9,10 @@ import ( "path" log "github.com/Sirupsen/logrus" - "github.com/docker/hyperkit/go" - "github.com/docker/infrakit/pkg/spi/instance" "github.com/docker/infrakit/pkg/types" + "github.com/rneugeba/iso9660wrap" ) // NewHyperKitPlugin creates an instance plugin for hyperkit. @@ -55,8 +54,8 @@ func (p hyperkitPlugin) Provision(spec instance.Spec) (*instance.ID, error) { } } - if properties["Moby"] == nil { - return nil, errors.New("Property 'Moby' must be set") + if properties["kernel+initrd"] == nil { + return nil, errors.New("Property 'kernel+initrd' must be set") } if properties["CPUs"] == nil { properties["CPUs"] = 1 @@ -98,28 +97,39 @@ func (p hyperkitPlugin) Provision(spec instance.Spec) (*instance.ID, error) { // so it persists across reboots. if diskSize != 0 { diskImage = path.Join(p.DiskDir, logicalID+".img") - // Make sure the directory exists - err = os.MkdirAll(p.DiskDir, 0755) - if err != nil { - return nil, err - } } } + + isoImage := "" + if spec.Init != "" { + isoImage = path.Join(instanceDir, "data.iso") + outfh, err := os.OpenFile(isoImage, os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + log.Fatalf("Cannot create user data ISO: %s", err) + } + err = iso9660wrap.WriteBuffer(outfh, []byte(spec.Init), "config") + if err != nil { + log.Fatalf("Cannot write user data ISO: %s", err) + } + outfh.Close() + } + log.Infof("[%s] LogicalID: %s", id, logicalID) log.Debugf("[%s] UUID: %s", id, uuidStr) // Start a HyperKit instance - h, err := hyperkit.New(p.HyperKit, instanceDir, p.VPNKitSock, diskImage) + h, err := hyperkit.New(p.HyperKit, p.VPNKitSock, instanceDir) if err != nil { return nil, err } - h.Kernel = properties["Moby"].(string) + "-bzImage" - h.Initrd = properties["Moby"].(string) + "-initrd.img" + h.Kernel = properties["kernel+initrd"].(string) + "-bzImage" + h.Initrd = properties["kernel+initrd"].(string) + "-initrd.img" + h.UUID = uuidStr + h.DiskImage = diskImage + h.ISOImage = isoImage h.CPUs = int(properties["CPUs"].(float64)) h.Memory = int(properties["Memory"].(float64)) h.DiskSize = diskSize - h.UUID = uuidStr - h.UserData = spec.Init h.Console = hyperkit.ConsoleFile log.Infof("[%s] Booting: %s/%s", id, h.Kernel, h.Initrd) log.Infof("[%s] %d CPUs, %dMB Memory, %dMB Disk (%s)", id, h.CPUs, h.Memory, h.DiskSize, h.DiskImage) diff --git a/src/cmd/moby/run_hyperkit.go b/src/cmd/moby/run_hyperkit.go index 12faea39d..c3d29b1b2 100644 --- a/src/cmd/moby/run_hyperkit.go +++ b/src/cmd/moby/run_hyperkit.go @@ -86,18 +86,19 @@ func runHyperKit(args []string) { *disk = prefix + "-disk.img" } - h, err := hyperkit.New(*hyperkitPath, "", "auto", *disk) + h, err := hyperkit.New(*hyperkitPath, "auto", "") if err != nil { log.Fatalln("Error creating hyperkit: ", err) } h.Kernel = prefix + "-bzImage" h.Initrd = prefix + "-initrd.img" + h.UUID = uuidStr + h.DiskImage = *disk h.ISOImage = isoPath h.CPUs = *cpus h.Memory = *mem h.DiskSize = *diskSz - h.UUID = uuidStr err = h.Run(string(cmdline)) if err != nil { diff --git a/vendor.conf b/vendor.conf index 3bf35ba7a..f0b7863f5 100644 --- a/vendor.conf +++ b/vendor.conf @@ -9,10 +9,10 @@ github.com/docker/distribution 07f32ac1831ed0fc71960b7da5d6bb83cb6881b5 github.com/docker/engine-api cf82c64276ebc2501e72b241f9fdc1e21e421743 github.com/docker/go-connections e15c02316c12de00874640cd76311849de2aeed5 github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3 -github.com/docker/hyperkit/go 89b0a4a88ec340c756a6bd14af57e26f69d29d09 +github.com/docker/hyperkit c49c076a1b24883c61f5cfbec7943b2e16ad7c5a github.com/docker/infrakit cb420e3e50ea60afe58538b1d3cab1cb14059433 github.com/ghodss/yaml 0ca9ea5df5451ffdf184b4428c902747c2c11cd7 -github.com/golang/protobuf/proto c9c7427a2a70d2eb3bafa0ab2dc163e45f143317 +github.com/golang/protobuf c9c7427a2a70d2eb3bafa0ab2dc163e45f143317 github.com/googleapis/gax-go 8c5154c0fe5bf18cf649634d4c6df50897a32751 github.com/gorilla/context 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 github.com/gorilla/mux 599cba5e7b6137d46ddf58fb1765f5d928e69604 @@ -31,7 +31,7 @@ github.com/spf13/pflag 9ff6c6923cfffbcd502984b8e0c80539a94968b7 github.com/surma/gocpio fcb68777e7dc4ea43ffce871b552c0d073c17495 github.com/vaughan0/go-ini a98ad7ee00ec53921f08832bc06ecf7fd600e6a1 golang.org/x/crypto 573951cbe80bb6352881271bb276f48749eab6f4 -golang.org/x/net/context a6577fac2d73be281a500b310739095313165611 +golang.org/x/net a6577fac2d73be281a500b310739095313165611 golang.org/x/oauth2 1611bb46e67abc64a71ecc5c3ae67f1cbbc2b921 golang.org/x/sys 99f16d856c9836c42d24e7ab64ea72916925fa97 golang.org/x/text a263ba8 diff --git a/vendor/github.com/docker/hyperkit/go/hyperkit.go b/vendor/github.com/docker/hyperkit/go/hyperkit.go index f79ff94b1..7f43448ca 100644 --- a/vendor/github.com/docker/hyperkit/go/hyperkit.go +++ b/vendor/github.com/docker/hyperkit/go/hyperkit.go @@ -31,12 +31,12 @@ import ( "os" "os/exec" "os/user" + "path" "path/filepath" "strconv" "strings" "github.com/mitchellh/go-ps" - "github.com/rneugeba/iso9660wrap" ) const ( @@ -94,10 +94,6 @@ type HyperKit struct { // connected to. ConsoleStdio and ConsoleFile are supported. Console int `json:"console"` - // UserData, if non empty, will be added to a ISO under the - // filename `config` and passed to the VM. - UserData string `json:"user_data"` - // Below here are internal members, but they are exported so // that they are written to the state json file, if configured. @@ -118,7 +114,7 @@ type HyperKit struct { // - If vpnkitsock is empty no networking is configured. If it is set // to "auto" it tries to re-use the Docker for Mac VPNKit connection. // - If statedir is "" no state is written to disk. -func New(hyperkit, statedir, vpnkitsock, diskimage string) (*HyperKit, error) { +func New(hyperkit, vpnkitsock, statedir string) (*HyperKit, error) { h := HyperKit{} var err error @@ -131,13 +127,11 @@ func New(hyperkit, statedir, vpnkitsock, diskimage string) (*HyperKit, error) { if err != nil { return nil, err } - h.DiskImage = diskimage h.CPUs = defaultCPUs h.Memory = defaultMemory h.Console = ConsoleStdio - h.UserData = "" return &h, nil } @@ -199,9 +193,6 @@ func (h *HyperKit) execute(cmdline string) error { if h.Console == ConsoleFile && h.StateDir == "" { return fmt.Errorf("If ConsoleFile is set, StateDir must be specified") } - if h.UserData != "" && h.ISOImage != "" { - return fmt.Errorf("If UserData is supplied, ISOImage must not be set") - } if h.ISOImage != "" { if _, err = os.Stat(h.ISOImage); os.IsNotExist(err) { return fmt.Errorf("ISO %s does not exist", h.ISOImage) @@ -210,9 +201,6 @@ func (h *HyperKit) execute(cmdline string) error { if h.VSock && h.StateDir == "" { return fmt.Errorf("If virtio-sockets are enabled, StateDir must be specified") } - if h.UserData != "" && h.StateDir == "" { - return fmt.Errorf("If UserData is supplied, StateDir must be specified") - } if _, err = os.Stat(h.Kernel); os.IsNotExist(err) { return fmt.Errorf("Kernel %s does not exist", h.Kernel) } @@ -241,12 +229,6 @@ func (h *HyperKit) execute(cmdline string) error { } } } - if h.UserData != "" { - h.ISOImage, err = createUserDataISO(h.StateDir, h.UserData) - if err != nil { - return err - } - } // Run h.buildArgs(cmdline) @@ -331,6 +313,13 @@ func (h *HyperKit) String() string { // CreateDiskImage creates a empty file suitable for use as a disk image for a hyperkit VM. func CreateDiskImage(location string, sizeMB int) error { + diskDir := path.Dir(location) + if diskDir != "." { + if err := os.MkdirAll(diskDir, 0755); err != nil { + return err + } + } + f, err := os.Create(location) if err != nil { return err @@ -446,6 +435,9 @@ func (h *HyperKit) execHyperKit() error { if err != nil { return err } + } else { + // Make sure we reap the child when it exits + go cmd.Wait() } return nil } @@ -478,31 +470,6 @@ func stream(r io.ReadCloser, dest chan<- string) { }() } -// Create a ISO with Userdata in the specified directory -func createUserDataISO(dir string, init string) (string, error) { - cfgName := filepath.Join(dir, "config") - isoName := cfgName + ".iso" - - if err := ioutil.WriteFile(cfgName, []byte(init), 0644); err != nil { - return "", err - } - - outfh, err := os.OpenFile(isoName, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644) - if err != nil { - return "", err - } - infh, err := os.Open(cfgName) - if err != nil { - return "", err - } - err = iso9660wrap.WriteFile(outfh, infh) - if err != nil { - return "", err - } - - return isoName, nil -} - // checkHyperKit tries to find and/or validate the path of hyperkit func checkHyperKit(hyperkit string) (string, error) { if hyperkit != "" {