Fix flake on failed podman-remote build : try 2

This time we are checking if the function actually succeeded,
otherwise we will report an error.

Also if we did not get the id, report unexpected failure.

[NO TESTS NEEDED] Still no good way to test this, but manually.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2021-04-14 15:55:09 -04:00
parent 9f36efda37
commit 855a5a89dd
2 changed files with 20 additions and 6 deletions

View File

@ -464,15 +464,16 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
var (
imageID string
failed bool
success bool
)
runCtx, cancel := context.WithCancel(context.Background())
go func() {
defer cancel()
imageID, _, err = runtime.Build(r.Context(), buildOptions, query.Dockerfile)
if err != nil {
failed = true
if err == nil {
success = true
} else {
stderr.Write([]byte(err.Error() + "\n"))
}
}()
@ -534,7 +535,8 @@ loop:
}
flush()
case <-runCtx.Done():
if !failed {
flush()
if success {
if !utils.IsLibpodRequest(r) {
m.Stream = fmt.Sprintf("Successfully built %12.12s\n", imageID)
if err := enc.Encode(m); err != nil {