|
@@ -18,6 +18,7 @@ package compose
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"context"
|
|
"context"
|
|
|
|
|
+ "fmt"
|
|
|
"io"
|
|
"io"
|
|
|
"strings"
|
|
"strings"
|
|
|
"time"
|
|
"time"
|
|
@@ -65,6 +66,8 @@ type Service interface {
|
|
|
UnPause(ctx context.Context, project *types.Project) error
|
|
UnPause(ctx context.Context, project *types.Project) error
|
|
|
// Top executes the equivalent to a `compose top`
|
|
// Top executes the equivalent to a `compose top`
|
|
|
Top(ctx context.Context, projectName string, services []string) ([]ContainerProcSummary, error)
|
|
Top(ctx context.Context, projectName string, services []string) ([]ContainerProcSummary, error)
|
|
|
|
|
+ // Events executes the equivalent to a `compose events`
|
|
|
|
|
+ Events(ctx context.Context, project string, options EventsOptions) error
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// BuildOptions group options of the Build API
|
|
// BuildOptions group options of the Build API
|
|
@@ -156,7 +159,7 @@ type RemoveOptions struct {
|
|
|
Force bool
|
|
Force bool
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// RunOptions options to execute compose run
|
|
|
|
|
|
|
+// RunOptions group options of the Run API
|
|
|
type RunOptions struct {
|
|
type RunOptions struct {
|
|
|
Name string
|
|
Name string
|
|
|
Service string
|
|
Service string
|
|
@@ -177,6 +180,31 @@ type RunOptions struct {
|
|
|
Index int
|
|
Index int
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// EventsOptions group options of the Events API
|
|
|
|
|
+type EventsOptions struct {
|
|
|
|
|
+ Services []string
|
|
|
|
|
+ Consumer func(event Event) error
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// Event is a container runtime event served by Events API
|
|
|
|
|
+type Event struct {
|
|
|
|
|
+ Timestamp time.Time
|
|
|
|
|
+ Service string
|
|
|
|
|
+ Container string
|
|
|
|
|
+ Status string
|
|
|
|
|
+ Attributes map[string]string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (e Event) String() string {
|
|
|
|
|
+ t := e.Timestamp.Format("2006-01-02 15:04:05.000000")
|
|
|
|
|
+ var attr []string
|
|
|
|
|
+ for k, v := range e.Attributes {
|
|
|
|
|
+ attr = append(attr, fmt.Sprintf("%s=%s", k, v))
|
|
|
|
|
+ }
|
|
|
|
|
+ return fmt.Sprintf("%s container %s %s (%s)\n", t, e.Status, e.Container, strings.Join(attr, ", "))
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// EnvironmentMap return RunOptions.Environment as a MappingWithEquals
|
|
// EnvironmentMap return RunOptions.Environment as a MappingWithEquals
|
|
|
func (opts *RunOptions) EnvironmentMap() types.MappingWithEquals {
|
|
func (opts *RunOptions) EnvironmentMap() types.MappingWithEquals {
|
|
|
environment := types.MappingWithEquals{}
|
|
environment := types.MappingWithEquals{}
|