mirror of
https://github.com/containers/podman.git
synced 2025-05-21 00:56:36 +08:00
compat, build: suppress step errors when quiet is set
Match with docker API and suppress step errors when field quiet is set. Closes: https://github.com/containers/podman/issues/14315 Signed-off-by: Aditya R <arajan@redhat.com> Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
This commit is contained in:

committed by
tomsweeneyredhat

parent
33084ebddd
commit
48e614d44e
@ -622,15 +622,17 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
enc := json.NewEncoder(body)
|
enc := json.NewEncoder(body)
|
||||||
enc.SetEscapeHTML(true)
|
enc.SetEscapeHTML(true)
|
||||||
|
var stepErrors []string
|
||||||
|
|
||||||
for {
|
for {
|
||||||
m := struct {
|
type BuildResponse struct {
|
||||||
Stream string `json:"stream,omitempty"`
|
Stream string `json:"stream,omitempty"`
|
||||||
Error *jsonmessage.JSONError `json:"errorDetail,omitempty"`
|
Error *jsonmessage.JSONError `json:"errorDetail,omitempty"`
|
||||||
// NOTE: `error` is being deprecated check https://github.com/moby/moby/blob/master/pkg/jsonmessage/jsonmessage.go#L148
|
// NOTE: `error` is being deprecated check https://github.com/moby/moby/blob/master/pkg/jsonmessage/jsonmessage.go#L148
|
||||||
ErrorMessage string `json:"error,omitempty"` // deprecate this slowly
|
ErrorMessage string `json:"error,omitempty"` // deprecate this slowly
|
||||||
Aux json.RawMessage `json:"aux,omitempty"`
|
Aux json.RawMessage `json:"aux,omitempty"`
|
||||||
}{}
|
}
|
||||||
|
m := BuildResponse{}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case e := <-stdout.Chan():
|
case e := <-stdout.Chan():
|
||||||
@ -646,12 +648,27 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
flush()
|
flush()
|
||||||
case e := <-auxout.Chan():
|
case e := <-auxout.Chan():
|
||||||
|
if !query.Quiet {
|
||||||
m.Stream = string(e)
|
m.Stream = string(e)
|
||||||
if err := enc.Encode(m); err != nil {
|
if err := enc.Encode(m); err != nil {
|
||||||
stderr.Write([]byte(err.Error()))
|
stderr.Write([]byte(err.Error()))
|
||||||
}
|
}
|
||||||
flush()
|
flush()
|
||||||
|
} else {
|
||||||
|
stepErrors = append(stepErrors, string(e))
|
||||||
|
}
|
||||||
case e := <-stderr.Chan():
|
case e := <-stderr.Chan():
|
||||||
|
// Docker-API Compat parity : Build failed so
|
||||||
|
// output all step errors irrespective of quiet
|
||||||
|
// flag.
|
||||||
|
for _, stepError := range stepErrors {
|
||||||
|
t := BuildResponse{}
|
||||||
|
t.Stream = stepError
|
||||||
|
if err := enc.Encode(t); err != nil {
|
||||||
|
stderr.Write([]byte(err.Error()))
|
||||||
|
}
|
||||||
|
flush()
|
||||||
|
}
|
||||||
m.ErrorMessage = string(e)
|
m.ErrorMessage = string(e)
|
||||||
m.Error = &jsonmessage.JSONError{
|
m.Error = &jsonmessage.JSONError{
|
||||||
Message: m.ErrorMessage,
|
Message: m.ErrorMessage,
|
||||||
|
@ -210,6 +210,19 @@ t POST "images/load" ${TMPD}/test.tar 200 \
|
|||||||
t GET libpod/images/quay.io/libpod/alpine:latest/exists 204
|
t GET libpod/images/quay.io/libpod/alpine:latest/exists 204
|
||||||
t GET libpod/images/quay.io/libpod/busybox:latest/exists 204
|
t GET libpod/images/quay.io/libpod/busybox:latest/exists 204
|
||||||
|
|
||||||
|
CONTAINERFILE_WITH_ERR_TAR="${TMPD}/containerfile.tar"
|
||||||
|
cat > $TMPD/containerfile << EOF
|
||||||
|
FROM $IMAGE
|
||||||
|
RUN echo 'some error' >&2
|
||||||
|
EOF
|
||||||
|
tar --format=posix -C $TMPD -cvf ${CONTAINERFILE_WITH_ERR_TAR} containerfile &> /dev/null
|
||||||
|
t POST "/build?q=1&dockerfile=containerfile" $CONTAINERFILE_WITH_ERR_TAR 200
|
||||||
|
if [[ $output == *"some error"* ]];then
|
||||||
|
_show_ok 0 "compat quiet build" "[should not contain 'some error']" "$output"
|
||||||
|
else
|
||||||
|
_show_ok 1 "compat quiet build"
|
||||||
|
fi
|
||||||
|
|
||||||
cleanBuildTest
|
cleanBuildTest
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
Reference in New Issue
Block a user