Skip to content

Commit

Permalink
Fixes containers#12063 Add docker compatible output after image build.
Browse files Browse the repository at this point in the history
Signed-off-by: Ananth Bhaskararaman <[email protected]>
  • Loading branch information
ananthb committed Dec 14, 2021
1 parent 4a060ca commit 52b12fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
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
ErrorMessage string `json:"error,omitempty"` // deprecate this slowly
Aux json.RawMessage `json:"aux,omitempty"`
}{}

select {
Expand Down Expand Up @@ -656,6 +657,11 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
case <-runCtx.Done():
if success {
if !utils.IsLibpodRequest(r) && !query.Quiet {
m.Aux = []byte(fmt.Sprintf(`{"ID":"sha256:%s"}`, imageID))
if err := enc.Encode(m); err != nil {
logrus.Warnf("failed to json encode error %v", err)
}
m.Aux = nil
m.Stream = fmt.Sprintf("Successfully built %12.12s\n", imageID)
if err := enc.Encode(m); err != nil {
logrus.Warnf("Failed to json encode error %v", err)
Expand Down
14 changes: 14 additions & 0 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,20 @@ if ! grep -q '400 Bad Request' "${TMPD}/headers.txt"; then
BUILD_TEST_ERROR="1"
fi

curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
-H "content-type: application/tar" \
--dump-header "${TMPD}/headers.txt" \
-o "${TMPD}/response.txt" \
"http://$HOST:$PORT/v1.40/build?dockerfile=containerfile" &> /dev/null
if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/tar)"
BUILD_TEST_ERROR="1"
fi
if ! grep -qP '^{"aux":{"ID":"sha256:[0-9a-f]{64}"}}$' "${TMPD}/response.txt"; then
echo -e "${red}NOK: Image build response does not contain ID"
BUILD_TEST_ERROR="1"
fi

t POST libpod/images/prune 200
t POST libpod/images/prune 200 length=0 []

Expand Down

0 comments on commit 52b12fe

Please sign in to comment.