diff --git a/pkg/compose/pull.go b/pkg/compose/pull.go index fbeacace..88cfefbf 100644 --- a/pkg/compose/pull.go +++ b/pkg/compose/pull.go @@ -181,6 +181,18 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser RegistryAuth: base64.URLEncoding.EncodeToString(buf), Platform: service.Platform, }) + + // check if has error and the service has a build section + // then the status should be warning instead of error + if err != nil && service.Build != nil { + w.Event(progress.Event{ + ID: service.Name, + Status: progress.Warning, + Text: "Warning", + }) + return "", WrapCategorisedComposeError(err, PullFailure) + } + if err != nil { w.Event(progress.Event{ ID: service.Name, diff --git a/pkg/progress/event.go b/pkg/progress/event.go index 0ead54dd..8603410e 100644 --- a/pkg/progress/event.go +++ b/pkg/progress/event.go @@ -28,6 +28,8 @@ const ( Done // Error means that the current task has errored Error + // Warning means that the current task has warning + Warning ) // Event represents a progress event. diff --git a/pkg/progress/tty.go b/pkg/progress/tty.go index 09338fb8..8729571a 100644 --- a/pkg/progress/tty.go +++ b/pkg/progress/tty.go @@ -75,7 +75,7 @@ func (w *ttyWriter) Event(e Event) { if _, ok := w.events[e.ID]; ok { last := w.events[e.ID] switch e.Status { - case Done, Error: + case Done, Error, Warning: if last.Status != e.Status { last.stop() } @@ -222,6 +222,9 @@ func lineText(event Event, pad string, terminalWidth, statusPadding int, color b if event.Status == Error { color = aec.RedF } + if event.Status == Warning { + color = aec.YellowF + } return aec.Apply(o, color) } diff --git a/pkg/progress/tty_test.go b/pkg/progress/tty_test.go index f9b4071d..e9e0c7e2 100644 --- a/pkg/progress/tty_test.go +++ b/pkg/progress/tty_test.go @@ -54,6 +54,10 @@ func TestLineText(t *testing.T) { ev.Status = Error out = lineText(ev, "", 50, lineWidth, true) assert.Equal(t, out, "\x1b[31m . id Text Status 0.0s\n\x1b[0m") + + ev.Status = Warning + out = lineText(ev, "", 50, lineWidth, true) + assert.Equal(t, out, "\x1b[33m . id Text Status 0.0s\n\x1b[0m") } func TestLineTextSingleEvent(t *testing.T) { @@ -103,3 +107,32 @@ func TestErrorEvent(t *testing.T) { assert.Assert(t, ok) assert.Assert(t, event.endTime.After(time.Now().Add(-10*time.Second))) } + +func TestWarningEvent(t *testing.T) { + w := &ttyWriter{ + events: map[string]Event{}, + mtx: &sync.Mutex{}, + } + e := Event{ + ID: "id", + Text: "Text", + Status: Working, + StatusText: "Working", + startTime: time.Now(), + spinner: &spinner{ + chars: []string{"."}, + }, + } + // Fire "Working" event and check end time isn't touched + w.Event(e) + event, ok := w.events[e.ID] + assert.Assert(t, ok) + assert.Assert(t, event.endTime.Equal(time.Time{})) + + // Fire "Warning" event and check end time is set + e.Status = Warning + w.Event(e) + event, ok = w.events[e.ID] + assert.Assert(t, ok) + assert.Assert(t, event.endTime.After(time.Now().Add(-10*time.Second))) +}