Install the kernel in a single container run
This commit is contained in:
parent
a4f2a31819
commit
e35e030c54
71
kernel.go
71
kernel.go
@ -389,17 +389,10 @@ func generateBaseDockerImage(registry string, commands []config.DockerCommand,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (err error) {
|
func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (err error) {
|
||||||
tmpdir, err := os.MkdirTemp(tempDirBase, "out-of-tree-"+pkgname+"-")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("make tmp directory")
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
|
|
||||||
slog := log.With().
|
slog := log.With().
|
||||||
Str("distro_type", sk.DistroType.String()).
|
Str("distro_type", sk.DistroType.String()).
|
||||||
Str("distro_release", sk.DistroRelease).
|
Str("distro_release", sk.DistroRelease).
|
||||||
Str("pkg", pkgname).
|
Str("pkg", pkgname).
|
||||||
Str("tmpdir", tmpdir).
|
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
c, err := NewContainer(sk.DockerName(), time.Hour) // TODO conf
|
c, err := NewContainer(sk.DockerName(), time.Hour) // TODO conf
|
||||||
@ -425,17 +418,14 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
|
|||||||
|
|
||||||
volumes := c.Volumes
|
volumes := c.Volumes
|
||||||
|
|
||||||
c.Volumes.LibModules = fmt.Sprintf("%s/libmodules", tmpdir)
|
c.Volumes.LibModules = ""
|
||||||
os.MkdirAll(c.Volumes.LibModules, 0777)
|
c.Volumes.UsrSrc = ""
|
||||||
|
c.Volumes.Boot = ""
|
||||||
c.Volumes.UsrSrc = fmt.Sprintf("%s/usrsrc", tmpdir)
|
|
||||||
os.MkdirAll(c.Volumes.UsrSrc, 0777)
|
|
||||||
|
|
||||||
c.Volumes.Boot = fmt.Sprintf("%s/boot", tmpdir)
|
|
||||||
os.MkdirAll(c.Volumes.Boot, 0777)
|
|
||||||
|
|
||||||
slog.Debug().Msgf("Installing kernel")
|
slog.Debug().Msgf("Installing kernel")
|
||||||
|
|
||||||
|
cmd := "true"
|
||||||
|
|
||||||
switch sk.DistroType {
|
switch sk.DistroType {
|
||||||
case config.Ubuntu:
|
case config.Ubuntu:
|
||||||
var headerspkg string
|
var headerspkg string
|
||||||
@ -443,12 +433,7 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
|
|||||||
headerspkg = strings.Replace(pkgname, "image", "headers", -1)
|
headerspkg = strings.Replace(pkgname, "image", "headers", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := fmt.Sprintf("apt-get install -y %s %s", pkgname, headerspkg)
|
cmd += fmt.Sprintf(" && apt-get install -y %s %s", pkgname, headerspkg)
|
||||||
|
|
||||||
_, err = c.Run(tempDirBase, cmd)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case config.CentOS:
|
case config.CentOS:
|
||||||
imagepkg := strings.Replace(pkgname, "-devel", "", -1)
|
imagepkg := strings.Replace(pkgname, "-devel", "", -1)
|
||||||
|
|
||||||
@ -457,19 +442,11 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
|
|||||||
if !headers {
|
if !headers {
|
||||||
pkgname = ""
|
pkgname = ""
|
||||||
}
|
}
|
||||||
cmd := fmt.Sprintf("yum -y install %s %s\n", imagepkg,
|
cmd += fmt.Sprintf(" && yum -y install %s %s", imagepkg,
|
||||||
pkgname)
|
pkgname)
|
||||||
_, err = c.Run(tempDirBase, cmd)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = fmt.Sprintf("dracut --add-drivers 'e1000 ext4' -f "+
|
cmd += fmt.Sprintf(" && dracut --add-drivers 'e1000 ext4' -f "+
|
||||||
"/boot/initramfs-%s.img %s\n", version, version)
|
"/boot/initramfs-%s.img %s", version, version)
|
||||||
_, err = c.Run(tempDirBase, cmd)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("%s not yet supported", sk.DistroType.String())
|
err = fmt.Errorf("%s not yet supported", sk.DistroType.String())
|
||||||
return
|
return
|
||||||
@ -479,33 +456,11 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
|
|||||||
c.Args = append(c.Args, "-v", volumes.UsrSrc+":/target/usr/src")
|
c.Args = append(c.Args, "-v", volumes.UsrSrc+":/target/usr/src")
|
||||||
c.Args = append(c.Args, "-v", volumes.Boot+":/target/boot")
|
c.Args = append(c.Args, "-v", volumes.Boot+":/target/boot")
|
||||||
|
|
||||||
cmd := "true"
|
cmd += " && cp -r /boot /target/"
|
||||||
|
cmd += " && cp -r /lib/modules /target/lib/"
|
||||||
|
cmd += " && cp -r /usr/src /target/usr/"
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(c.Volumes.Boot)
|
_, err = c.Run("", cmd)
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(files) != 0 {
|
|
||||||
cmd += " && cp -r /boot/* /target/boot/"
|
|
||||||
}
|
|
||||||
|
|
||||||
files, err = ioutil.ReadDir(c.Volumes.LibModules)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(files) != 0 {
|
|
||||||
cmd += " && cp -r /lib/modules/* /target/lib/modules/"
|
|
||||||
}
|
|
||||||
|
|
||||||
files, err = ioutil.ReadDir(c.Volumes.UsrSrc)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(files) != 0 {
|
|
||||||
cmd += " && cp -r /usr/src/* /target/usr/src/"
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = c.Run(tempDirBase, cmd)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user