feat: multiple commands to run in container
This commit is contained in:
parent
e302c447f5
commit
c6e06d8e3e
@ -250,10 +250,10 @@ func (c Container) build(imagePath string) (output string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Container) Run(workdir string, command string) (output string, err error) {
|
func (c Container) Run(workdir string, cmds []string) (out string, err error) {
|
||||||
flog := c.Log.With().
|
flog := c.Log.With().
|
||||||
Str("workdir", workdir).
|
Str("workdir", workdir).
|
||||||
Str("command", command).
|
Str("command", fmt.Sprintf("%v", cmds)).
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
var args []string
|
var args []string
|
||||||
@ -268,6 +268,11 @@ func (c Container) Run(workdir string, command string) (output string, err error
|
|||||||
args = append(args, "-v", mount)
|
args = append(args, "-v", mount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command := "true"
|
||||||
|
for _, c := range cmds {
|
||||||
|
command += fmt.Sprintf(" && %s", c)
|
||||||
|
}
|
||||||
|
|
||||||
args = append(args, c.name, "bash", "-c")
|
args = append(args, c.name, "bash", "-c")
|
||||||
if workdir != "" {
|
if workdir != "" {
|
||||||
args = append(args, "cd /work && "+command)
|
args = append(args, "cd /work && "+command)
|
||||||
@ -307,7 +312,7 @@ func (c Container) Run(workdir string, command string) (output string, err error
|
|||||||
scanner := bufio.NewScanner(stdout)
|
scanner := bufio.NewScanner(stdout)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
m := scanner.Text()
|
m := scanner.Text()
|
||||||
output += m + "\n"
|
out += m + "\n"
|
||||||
flog.Trace().Str("stdout", m).Msg("")
|
flog.Trace().Str("stdout", m).Msg("")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -315,7 +320,7 @@ func (c Container) Run(workdir string, command string) (output string, err error
|
|||||||
err = cmd.Wait()
|
err = cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Sprintf("error `%v` for cmd `%v` with output `%v`",
|
e := fmt.Sprintf("error `%v` for cmd `%v` with output `%v`",
|
||||||
err, command, output)
|
err, cmds, out)
|
||||||
err = errors.New(e)
|
err = errors.New(e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -379,7 +384,7 @@ func (c Container) Kernels() (kernels []config.KernelInfo, err error) {
|
|||||||
for _, cmd := range []string{
|
for _, cmd := range []string{
|
||||||
"find /boot -type f -exec chmod a+r {} \\;",
|
"find /boot -type f -exec chmod a+r {} \\;",
|
||||||
} {
|
} {
|
||||||
_, err = c.Run(config.Dir("tmp"), cmd)
|
_, err = c.Run(config.Dir("tmp"), []string{cmd})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ func (centos CentOS) Packages() (pkgs []string, err error) {
|
|||||||
"| grep -v src " +
|
"| grep -v src " +
|
||||||
"| cut -d ' ' -f 1"
|
"| cut -d ' ' -f 1"
|
||||||
|
|
||||||
output, err := c.Run(config.Dir("tmp"), cmd)
|
output, err := c.Run(config.Dir("tmp"), []string{cmd})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ func (ol OracleLinux) Packages() (pkgs []string, err error) {
|
|||||||
"| grep -v src " +
|
"| grep -v src " +
|
||||||
"| cut -d ' ' -f 1"
|
"| cut -d ' ' -f 1"
|
||||||
|
|
||||||
output, err := c.Run(config.Dir("tmp"), cmd)
|
output, err := c.Run(config.Dir("tmp"), []string{cmd})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (u Ubuntu) Packages() (pkgs []string, err error) {
|
|||||||
"--names-only '^linux-image-[0-9\\.\\-]*-generic$' " +
|
"--names-only '^linux-image-[0-9\\.\\-]*-generic$' " +
|
||||||
"| awk '{ print $1 }'"
|
"| awk '{ print $1 }'"
|
||||||
|
|
||||||
output, err := c.Run(config.Dir("tmp"), cmd)
|
output, err := c.Run(config.Dir("tmp"), []string{cmd})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ func installKernel(sk config.Target, pkgname string, force, headers bool) (err e
|
|||||||
cmd += " && cp -r /usr/src /target/usr/"
|
cmd += " && cp -r /usr/src /target/usr/"
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = c.Run("", cmd)
|
_, err = c.Run("", []string{cmd})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
4
pew.go
4
pew.go
@ -296,7 +296,9 @@ func build(flog zerolog.Logger, tmp string, ka config.Artifact,
|
|||||||
log.Fatal().Err(err).Msg("container creation failure")
|
log.Fatal().Err(err).Msg("container creation failure")
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err = c.Run(outdir, buildCommand+" && chmod -R 777 /work")
|
output, err = c.Run(outdir, []string{
|
||||||
|
buildCommand + " && chmod -R 777 /work",
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
cmd := exec.Command("bash", "-c", "cd "+outdir+" && "+
|
cmd := exec.Command("bash", "-c", "cd "+outdir+" && "+
|
||||||
buildCommand)
|
buildCommand)
|
||||||
|
Loading…
Reference in New Issue
Block a user