1
0

feat: implement global docker timeout

This commit is contained in:
dump_stack() 2023-05-22 14:41:00 +00:00
parent 2fe3103603
commit fa5d0adb39
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
6 changed files with 13 additions and 17 deletions

View File

@ -25,6 +25,8 @@ import (
var Runtime = "docker" var Runtime = "docker"
var Timeout = time.Hour
type Image struct { type Image struct {
Name string Name string
Distro distro.Distro Distro distro.Distro
@ -78,8 +80,6 @@ type Volume struct {
type Container struct { type Container struct {
name string name string
timeout time.Duration
Volumes []Volume Volumes []Volume
// Additional arguments // Additional arguments
@ -88,13 +88,12 @@ type Container struct {
Log zerolog.Logger Log zerolog.Logger
} }
func New(name string, timeout time.Duration) (c Container, err error) { func New(name string) (c Container, err error) {
c.Log = log.With(). c.Log = log.With().
Str("container", name). Str("container", name).
Logger() Logger()
c.name = name c.name = name
c.timeout = timeout
c.Volumes = append(c.Volumes, Volume{ c.Volumes = append(c.Volumes, Volume{
Src: config.Dir("volumes", name, "lib", "modules"), Src: config.Dir("volumes", name, "lib", "modules"),
@ -114,11 +113,10 @@ func New(name string, timeout time.Duration) (c Container, err error) {
return return
} }
func NewFromKernelInfo(ki config.KernelInfo, timeout time.Duration) ( func NewFromKernelInfo(ki config.KernelInfo) (
c Container, err error) { c Container, err error) {
c.name = ki.ContainerName c.name = ki.ContainerName
c.timeout = timeout
c.Log = log.With(). c.Log = log.With().
Str("container", c.name). Str("container", c.name).
@ -211,7 +209,7 @@ func (c Container) Run(workdir string, command string) (output string, err error
} }
cmd.Stderr = cmd.Stdout cmd.Stderr = cmd.Stdout
timer := time.AfterFunc(c.timeout, func() { timer := time.AfterFunc(Timeout, func() {
flog.Info().Msg("killing container by timeout") flog.Info().Msg("killing container by timeout")
flog.Debug().Msg("SIGINT") flog.Debug().Msg("SIGINT")

View File

@ -3,7 +3,6 @@ package centos
import ( import (
"fmt" "fmt"
"strings" "strings"
"time"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -43,7 +42,7 @@ func (centos CentOS) Equal(d distro.Distro) bool {
} }
func (centos CentOS) Packages() (pkgs []string, err error) { func (centos CentOS) Packages() (pkgs []string, err error) {
c, err := container.New(centos.container, time.Hour) c, err := container.New(centos.container)
if err != nil { if err != nil {
return return
} }

View File

@ -3,7 +3,6 @@ package oraclelinux
import ( import (
"fmt" "fmt"
"strings" "strings"
"time"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -43,7 +42,7 @@ func (ol OracleLinux) Equal(d distro.Distro) bool {
} }
func (ol OracleLinux) Packages() (pkgs []string, err error) { func (ol OracleLinux) Packages() (pkgs []string, err error) {
c, err := container.New(ol.container, time.Hour) c, err := container.New(ol.container)
if err != nil { if err != nil {
return return
} }

View File

@ -3,7 +3,6 @@ package ubuntu
import ( import (
"fmt" "fmt"
"strings" "strings"
"time"
"code.dumpstack.io/tools/out-of-tree/config" "code.dumpstack.io/tools/out-of-tree/config"
"code.dumpstack.io/tools/out-of-tree/container" "code.dumpstack.io/tools/out-of-tree/container"
@ -49,7 +48,7 @@ func (u Ubuntu) Equal(d distro.Distro) bool {
} }
func (u Ubuntu) Packages() (pkgs []string, err error) { func (u Ubuntu) Packages() (pkgs []string, err error) {
c, err := container.New(u.container, time.Hour) c, err := container.New(u.container)
if err != nil { if err != nil {
return return
} }

View File

@ -163,7 +163,7 @@ func GenerateBaseDockerImage(registry string, commands []config.DockerCommand,
return return
} }
c, err := container.New(sk.DockerName(), time.Hour) c, err := container.New(sk.DockerName())
if err != nil { if err != nil {
return return
} }
@ -189,7 +189,7 @@ func installKernel(sk config.Target, pkgname string, force, headers bool) (err e
Str("pkg", pkgname). Str("pkg", pkgname).
Logger() Logger()
c, err := container.New(sk.DockerName(), time.Hour) // TODO conf c, err := container.New(sk.DockerName()) // TODO conf
if err != nil { if err != nil {
return return
} }
@ -407,7 +407,7 @@ func listContainersKernels(dii container.Image, newkcfg *config.KernelConfig,
return return
} }
c, err := container.New(dii.Name, time.Hour) c, err := container.New(dii.Name)
if err != nil { if err != nil {
return return
} }

3
pew.go
View File

@ -289,7 +289,8 @@ 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.NewFromKernelInfo(ki, dockerTimeout) container.Timeout = dockerTimeout
c, err = container.NewFromKernelInfo(ki)
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")