mirror of
https://github.com/mudler/luet.git
synced 2025-09-02 15:54:39 +00:00
@@ -16,7 +16,6 @@
|
|||||||
package backend
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/mudler/luet/pkg/compiler"
|
"github.com/mudler/luet/pkg/compiler"
|
||||||
@@ -49,43 +48,29 @@ func NewBackend(s string) compiler.CompilerBackend {
|
|||||||
return compilerBackend
|
return compilerBackend
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCommand(cmd *exec.Cmd) (string, error) {
|
func runCommand(cmd *exec.Cmd) error {
|
||||||
|
output := ""
|
||||||
buffered := !config.LuetCfg.GetGeneral().ShowBuildOutput
|
buffered := !config.LuetCfg.GetGeneral().ShowBuildOutput
|
||||||
if buffered {
|
|
||||||
Spinner(22)
|
|
||||||
defer SpinnerStop()
|
|
||||||
}
|
|
||||||
|
|
||||||
ans := ""
|
|
||||||
writer := NewBackendWriter(buffered)
|
writer := NewBackendWriter(buffered)
|
||||||
|
|
||||||
cmd.Stdout = writer
|
cmd.Stdout = writer
|
||||||
cmd.Stderr = writer
|
cmd.Stderr = writer
|
||||||
|
|
||||||
|
if buffered {
|
||||||
|
Spinner(22)
|
||||||
|
defer SpinnerStop()
|
||||||
|
}
|
||||||
|
|
||||||
err := cmd.Start()
|
err := cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "Failed starting build")
|
return errors.Wrap(err, "Failed starting command")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = cmd.Wait()
|
err = cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "Failed waiting for building command")
|
output = writer.GetCombinedOutput()
|
||||||
|
return errors.Wrapf(err, "Failed running command: %s", output)
|
||||||
}
|
}
|
||||||
|
|
||||||
res := cmd.ProcessState.ExitCode()
|
return nil
|
||||||
if res != 0 {
|
|
||||||
errMsg := fmt.Sprintf("Failed building image (exiting with %d)", res)
|
|
||||||
if buffered {
|
|
||||||
errMsg = fmt.Sprintf("Failed building image (exiting with %d): %s",
|
|
||||||
res, writer.GetCombinedOutput())
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", errors.Wrap(err, errMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
if buffered {
|
|
||||||
ans = writer.GetCombinedOutput()
|
|
||||||
}
|
|
||||||
|
|
||||||
return ans, nil
|
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,7 @@ func (*SimpleDocker) BuildImage(opts compiler.CompilerBackendOptions) error {
|
|||||||
Info(":whale2: Building image " + name)
|
Info(":whale2: Building image " + name)
|
||||||
cmd := exec.Command("docker", buildarg...)
|
cmd := exec.Command("docker", buildarg...)
|
||||||
cmd.Dir = path
|
cmd.Dir = path
|
||||||
_, err := runCommand(cmd)
|
err := runCommand(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -49,7 +49,7 @@ func (*SimpleImg) BuildImage(opts compiler.CompilerBackendOptions) error {
|
|||||||
|
|
||||||
cmd := exec.Command("img", buildarg...)
|
cmd := exec.Command("img", buildarg...)
|
||||||
cmd.Dir = path
|
cmd.Dir = path
|
||||||
_, err := runCommand(cmd)
|
err := runCommand(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
// Copyright © 2021 Daniele Rondina <geaaru@sabayonlinux.org>
|
// Copyright © 2021 Daniele Rondina <geaaru@sabayonlinux.org>
|
||||||
|
// Ettore Di Giacinto <mudler@sabayonlinux.org>
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This program is free software; you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,21 +24,23 @@ import (
|
|||||||
|
|
||||||
type BackendWriter struct {
|
type BackendWriter struct {
|
||||||
BufferedOutput bool
|
BufferedOutput bool
|
||||||
Buffer bytes.Buffer
|
Buffer *bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBackendWriter(buffered bool) *BackendWriter {
|
func NewBackendWriter(buffered bool) *BackendWriter {
|
||||||
return &BackendWriter{
|
return &BackendWriter{
|
||||||
BufferedOutput: buffered,
|
BufferedOutput: buffered,
|
||||||
|
Buffer: &bytes.Buffer{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BackendWriter) Write(p []byte) (int, error) {
|
func (b *BackendWriter) Write(p []byte) (int, error) {
|
||||||
if b.BufferedOutput {
|
if b.BufferedOutput {
|
||||||
return b.Buffer.Write(p)
|
return b.Buffer.Write(p)
|
||||||
} else {
|
|
||||||
Msg("info", false, false, (string(p)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Msg("info", false, false, (string(p)))
|
||||||
|
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user