infrakit: Write ISO file from instance init contents

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer
2017-03-10 14:24:18 +00:00
parent edcb5a8e83
commit cde6fb9309
8 changed files with 651 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ import (
log "github.com/Sirupsen/logrus"
ps "github.com/mitchellh/go-ps"
"github.com/rneugeba/iso9660wrap"
"github.com/docker/infrakit/pkg/spi/instance"
"github.com/docker/infrakit/pkg/template"
@@ -91,7 +92,7 @@ func (v hyperkitPlugin) Provision(spec instance.Spec) (*instance.ID, error) {
"Properties": properties,
}
err = v.execHyperKit(params)
err = v.execHyperKit(spec, params)
if err != nil {
v.Destroy(id)
return nil, err
@@ -247,7 +248,7 @@ const hyperkitKernArgs = "kexec," +
"{{.Properties.Moby}}-initrd.img," +
"earlyprintk=serial console=ttyS0 panic=1 vsyscall=emulate page_poison=1 ntp=gateway"
func (v hyperkitPlugin) execHyperKit(params map[string]interface{}) error {
func (v hyperkitPlugin) execHyperKit(spec instance.Spec, params map[string]interface{}) error {
instanceDir := params["VMLocation"].(string)
@@ -280,6 +281,13 @@ func (v hyperkitPlugin) execHyperKit(params map[string]interface{}) error {
return err
}
if len(spec.Init) != 0 {
err = createConfigISO(instanceDir, spec.Init)
if err != nil {
return err
}
}
cmd := exec.Command(c[0], c[1:]...)
cmd.Env = os.Environ()
@@ -338,6 +346,29 @@ func createDisk(instanceDir string, diskSz int) error {
return nil
}
func createConfigISO(instanceDir, init string) error {
inName := path.Join(instanceDir, "config")
if err := ioutil.WriteFile(inName, []byte(init), 0666); err != nil {
return err
}
outfh, err := os.OpenFile(inName+".iso", os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0666)
if err != nil {
return err
}
infh, err := os.Open(inName)
if err != nil {
return err
}
err = iso9660wrap.WriteFile(outfh, infh)
if err != nil {
log.Fatalf("writing file failed with %s", err)
}
return nil
}
func stream(r io.ReadCloser, dest chan<- string) {
go func() {
defer r.Close()