mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 19:05:37 +00:00
Add VHD and GCE output formats
- VHD is uncompressed VHD. Currently hard coded at 1GB, which may need to change. Use `format: vhd` - GCE is the GCE compressed tarred raw image. Use `format: gce-img` - reserving `gce` for actually uploading the image. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
3fa9192f56
commit
64d388d3fe
49
output.go
49
output.go
@ -11,6 +11,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
bios = "mobylinux/mkimage-iso-bios:489b1f054a77a8f379d0bfc6cd91639b4db6b67c@sha256:0f058951aac4367d132682aa19eeb5cdcb05600a5d51fe5d0fcbd97b03ae4f87"
|
bios = "mobylinux/mkimage-iso-bios:489b1f054a77a8f379d0bfc6cd91639b4db6b67c@sha256:0f058951aac4367d132682aa19eeb5cdcb05600a5d51fe5d0fcbd97b03ae4f87"
|
||||||
efi = "mobylinux/mkimage-iso-efi:b210c58e096e53082d35b28fa2b52dba6ae200c8@sha256:10c2789bf5fbd27c35c5fe2f3b97f75a7108bbde389d0f5ed750e3e2dae95376"
|
efi = "mobylinux/mkimage-iso-efi:b210c58e096e53082d35b28fa2b52dba6ae200c8@sha256:10c2789bf5fbd27c35c5fe2f3b97f75a7108bbde389d0f5ed750e3e2dae95376"
|
||||||
|
gce = "mobylinux/mkimage-gce:2039be4e39e855d1845aee188e266bba3f1d2eed@sha256:e12f76003fd9eaa0c6f39f149db5998cf56de42539b989c994893c8344ca69c0"
|
||||||
|
vhd = "mobylinux/mkimage-vhd:73c80e433bf717578c507621a84fd58cec27fe95@sha256:0ae1eda2d6592f309977dc4b25cca120cc4e2ee2cc786e88fdc2761c0d49cb14"
|
||||||
)
|
)
|
||||||
|
|
||||||
func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
|
func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
|
||||||
@ -31,6 +33,16 @@ func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
||||||
}
|
}
|
||||||
|
case "gce-img":
|
||||||
|
err := outputImg(gce, base+".img.tar.gz", bzimage, initrd, m.Kernel.Cmdline)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
||||||
|
}
|
||||||
|
case "vhd":
|
||||||
|
err := outputImg(vhd, base+".vhd", bzimage, initrd, m.Kernel.Cmdline)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
||||||
|
}
|
||||||
case "":
|
case "":
|
||||||
return fmt.Errorf("No format specified for output")
|
return fmt.Errorf("No format specified for output")
|
||||||
default:
|
default:
|
||||||
@ -40,9 +52,7 @@ func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add kernel command line
|
func tarInitrdKernel(bzimage, initrd []byte) (*bytes.Buffer, error) {
|
||||||
func outputISO(image, filename string, bzimage []byte, initrd []byte, args ...string) error {
|
|
||||||
// first build the input tarball from kernel and initrd
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
tw := tar.NewWriter(buf)
|
tw := tar.NewWriter(buf)
|
||||||
hdr := &tar.Header{
|
hdr := &tar.Header{
|
||||||
@ -52,11 +62,11 @@ func outputISO(image, filename string, bzimage []byte, initrd []byte, args ...st
|
|||||||
}
|
}
|
||||||
err := tw.WriteHeader(hdr)
|
err := tw.WriteHeader(hdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return buf, err
|
||||||
}
|
}
|
||||||
_, err = tw.Write(bzimage)
|
_, err = tw.Write(bzimage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return buf, err
|
||||||
}
|
}
|
||||||
hdr = &tar.Header{
|
hdr = &tar.Header{
|
||||||
Name: "initrd.img",
|
Name: "initrd.img",
|
||||||
@ -65,13 +75,38 @@ func outputISO(image, filename string, bzimage []byte, initrd []byte, args ...st
|
|||||||
}
|
}
|
||||||
err = tw.WriteHeader(hdr)
|
err = tw.WriteHeader(hdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return buf, err
|
||||||
}
|
}
|
||||||
_, err = tw.Write(initrd)
|
_, err = tw.Write(initrd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return buf, err
|
||||||
}
|
}
|
||||||
err = tw.Close()
|
err = tw.Close()
|
||||||
|
if err != nil {
|
||||||
|
return buf, err
|
||||||
|
}
|
||||||
|
return buf, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func outputImg(image, filename string, bzimage []byte, initrd []byte, args ...string) error {
|
||||||
|
buf, err := tarInitrdKernel(bzimage, initrd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
img, err := dockerRunInput(buf, append([]string{image}, args...)...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(filename, img, os.FileMode(0644))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println(filename)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func outputISO(image, filename string, bzimage []byte, initrd []byte, args ...string) error {
|
||||||
|
buf, err := tarInitrdKernel(bzimage, initrd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user