1
0

Add command to populate debian cache

This commit is contained in:
dump_stack() 2023-05-11 20:08:08 +00:00
parent 26c261b6f3
commit da6843f9b7
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 60 additions and 0 deletions

59
debian.go Normal file
View File

@ -0,0 +1,59 @@
package main
import (
"github.com/rs/zerolog/log"
"code.dumpstack.io/tools/out-of-tree/distro/debian"
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
)
type DebianCmd struct {
Cache DebianCacheCmd `cmd:"" help:"populate cache"`
}
type DebianCacheCmd struct {
Path string `help:"path to cache" default:"debian.cache"`
}
func (cmd *DebianCacheCmd) Run() (err error) {
c, err := debian.NewCache(cmd.Path)
if err != nil {
log.Error().Err(err).Msg("cache")
return
}
defer c.Close()
versions, err := snapshot.SourcePackageVersions("linux")
if err != nil {
log.Error().Err(err).Msg("get source package versions")
return
}
for i, version := range versions {
slog := log.With().Str("version", version).Logger()
slog.Info().Msgf("%03d/%03d", i, len(versions))
_, err = c.Get(version)
if err == nil {
slog.Info().Msgf("found in cache")
continue
}
var dk debian.DebianKernel
dk, err = debian.GetDebianKernel(version)
if err != nil {
slog.Error().Err(err).Msg("get debian kernel")
continue
}
err = c.Put(dk)
if err != nil {
slog.Error().Err(err).Msg("put to cache")
return
}
slog.Info().Msgf("%s cached", version)
}
return
}

View File

@ -42,6 +42,7 @@ type CLI struct {
Gen GenCmd `cmd:"" help:"generate .out-of-tree.toml skeleton"` Gen GenCmd `cmd:"" help:"generate .out-of-tree.toml skeleton"`
Image ImageCmd `cmd:"" help:"manage images"` Image ImageCmd `cmd:"" help:"manage images"`
Container ContainerCmd `cmd:"" help:"manage containers"` Container ContainerCmd `cmd:"" help:"manage containers"`
Debian DebianCmd `cmd:"" help:"" hidden:""`
Version VersionFlag `name:"version" help:"print version information and quit"` Version VersionFlag `name:"version" help:"print version information and quit"`