diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-06-28 12:32:30 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-06-28 13:42:07 +0200 |
| commit | 68ce63c46891becd752fa1c0a0c3caaa98117832 (patch) | |
| tree | e425345a35ae428fb756efc0f66eee8893b04fd2 /pkg/instance/instance.go | |
| parent | e502f1a6dfee2bd1716d838340b1584c05d29b60 (diff) | |
pkg/build: support fuchsia builds
Diffstat (limited to 'pkg/instance/instance.go')
| -rw-r--r-- | pkg/instance/instance.go | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go index 79616f3fa..556208876 100644 --- a/pkg/instance/instance.go +++ b/pkg/instance/instance.go @@ -7,6 +7,7 @@ package instance import ( "bytes" + "encoding/json" "fmt" "net" "os" @@ -85,9 +86,42 @@ func (env *Env) BuildKernel(compilerBin, userspaceDir, cmdlineFile, sysctlFile s cmdlineFile, sysctlFile, kernelConfig); err != nil { return err } + return SetConfigImage(cfg, imageDir) +} + +func SetConfigImage(cfg *mgrconfig.Config, imageDir string) error { cfg.KernelObj = filepath.Join(imageDir, "obj") cfg.Image = filepath.Join(imageDir, "image") - cfg.SSHKey = filepath.Join(imageDir, "key") + if keyFile := filepath.Join(imageDir, "key"); osutil.IsExist(keyFile) { + cfg.SSHKey = keyFile + } + if cfg.Type == "qemu" { + kernel := filepath.Join(imageDir, "kernel") + if !osutil.IsExist(kernel) { + kernel = "" + } + initrd := filepath.Join(imageDir, "initrd") + if !osutil.IsExist(initrd) { + initrd = "" + } + if kernel != "" || initrd != "" { + qemu := make(map[string]interface{}) + if err := json.Unmarshal(cfg.VM, &qemu); err != nil { + return fmt.Errorf("failed to parse qemu config: %v", err) + } + if kernel != "" { + qemu["kernel"] = kernel + } + if initrd != "" { + qemu["initrd"] = initrd + } + vmCfg, err := json.Marshal(qemu) + if err != nil { + return fmt.Errorf("failed to serialize qemu config: %v", err) + } + cfg.VM = vmCfg + } + } return nil } |
