From 7f331cb9c62a8e45fbd95e17b9731ef71170fec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Thu, 15 Nov 2018 18:07:10 +1100 Subject: [PATCH] boot.img: more compression options --- cmd/dkl-local-server/boot-img.go | 23 +++++++++++++++++++++-- cmd/dkl-local-server/http.go | 8 +++++++- cmd/dkl-local-server/initrd.go | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cmd/dkl-local-server/boot-img.go b/cmd/dkl-local-server/boot-img.go index b63c54e..658fe94 100644 --- a/cmd/dkl-local-server/boot-img.go +++ b/cmd/dkl-local-server/boot-img.go @@ -2,6 +2,7 @@ package main import ( "archive/tar" + "compress/gzip" "io" "io/ioutil" "log" @@ -40,11 +41,29 @@ func buildBootImg(out io.Writer, ctx *renderContext) (err error) { // send the result bootImg.Seek(0, os.SEEK_SET) + io.Copy(out, bootImg) + return +} +func buildBootImgLZ4(out io.Writer, ctx *renderContext) (err error) { lz4Out := lz4.NewWriter(out) - io.Copy(lz4Out, bootImg) - lz4Out.Close() + if err = buildBootImg(lz4Out, ctx); err != nil { + return + } + + lz4Out.Close() + return +} + +func buildBootImgGZ(out io.Writer, ctx *renderContext) (err error) { + gzOut := gzip.NewWriter(out) + + if err = buildBootImg(gzOut, ctx); err != nil { + return + } + + gzOut.Close() return } diff --git a/cmd/dkl-local-server/http.go b/cmd/dkl-local-server/http.go index 624d7b4..1b8f360 100644 --- a/cmd/dkl-local-server/http.go +++ b/cmd/dkl-local-server/http.go @@ -165,9 +165,15 @@ func renderHost(w http.ResponseWriter, r *http.Request, what string, host *clust case "boot.tar": err = renderCtx(w, r, ctx, "boot.tar", buildBootTar) - case "boot.img.lz4": + case "boot.img": err = renderCtx(w, r, ctx, what, buildBootImg) + case "boot.img.gz": + err = renderCtx(w, r, ctx, what, buildBootImgGZ) + + case "boot.img.lz4": + err = renderCtx(w, r, ctx, what, buildBootImgLZ4) + case "config": err = renderConfig(w, r, ctx) diff --git a/cmd/dkl-local-server/initrd.go b/cmd/dkl-local-server/initrd.go index a5e5a2d..838daa9 100644 --- a/cmd/dkl-local-server/initrd.go +++ b/cmd/dkl-local-server/initrd.go @@ -46,6 +46,7 @@ func renderStaticPods(w http.ResponseWriter, r *http.Request, ctx *renderContext return nil } +// TODO move somewhere logical func renderCtx(w http.ResponseWriter, r *http.Request, ctx *renderContext, what string, create func(out io.Writer, ctx *renderContext) error) error { log.Printf("sending %s for %q", what, ctx.Host.Name)