1
0

refactor: rename debian functions to common interface

This commit is contained in:
dump_stack() 2023-05-18 11:34:46 +00:00
parent 90f7e62888
commit 99c9346995
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 13 additions and 12 deletions

View File

@ -111,7 +111,7 @@ func kernelRelease(deb string) (r Release, err error) {
return return
} }
func MatchImagePkg(km config.KernelMask) (pkgs []string, err error) { func Match(km config.KernelMask) (pkgs []string, err error) {
kernels, err := GetKernels() kernels, err := GetKernels()
if err != nil { if err != nil {
log.Error().Err(err).Msg("get kernels") log.Error().Err(err).Msg("get kernels")
@ -143,7 +143,7 @@ func MatchImagePkg(km config.KernelMask) (pkgs []string, err error) {
return return
} }
func ContainerEnvs(km config.KernelMask) (envs []string) { func Envs(km config.KernelMask) (envs []string) {
envs = append(envs, "DEBIAN_FRONTEND=noninteractive") envs = append(envs, "DEBIAN_FRONTEND=noninteractive")
return return
} }
@ -196,7 +196,7 @@ func repositories(release Release) (repos []string) {
return return
} }
func ContainerCommands(km config.KernelMask) (commands []string) { func Runs(km config.KernelMask) (commands []string) {
release := releaseFromString(km.DistroRelease) release := releaseFromString(km.DistroRelease)
cmdf := func(f string, s ...interface{}) { cmdf := func(f string, s ...interface{}) {
@ -307,7 +307,7 @@ func ContainerKernels(d container.Image, kcfg *config.KernelConfig) (err error)
return return
} }
func ContainerVolumes(km config.KernelMask, pkgname string) (volumes container.Volumes) { func Volumes(km config.KernelMask, pkgname string) (volumes container.Volumes) {
pkgdir := filepath.Join("volumes", km.DockerName(), pkgname) pkgdir := filepath.Join("volumes", km.DockerName(), pkgname)
volumes.LibModules = config.Dir(pkgdir, "/lib/modules") volumes.LibModules = config.Dir(pkgdir, "/lib/modules")
@ -317,7 +317,7 @@ func ContainerVolumes(km config.KernelMask, pkgname string) (volumes container.V
return return
} }
func InstallCommands(km config.KernelMask, pkgname string, headers bool) (cmds []string, err error) { func Install(km config.KernelMask, pkgname string, headers bool) (cmds []string, err error) {
dk, err := getCachedKernel(pkgname + ".deb") dk, err := getCachedKernel(pkgname + ".deb")
if err != nil { if err != nil {
return return
@ -353,7 +353,7 @@ func InstallCommands(km config.KernelMask, pkgname string, headers bool) (cmds [
return return
} }
func CleanupFailed(km config.KernelMask, pkgname string) { func Cleanup(km config.KernelMask, pkgname string) {
pkgdir := config.Dir(filepath.Join("volumes", km.DockerName(), pkgname)) pkgdir := config.Dir(filepath.Join("volumes", km.DockerName(), pkgname))
log.Debug().Msgf("cleanup %s", pkgdir) log.Debug().Msgf("cleanup %s", pkgdir)

View File

@ -31,13 +31,14 @@ import (
) )
func MatchPackages(km config.KernelMask) (pkgs []string, err error) { func MatchPackages(km config.KernelMask) (pkgs []string, err error) {
// TODO interface for kernels match
switch km.DistroType { switch km.DistroType {
case config.Ubuntu: case config.Ubuntu:
pkgs, err = ubuntu.Match(km) pkgs, err = ubuntu.Match(km)
case config.OracleLinux, config.CentOS: case config.OracleLinux, config.CentOS:
pkgs, err = oraclelinux.Match(km) pkgs, err = oraclelinux.Match(km)
case config.Debian: case config.Debian:
pkgs, err = debian.MatchImagePkg(km) pkgs, err = debian.Match(km)
default: default:
err = fmt.Errorf("%s not yet supported", km.DistroType.String()) err = fmt.Errorf("%s not yet supported", km.DistroType.String())
} }
@ -136,10 +137,10 @@ func GenerateBaseDockerImage(registry string, commands []config.DockerCommand,
d += "RUN " + c + "\n" d += "RUN " + c + "\n"
} }
case config.Debian: case config.Debian:
for _, e := range debian.ContainerEnvs(sk) { for _, e := range debian.Envs(sk) {
d += "ENV " + e + "\n" d += "ENV " + e + "\n"
} }
for _, c := range debian.ContainerCommands(sk) { for _, c := range debian.Runs(sk) {
d += "RUN " + c + "\n" d += "RUN " + c + "\n"
} }
default: default:
@ -211,7 +212,7 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
if sk.DistroType == config.Debian { if sk.DistroType == config.Debian {
// Debian has different kernels (package version) by the // Debian has different kernels (package version) by the
// same name (ABI), so we need to separate /boot // same name (ABI), so we need to separate /boot
c.Volumes = debian.ContainerVolumes(sk, pkgname) c.Volumes = debian.Volumes(sk, pkgname)
} }
volumes := c.Volumes volumes := c.Volumes
@ -263,13 +264,13 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
} }
case config.Debian: case config.Debian:
var commands []string var commands []string
commands, err = debian.InstallCommands(sk, pkgname, headers) commands, err = debian.Install(sk, pkgname, headers)
if err != nil { if err != nil {
return return
} }
defer func() { defer func() {
if err != nil { if err != nil {
debian.CleanupFailed(sk, pkgname) debian.Cleanup(sk, pkgname)
} }
}() }()