aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/images/build.go18
-rw-r--r--cmd/podman/machine/init.go8
-rw-r--r--cmd/podman/utils/error.go26
3 files changed, 51 insertions, 1 deletions
diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go
index 4c563ed27..751db099f 100644
--- a/cmd/podman/images/build.go
+++ b/cmd/podman/images/build.go
@@ -1,9 +1,11 @@
package images
import (
+ "fmt"
"io"
"io/ioutil"
"os"
+ "os/exec"
"path/filepath"
"strings"
"time"
@@ -289,7 +291,23 @@ func build(cmd *cobra.Command, args []string) error {
}
report, err := registry.ImageEngine().Build(registry.GetContext(), containerFiles, *apiBuildOpts)
+
if err != nil {
+ exitCode := buildahCLI.ExecErrorCodeGeneric
+ if registry.IsRemote() {
+ // errors from server does not contain ExitCode
+ // so parse exit code from error message
+ remoteExitCode, parseErr := utils.ExitCodeFromBuildError(fmt.Sprint(errors.Cause(err)))
+ if parseErr == nil {
+ exitCode = remoteExitCode
+ }
+ }
+
+ if ee, ok := (errors.Cause(err)).(*exec.ExitError); ok {
+ exitCode = ee.ExitCode()
+ }
+
+ registry.SetExitCode(exitCode)
return err
}
diff --git a/cmd/podman/machine/init.go b/cmd/podman/machine/init.go
index adde887f7..bee6844df 100644
--- a/cmd/podman/machine/init.go
+++ b/cmd/podman/machine/init.go
@@ -38,7 +38,6 @@ func init() {
})
flags := initCmd.Flags()
cfg := registry.PodmanConfig()
-
cpusFlagName := "cpus"
flags.Uint64Var(
&initOpts.CPUS,
@@ -69,6 +68,13 @@ func init() {
"now", false,
"Start machine now",
)
+ timezoneFlagName := "timezone"
+ defaultTz := cfg.TZ()
+ if len(defaultTz) < 1 {
+ defaultTz = "local"
+ }
+ flags.StringVar(&initOpts.TimeZone, timezoneFlagName, defaultTz, "Set timezone")
+ _ = initCmd.RegisterFlagCompletionFunc(timezoneFlagName, completion.AutocompleteDefault)
ImagePathFlagName := "image-path"
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Machine.Image, "Path to qcow image")
diff --git a/cmd/podman/utils/error.go b/cmd/podman/utils/error.go
index 2d58bc70d..aab1da675 100644
--- a/cmd/podman/utils/error.go
+++ b/cmd/podman/utils/error.go
@@ -1,8 +1,13 @@
package utils
import (
+ "errors"
"fmt"
"os"
+ "strconv"
+ "strings"
+
+ buildahCLI "github.com/containers/buildah/pkg/cli"
)
type OutputErrors []error
@@ -17,3 +22,24 @@ func (o OutputErrors) PrintErrors() (lastError error) {
}
return
}
+
+/* For remote client, server does not returns error with exit code
+ instead returns a message and we cast it to a new error.
+
+ Following function performs parsing on build error and returns
+ exit status which was exepected for this current build
+*/
+func ExitCodeFromBuildError(errorMsg string) (int, error) {
+ if strings.Contains(errorMsg, "exit status") {
+ errorSplit := strings.Split(errorMsg, " ")
+ if errorSplit[len(errorSplit)-2] == "status" {
+ tmpSplit := strings.Split(errorSplit[len(errorSplit)-1], "\n")
+ exitCodeRemote, err := strconv.Atoi(tmpSplit[0])
+ if err == nil {
+ return exitCodeRemote, nil
+ }
+ return buildahCLI.ExecErrorCodeGeneric, err
+ }
+ }
+ return buildahCLI.ExecErrorCodeGeneric, errors.New("error message does not contains a valid exit code")
+}