Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bin/
coverage.out
covdatafiles/
.DS_Store
pkg/e2e/*.tar
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ require (

require (
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.3 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkk
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/DefangLabs/secret-detector v0.0.0-20250403165618-22662109213e h1:rd4bOvKmDIx0WeTv9Qz+hghsgyjikFiPrseXHlKepO0=
github.com/DefangLabs/secret-detector v0.0.0-20250403165618-22662109213e/go.mod h1:blbwPQh4DTlCZEfk1BLU4oMIhLda2U+A840Uag9DsZw=
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
Expand Down
22 changes: 9 additions & 13 deletions pkg/compose/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,18 @@ func (s *composeService) commit(ctx context.Context, projectName string, options
}

name := getCanonicalContainerName(ctr)
msg := fmt.Sprintf("Commit %s", name)

s.events.On(progress.Event{
ID: name,
Text: msg,
Status: progress.Working,
StatusText: "Committing",
ID: name,
Status: progress.Working,
Text: progress.StatusCommitting,
})

if s.dryRun {
s.events.On(progress.Event{
ID: name,
Text: msg,
Status: progress.Done,
StatusText: "Committed",
ID: name,
Status: progress.Done,
Text: progress.StatusCommitted,
})

return nil
Expand All @@ -73,10 +70,9 @@ func (s *composeService) commit(ctx context.Context, projectName string, options
}

s.events.On(progress.Event{
ID: name,
Text: msg,
Status: progress.Done,
StatusText: fmt.Sprintf("Committed as %s", response.ID),
ID: name,
Text: fmt.Sprintf("Committed as %s", response.ID),
Status: progress.Done,
})

return nil
Expand Down
20 changes: 12 additions & 8 deletions pkg/compose/convergence.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
logrus.Warnf("optional dependency %q failed to start: %s", dep, err.Error())
return nil
}
s.events.On(containerEvents(waitingFor, progress.ErrorEvent)...)
s.events.On(containerEvents(waitingFor, func(s string) progress.Event {
return progress.ErrorEventf(s, "dependency %s failed to start", dep)
})...)
return fmt.Errorf("dependency failed to start: %w", err)
}
if healthy {
Expand Down Expand Up @@ -532,7 +534,9 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
}

msg := fmt.Sprintf("service %s", messageSuffix)
s.events.On(containerReasonEvents(waitingFor, progress.ErrorMessageEvent, msg)...)
s.events.On(containerEvents(waitingFor, func(s string) progress.Event {
return progress.ErrorEventf(s, "service %s", messageSuffix)
})...)
return errors.New(msg)
}
default:
Expand Down Expand Up @@ -600,9 +604,9 @@ func (s *composeService) createContainer(ctx context.Context, project *types.Pro
if err != nil {
if ctx.Err() == nil {
s.events.On(progress.Event{
ID: eventName,
Status: progress.Error,
StatusText: err.Error(),
ID: eventName,
Status: progress.Error,
Text: err.Error(),
})
}
return ctr, err
Expand All @@ -619,9 +623,9 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
defer func() {
if err != nil && ctx.Err() == nil {
s.events.On(progress.Event{
ID: eventName,
Status: progress.Error,
StatusText: err.Error(),
ID: eventName,
Status: progress.Error,
Text: err.Error(),
})
}
}()
Expand Down
20 changes: 10 additions & 10 deletions pkg/compose/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,24 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
name := getCanonicalContainerName(ctr)
var msg string
if direction == fromService {
msg = fmt.Sprintf("copy %s:%s to %s", name, srcPath, dstPath)
msg = fmt.Sprintf("%s:%s to %s", name, srcPath, dstPath)
} else {
msg = fmt.Sprintf("copy %s to %s:%s", srcPath, name, dstPath)
msg = fmt.Sprintf("%s to %s:%s", srcPath, name, dstPath)
}
s.events.On(progress.Event{
ID: name,
Text: msg,
Status: progress.Working,
StatusText: "Copying",
ID: name,
Text: progress.StatusCopying,
Details: msg,
Status: progress.Working,
})
if err := copyFunc(ctx, ctr.ID, srcPath, dstPath, options); err != nil {
return err
}
s.events.On(progress.Event{
ID: name,
Text: msg,
Status: progress.Done,
StatusText: "Copied",
ID: name,
Text: progress.StatusCopied,
Details: msg,
Status: progress.Done,
})
return nil
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ func (s *composeService) resolveOrCreateNetwork(ctx context.Context, project *ty

resp, err := s.apiClient().NetworkCreate(ctx, n.Name, createOpts)
if err != nil {
s.events.On(progress.ErrorEvent(networkEventName))
s.events.On(progress.ErrorEvent(networkEventName, err.Error()))
return "", fmt.Errorf("failed to create network %s: %w", n.Name, err)
}
s.events.On(progress.CreatedEvent(networkEventName))
Expand Down Expand Up @@ -1632,7 +1632,7 @@ func (s *composeService) createVolume(ctx context.Context, volume types.VolumeCo
DriverOpts: volume.DriverOpts,
})
if err != nil {
s.events.On(progress.ErrorEvent(eventName))
s.events.On(progress.ErrorEvent(eventName, err.Error()))
return err
}
s.events.On(progress.CreatedEvent(eventName))
Expand Down
6 changes: 3 additions & 3 deletions pkg/compose/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (s *composeService) removeNetwork(ctx context.Context, composeNetworkName s
if errdefs.IsNotFound(err) {
continue
}
s.events.On(progress.ErrorEvent(eventName))
s.events.On(progress.ErrorEvent(eventName, err.Error()))
return fmt.Errorf("failed to remove network %s: %w", name, err)
}
s.events.On(progress.RemovedEvent(eventName))
Expand Down Expand Up @@ -317,7 +317,7 @@ func (s *composeService) stopContainer(ctx context.Context, service *types.Servi
timeoutInSecond := utils.DurationSecondToInt(timeout)
err := s.apiClient().ContainerStop(ctx, ctr.ID, containerType.StopOptions{Timeout: timeoutInSecond})
if err != nil {
s.events.On(progress.ErrorMessageEvent(eventName, "Error while Stopping"))
s.events.On(progress.ErrorEvent(eventName, "Error while Stopping"))
return err
}
s.events.On(progress.StoppedEvent(eventName))
Expand Down Expand Up @@ -360,7 +360,7 @@ func (s *composeService) stopAndRemoveContainer(ctx context.Context, ctr contain
RemoveVolumes: volumes,
})
if err != nil && !errdefs.IsNotFound(err) && !errdefs.IsConflict(err) {
s.events.On(progress.ErrorMessageEvent(eventName, "Error while Removing"))
s.events.On(progress.ErrorEvent(eventName, "Error while Removing"))
return err
}
s.events.On(progress.RemovedEvent(eventName))
Expand Down
23 changes: 7 additions & 16 deletions pkg/compose/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ func (s *composeService) export(ctx context.Context, projectName string, options
}

name := getCanonicalContainerName(container)
msg := fmt.Sprintf("export %s to %s", name, options.Output)

s.events.On(progress.Event{
ID: name,
Text: msg,
Status: progress.Working,
StatusText: "Exporting",
ID: name,
Text: progress.StatusExporting,
Status: progress.Working,
})

responseBody, err := s.apiClient().ContainerExport(ctx, container.ID)
Expand All @@ -67,12 +64,7 @@ func (s *composeService) export(ctx context.Context, projectName string, options

defer func() {
if err := responseBody.Close(); err != nil {
s.events.On(progress.Event{
ID: name,
Text: msg,
Status: progress.Error,
StatusText: fmt.Sprintf("Failed to close response body: %v", err),
})
s.events.On(progress.ErrorEventf(name, "Failed to close response body: %s", err.Error()))
}
}()

Expand All @@ -93,10 +85,9 @@ func (s *composeService) export(ctx context.Context, projectName string, options
}

s.events.On(progress.Event{
ID: name,
Text: msg,
Status: progress.Done,
StatusText: "Exported",
ID: name,
Text: progress.StatusExported,
Status: progress.Done,
})

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/compose/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *composeService) kill(ctx context.Context, projectName string, options a
s.events.On(progress.KillingEvent(eventName))
err := s.apiClient().ContainerKill(ctx, ctr.ID, options.Signal)
if err != nil {
s.events.On(progress.ErrorMessageEvent(eventName, "Error while Killing"))
s.events.On(progress.ErrorEvent(eventName, "Error while Killing"))
return err
}
s.events.On(progress.KilledEvent(eventName))
Expand Down
21 changes: 10 additions & 11 deletions pkg/compose/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,30 @@ func (m *modelAPI) PullModel(ctx context.Context, model types.ModelConfig, quiet

if !quietPull {
events.On(progress.Event{
ID: model.Name,
Status: progress.Working,
Text: "Pulling",
StatusText: msg,
ID: model.Name,
Status: progress.Working,
Text: progress.StatusPulling,
})
}
}

err = cmd.Wait()
if err != nil {
events.On(progress.ErrorMessageEvent(model.Name, err.Error()))
events.On(progress.ErrorEvent(model.Name, err.Error()))
}
events.On(progress.Event{
ID: model.Name,
Status: progress.Working,
StatusText: "Pulled",
ID: model.Name,
Status: progress.Working,
Text: progress.StatusPulled,
})
return err
}

func (m *modelAPI) ConfigureModel(ctx context.Context, config types.ModelConfig, events progress.EventProcessor) error {
events.On(progress.Event{
ID: config.Name,
Status: progress.Working,
StatusText: "Configuring",
ID: config.Name,
Status: progress.Working,
Text: "Configuring",
})
// configure [--context-size=<n>] MODEL [-- <runtime-flags...>]
args := []string{"configure"}
Expand Down
2 changes: 1 addition & 1 deletion pkg/compose/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (s *composeService) executePlugin(cmd *exec.Cmd, command string, service ty

err = cmd.Wait()
if err != nil {
s.events.On(progress.ErrorMessageEvent(service.Name, err.Error()))
s.events.On(progress.ErrorEvent(service.Name, err.Error()))
return nil, fmt.Errorf("failed to %s service provider: %s", action, err.Error())
}
switch command {
Expand Down
Loading