common/embed: replace all go:embed use by an embedded archive

Some of the files were quite big:

- asns.csv ~ 3 MB
- index.js ~ 1.5 MB
- *.svg ~ 2 MB

Use a ZIP archive to put them all and embed it. This reduce the binary
size from 89 MB to 82 MB. 🤯

This also pulls some code modernization (use of http.ServeFileFS).
This commit is contained in:
Vincent Bernat
2025-09-02 23:30:20 +02:00
parent d102e5f20e
commit b1d6382585
13 changed files with 107 additions and 47 deletions

View File

@@ -19,6 +19,7 @@ import (
"akvorado/common/clickhousedb"
"akvorado/common/daemon"
"akvorado/common/embed"
"akvorado/common/httpserver"
"akvorado/common/reporter"
"akvorado/common/schema"
@@ -138,14 +139,14 @@ func (c *Component) Stop() error {
// embedOrLiveFS returns a subset of the provided embedded filesystem,
// except if the component is configured to use the live filesystem.
// Then, it returns the provided tree.
func (c *Component) embedOrLiveFS(embed fs.FS, p string) fs.FS {
func (c *Component) embedOrLiveFS(prefix string) fs.FS {
var fileSystem fs.FS
if c.config.ServeLiveFS {
_, src, _, _ := runtime.Caller(0)
fileSystem = os.DirFS(filepath.Join(path.Dir(src), p))
fileSystem = os.DirFS(filepath.Join(path.Dir(src), prefix))
} else {
var err error
fileSystem, err = fs.Sub(embed, p)
fileSystem, err = fs.Sub(embed.Data(), path.Join("console", prefix))
if err != nil {
panic(err)
}