compress initrds with zstd

This commit is contained in:
Mikaël Cluseau
2025-07-21 17:37:29 +02:00
parent 899a0a9dab
commit af2758dead
3 changed files with 21 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import (
"net/http"
"os"
"github.com/klauspost/compress/zstd"
yaml "gopkg.in/yaml.v2"
"novit.tech/direktil/pkg/cpiocat"
@ -39,7 +40,12 @@ func buildInitrd(out io.Writer, ctx *renderContext) (err error) {
return
}
cat := cpiocat.New(out)
zout, err := zstd.NewWriter(out, zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(12)))
if err != nil {
return fmt.Errorf("zstd writer setup failed: %w", err)
}
cat := cpiocat.New(zout)
// initrd
initrdPath, err := distFetch("initrd", ctx.Host.Initrd)
@ -88,7 +94,15 @@ func buildInitrd(out io.Writer, ctx *renderContext) (err error) {
cat.AppendBytes(userCA, "user_ca.pub", 0600)
return cat.Close()
if err = cat.Close(); err != nil {
return fmt.Errorf("cpio close failed: %w", err)
}
if err = zout.Close(); err != nil {
return fmt.Errorf("zstd close failed: %w", err)
}
return
}
func buildBootstrap(out io.Writer, ctx *renderContext) (err error) {