Add command to populate debian cache
This commit is contained in:
parent
26c261b6f3
commit
da6843f9b7
59
debian.go
Normal file
59
debian.go
Normal 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
|
||||||
|
}
|
1
main.go
1
main.go
@ -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"`
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user