Skip to content

Commit

Permalink
Merge pull request #14319 from flouthoc/suppress-aux-on-quiet
Browse files Browse the repository at this point in the history
compat, build: suppress `step` errors when `quiet=1` is set
  • Loading branch information
openshift-merge-robot authored May 24, 2022
2 parents 6240783 + 2133edb commit c6152f4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
29 changes: 23 additions & 6 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,15 +674,17 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {

enc := json.NewEncoder(body)
enc.SetEscapeHTML(true)
var stepErrors []string

for {
m := struct {
type BuildResponse struct {
Stream string `json:"stream,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
ErrorMessage string `json:"error,omitempty"` // deprecate this slowly
Aux json.RawMessage `json:"aux,omitempty"`
}{}
}
m := BuildResponse{}

select {
case e := <-stdout.Chan():
Expand All @@ -698,12 +700,27 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
}
flush()
case e := <-auxout.Chan():
m.Stream = string(e)
if err := enc.Encode(m); err != nil {
stderr.Write([]byte(err.Error()))
if !query.Quiet {
m.Stream = string(e)
if err := enc.Encode(m); err != nil {
stderr.Write([]byte(err.Error()))
}
flush()
} else {
stepErrors = append(stepErrors, string(e))
}
flush()
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.Error = &jsonmessage.JSONError{
Message: m.ErrorMessage,
Expand Down
12 changes: 12 additions & 0 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ 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/busybox:latest/exists 204

CONTAINERFILE_WITH_ERR_TAR="${TMPD}/containerfile.tar"
cat > $TMPD/containerfile << EOF
FROM quay.io/fedora/fedora
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
response_output=$(cat "$WORKDIR/curl.result.out")
if [[ ${response_output} == *"some error"* ]];then
_show_ok 0 "compat quiet build" "~ $response_output" "found output from stderr in API"
fi

cleanBuildTest

# vim: filetype=sh

0 comments on commit c6152f4

Please sign in to comment.