1
0

Fix check for installed kernels

This commit is contained in:
dump_stack() 2023-03-22 18:05:13 +00:00
parent 3e9410bf09
commit 0f1bdc795d
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 23 additions and 15 deletions

View File

@ -211,7 +211,7 @@ func generateBaseDockerImage(registry string, commands []config.DockerCommand,
d := "# BASE\n" d := "# BASE\n"
cmd := exec.Command("docker", "images", "-q", sk.DockerName()) cmd := exec.Command("docker", "images", "-q", sk.DockerName())
log.Debug().Msgf("%v", cmd) log.Debug().Msgf("run %v", cmd)
rawOutput, err := cmd.CombinedOutput() rawOutput, err := cmd.CombinedOutput()
if err != nil { if err != nil {
@ -334,25 +334,36 @@ func generateBaseDockerImage(registry string, commands []config.DockerCommand,
} }
func installKernel(sk config.KernelMask, pkgname string) (err error) { func installKernel(sk config.KernelMask, pkgname string) (err error) {
slog := log.With().
Str("distro_type", sk.DistroType.String()).
Str("distro_release", sk.DistroRelease).
Str("pkg", pkgname).
Logger()
c, err := NewContainer(sk.DockerName(), time.Hour) // TODO conf c, err := NewContainer(sk.DockerName(), time.Hour) // TODO conf
if err != nil { if err != nil {
return return
} }
if exists(c.Volumes.LibModules + "/" + sk.ReleaseMask) { moddirs, err := ioutil.ReadDir(c.Volumes.LibModules)
// already installed kernel if err != nil {
log.Info().Msgf("kernel %s for %s:%s is already exists",
pkgname, sk.DistroType.String(), sk.DistroRelease)
return return
} }
for _, krel := range moddirs {
if strings.Contains(pkgname, krel.Name()) {
// already installed kernel
slog.Info().Msg("Already installed")
return
}
}
slog.Info().Msgf("Installing kernel")
switch sk.DistroType { switch sk.DistroType {
case config.Ubuntu: case config.Ubuntu:
imagepkg := strings.Replace(pkgname, "headers", "image", -1) imagepkg := strings.Replace(pkgname, "headers", "image", -1)
log.Info().Msgf("Start adding kernel %s for %s:%s",
imagepkg, sk.DistroType.String(), sk.DistroRelease)
cmd := fmt.Sprintf("apt-get install -y %s %s", imagepkg, cmd := fmt.Sprintf("apt-get install -y %s %s", imagepkg,
pkgname) pkgname)
@ -363,9 +374,6 @@ func installKernel(sk config.KernelMask, pkgname string) (err error) {
case config.CentOS: case config.CentOS:
imagepkg := strings.Replace(pkgname, "-devel", "", -1) imagepkg := strings.Replace(pkgname, "-devel", "", -1)
log.Info().Msgf("Start adding kernel %s for %s:%s",
imagepkg, sk.DistroType.String(), sk.DistroRelease)
version := strings.Replace(pkgname, "kernel-devel-", "", -1) version := strings.Replace(pkgname, "kernel-devel-", "", -1)
cmd := fmt.Sprintf("yum -y install %s %s\n", imagepkg, cmd := fmt.Sprintf("yum -y install %s %s\n", imagepkg,
@ -386,9 +394,7 @@ func installKernel(sk config.KernelMask, pkgname string) (err error) {
return return
} }
log.Info().Msgf("Add kernel %s for %s:%s success", slog.Info().Msgf("Success")
pkgname, sk.DistroType.String(), sk.DistroRelease)
return return
} }
@ -638,7 +644,7 @@ func generateKernels(km config.KernelMask, registry string,
break break
} }
log.Info().Msgf("%d/%d %s", i, len(pkgs), pkg) log.Info().Msgf("%d/%d %s", i+1, len(pkgs), pkg)
err = installKernel(km, pkg) err = installKernel(km, pkg)
if err == nil { if err == nil {

2
pew.go
View File

@ -679,8 +679,10 @@ func performCI(ka config.Artifact, kcfg config.KernelConfig, binaryPath,
func exists(path string) bool { func exists(path string) bool {
if _, err := os.Stat(path); err != nil { if _, err := os.Stat(path); err != nil {
log.Debug().Msgf("%s does not exist", path)
return false return false
} }
log.Debug().Msgf("%s exist", path)
return true return true
} }