refactor: rename debian functions to common interface
This commit is contained in:
parent
90f7e62888
commit
99c9346995
@ -111,7 +111,7 @@ func kernelRelease(deb string) (r Release, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func MatchImagePkg(km config.KernelMask) (pkgs []string, err error) {
|
||||
func Match(km config.KernelMask) (pkgs []string, err error) {
|
||||
kernels, err := GetKernels()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("get kernels")
|
||||
@ -143,7 +143,7 @@ func MatchImagePkg(km config.KernelMask) (pkgs []string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func ContainerEnvs(km config.KernelMask) (envs []string) {
|
||||
func Envs(km config.KernelMask) (envs []string) {
|
||||
envs = append(envs, "DEBIAN_FRONTEND=noninteractive")
|
||||
return
|
||||
}
|
||||
@ -196,7 +196,7 @@ func repositories(release Release) (repos []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func ContainerCommands(km config.KernelMask) (commands []string) {
|
||||
func Runs(km config.KernelMask) (commands []string) {
|
||||
release := releaseFromString(km.DistroRelease)
|
||||
|
||||
cmdf := func(f string, s ...interface{}) {
|
||||
@ -307,7 +307,7 @@ func ContainerKernels(d container.Image, kcfg *config.KernelConfig) (err error)
|
||||
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)
|
||||
|
||||
volumes.LibModules = config.Dir(pkgdir, "/lib/modules")
|
||||
@ -317,7 +317,7 @@ func ContainerVolumes(km config.KernelMask, pkgname string) (volumes container.V
|
||||
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")
|
||||
if err != nil {
|
||||
return
|
||||
@ -353,7 +353,7 @@ func InstallCommands(km config.KernelMask, pkgname string, headers bool) (cmds [
|
||||
return
|
||||
}
|
||||
|
||||
func CleanupFailed(km config.KernelMask, pkgname string) {
|
||||
func Cleanup(km config.KernelMask, pkgname string) {
|
||||
pkgdir := config.Dir(filepath.Join("volumes", km.DockerName(), pkgname))
|
||||
|
||||
log.Debug().Msgf("cleanup %s", pkgdir)
|
||||
|
@ -31,13 +31,14 @@ import (
|
||||
)
|
||||
|
||||
func MatchPackages(km config.KernelMask) (pkgs []string, err error) {
|
||||
// TODO interface for kernels match
|
||||
switch km.DistroType {
|
||||
case config.Ubuntu:
|
||||
pkgs, err = ubuntu.Match(km)
|
||||
case config.OracleLinux, config.CentOS:
|
||||
pkgs, err = oraclelinux.Match(km)
|
||||
case config.Debian:
|
||||
pkgs, err = debian.MatchImagePkg(km)
|
||||
pkgs, err = debian.Match(km)
|
||||
default:
|
||||
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"
|
||||
}
|
||||
case config.Debian:
|
||||
for _, e := range debian.ContainerEnvs(sk) {
|
||||
for _, e := range debian.Envs(sk) {
|
||||
d += "ENV " + e + "\n"
|
||||
}
|
||||
for _, c := range debian.ContainerCommands(sk) {
|
||||
for _, c := range debian.Runs(sk) {
|
||||
d += "RUN " + c + "\n"
|
||||
}
|
||||
default:
|
||||
@ -211,7 +212,7 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
|
||||
if sk.DistroType == config.Debian {
|
||||
// Debian has different kernels (package version) by the
|
||||
// same name (ABI), so we need to separate /boot
|
||||
c.Volumes = debian.ContainerVolumes(sk, pkgname)
|
||||
c.Volumes = debian.Volumes(sk, pkgname)
|
||||
}
|
||||
|
||||
volumes := c.Volumes
|
||||
@ -263,13 +264,13 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
|
||||
}
|
||||
case config.Debian:
|
||||
var commands []string
|
||||
commands, err = debian.InstallCommands(sk, pkgname, headers)
|
||||
commands, err = debian.Install(sk, pkgname, headers)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
debian.CleanupFailed(sk, pkgname)
|
||||
debian.Cleanup(sk, pkgname)
|
||||
}
|
||||
}()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user