1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-21 22:39:41 +02:00

fix(edge-stack): parse docker compose multi lines json output EE-6317 (#10627)

This commit is contained in:
cmeng 2023-11-20 22:54:28 +13:00 committed by GitHub
parent ad5a17ac34
commit 57ed6ae6a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,8 +1,10 @@
package composeplugin package composeplugin
import ( import (
"bytes"
"context" "context"
"fmt" "fmt"
"io"
"time" "time"
"github.com/portainer/portainer/pkg/libstack" "github.com/portainer/portainer/pkg/libstack"
@ -107,6 +109,7 @@ func (wrapper *PluginWrapper) WaitForStatus(ctx context.Context, name string, st
errorMessageCh := make(chan string) errorMessageCh := make(chan string)
go func() { go func() {
OUTER:
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
@ -135,13 +138,23 @@ func (wrapper *PluginWrapper) WaitForStatus(ctx context.Context, name string, st
} }
var services []service var services []service
err = json.Unmarshal(output, &services) dec := json.NewDecoder(bytes.NewReader(output))
for {
var svc service
err := dec.Decode(&svc)
if err == io.EOF {
break
}
if err != nil { if err != nil {
log.Debug(). log.Debug().
Str("project_name", name). Str("project_name", name).
Err(err). Err(err).
Msg("failed to parse docker compose output") Msg("failed to parse docker compose output")
continue continue OUTER
}
services = append(services, svc)
} }
if len(services) == 0 && status == libstack.StatusRemoved { if len(services) == 0 && status == libstack.StatusRemoved {