1
0
Fork 0

feat: mount container volumes based on kernel info

master
dump_stack() 2023-05-14 21:39:41 +00:00
parent 42be5161d8
commit de5ebd6455
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 20 additions and 1 deletions

View File

@ -11,6 +11,8 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/user" "os/user"
"path"
"path/filepath"
"regexp" "regexp"
"strings" "strings"
"time" "time"
@ -117,6 +119,23 @@ func New(name string, timeout time.Duration) (c Container, err error) {
return return
} }
func NewFromKernelInfo(ki config.KernelInfo, timeout time.Duration) (
c Container, err error) {
c.name = ki.ContainerName
c.timeout = timeout
c.Log = log.With().
Str("container", c.name).
Logger()
c.Volumes.LibModules = path.Dir(ki.ModulesPath)
c.Volumes.Boot = path.Dir(ki.KernelPath)
c.Volumes.UsrSrc = filepath.Join(path.Dir(ki.KernelPath), "../usr/src")
return
}
func (c Container) Build(imagePath string) (output string, err error) { func (c Container) Build(imagePath string) (output string, err error) {
args := []string{"build"} args := []string{"build"}
args = append(args, "-t", c.name, imagePath) args = append(args, "-t", c.name, imagePath)

2
pew.go
View File

@ -270,7 +270,7 @@ func build(flog zerolog.Logger, tmp string, ka config.Artifact,
if ki.ContainerName != "" { if ki.ContainerName != "" {
var c container.Container var c container.Container
c, err = container.New(ki.ContainerName, dockerTimeout) c, err = container.NewFromKernelInfo(ki, dockerTimeout)
c.Log = flog c.Log = flog
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("container creation failure") log.Fatal().Err(err).Msg("container creation failure")