Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add improvement output warning when pulling image #9829

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/compose/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions pkg/progress/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion pkg/progress/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
}

Expand Down
33 changes: 33 additions & 0 deletions pkg/progress/tty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)))
}