- Remove duplicated structs that we already have in engine-api.
Signed-off-by: David Calavera <david.calavera@gmail.com>
| ... | ... |
@@ -4,11 +4,11 @@ import ( |
| 4 | 4 |
"io" |
| 5 | 5 |
"time" |
| 6 | 6 |
|
| 7 |
+ "github.com/docker/docker/api/types/backend" |
|
| 7 | 8 |
"github.com/docker/docker/daemon/exec" |
| 8 | 9 |
"github.com/docker/docker/pkg/archive" |
| 9 | 10 |
"github.com/docker/docker/pkg/version" |
| 10 | 11 |
"github.com/docker/engine-api/types" |
| 11 |
- "github.com/docker/engine-api/types/backend" |
|
| 12 | 12 |
"github.com/docker/engine-api/types/container" |
| 13 | 13 |
) |
| 14 | 14 |
|
| ... | ... |
@@ -55,7 +55,7 @@ type monitorBackend interface {
|
| 55 | 55 |
ContainerStats(name string, config *backend.ContainerStatsConfig) error |
| 56 | 56 |
ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) |
| 57 | 57 |
|
| 58 |
- Containers(config *backend.ContainersConfig) ([]*types.Container, error) |
|
| 58 |
+ Containers(config *types.ContainerListOptions) ([]*types.Container, error) |
|
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 | 61 |
// attachBackend includes function to implement to provide container attaching functionality. |
| ... | ... |
@@ -13,6 +13,7 @@ import ( |
| 13 | 13 |
"github.com/Sirupsen/logrus" |
| 14 | 14 |
"github.com/docker/distribution/registry/api/errcode" |
| 15 | 15 |
"github.com/docker/docker/api/server/httputils" |
| 16 |
+ "github.com/docker/docker/api/types/backend" |
|
| 16 | 17 |
derr "github.com/docker/docker/errors" |
| 17 | 18 |
"github.com/docker/docker/pkg/ioutils" |
| 18 | 19 |
"github.com/docker/docker/pkg/signal" |
| ... | ... |
@@ -20,9 +21,8 @@ import ( |
| 20 | 20 |
"github.com/docker/docker/runconfig" |
| 21 | 21 |
"github.com/docker/docker/utils" |
| 22 | 22 |
"github.com/docker/engine-api/types" |
| 23 |
- "github.com/docker/engine-api/types/backend" |
|
| 24 | 23 |
"github.com/docker/engine-api/types/container" |
| 25 |
- timetypes "github.com/docker/engine-api/types/time" |
|
| 24 |
+ "github.com/docker/engine-api/types/filters" |
|
| 26 | 25 |
"golang.org/x/net/context" |
| 27 | 26 |
"golang.org/x/net/websocket" |
| 28 | 27 |
) |
| ... | ... |
@@ -31,13 +31,17 @@ func (s *containerRouter) getContainersJSON(ctx context.Context, w http.Response |
| 31 | 31 |
if err := httputils.ParseForm(r); err != nil {
|
| 32 | 32 |
return err |
| 33 | 33 |
} |
| 34 |
+ filter, err := filters.FromParam(r.Form.Get("filters"))
|
|
| 35 |
+ if err != nil {
|
|
| 36 |
+ return err |
|
| 37 |
+ } |
|
| 34 | 38 |
|
| 35 |
- config := &backend.ContainersConfig{
|
|
| 36 |
- All: httputils.BoolValue(r, "all"), |
|
| 37 |
- Size: httputils.BoolValue(r, "size"), |
|
| 38 |
- Since: r.Form.Get("since"),
|
|
| 39 |
- Before: r.Form.Get("before"),
|
|
| 40 |
- Filters: r.Form.Get("filters"),
|
|
| 39 |
+ config := &types.ContainerListOptions{
|
|
| 40 |
+ All: httputils.BoolValue(r, "all"), |
|
| 41 |
+ Size: httputils.BoolValue(r, "size"), |
|
| 42 |
+ Since: r.Form.Get("since"),
|
|
| 43 |
+ Before: r.Form.Get("before"),
|
|
| 44 |
+ Filter: filter, |
|
| 41 | 45 |
} |
| 42 | 46 |
|
| 43 | 47 |
if tmpLimit := r.Form.Get("limit"); tmpLimit != "" {
|
| ... | ... |
@@ -102,15 +106,6 @@ func (s *containerRouter) getContainersLogs(ctx context.Context, w http.Response |
| 102 | 102 |
return fmt.Errorf("Bad parameters: you must choose at least one stream")
|
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 |
- var since time.Time |
|
| 106 |
- if r.Form.Get("since") != "" {
|
|
| 107 |
- s, n, err := timetypes.ParseTimestamps(r.Form.Get("since"), 0)
|
|
| 108 |
- if err != nil {
|
|
| 109 |
- return err |
|
| 110 |
- } |
|
| 111 |
- since = time.Unix(s, n) |
|
| 112 |
- } |
|
| 113 |
- |
|
| 114 | 105 |
var closeNotifier <-chan bool |
| 115 | 106 |
if notifier, ok := w.(http.CloseNotifier); ok {
|
| 116 | 107 |
closeNotifier = notifier.CloseNotify() |
| ... | ... |
@@ -134,14 +129,16 @@ func (s *containerRouter) getContainersLogs(ctx context.Context, w http.Response |
| 134 | 134 |
defer output.Close() |
| 135 | 135 |
|
| 136 | 136 |
logsConfig := &backend.ContainerLogsConfig{
|
| 137 |
- Follow: httputils.BoolValue(r, "follow"), |
|
| 138 |
- Timestamps: httputils.BoolValue(r, "timestamps"), |
|
| 139 |
- Since: since, |
|
| 140 |
- Tail: r.Form.Get("tail"),
|
|
| 141 |
- UseStdout: stdout, |
|
| 142 |
- UseStderr: stderr, |
|
| 143 |
- OutStream: output, |
|
| 144 |
- Stop: closeNotifier, |
|
| 137 |
+ ContainerLogsOptions: types.ContainerLogsOptions{
|
|
| 138 |
+ Follow: httputils.BoolValue(r, "follow"), |
|
| 139 |
+ Timestamps: httputils.BoolValue(r, "timestamps"), |
|
| 140 |
+ Since: r.Form.Get("since"),
|
|
| 141 |
+ Tail: r.Form.Get("tail"),
|
|
| 142 |
+ ShowStdout: stdout, |
|
| 143 |
+ ShowStderr: stderr, |
|
| 144 |
+ }, |
|
| 145 |
+ OutStream: output, |
|
| 146 |
+ Stop: closeNotifier, |
|
| 145 | 147 |
} |
| 146 | 148 |
|
| 147 | 149 |
if err := s.backend.ContainerLogs(containerName, logsConfig); err != nil {
|
| ... | ... |
@@ -32,7 +32,7 @@ type imageBackend interface {
|
| 32 | 32 |
} |
| 33 | 33 |
|
| 34 | 34 |
type importExportBackend interface {
|
| 35 |
- LoadImage(inTar io.ReadCloser, outStream io.Writer) error |
|
| 35 |
+ LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error |
|
| 36 | 36 |
ImportImage(src string, newRef reference.Named, msg string, inConfig io.ReadCloser, outStream io.Writer, config *container.Config) error |
| 37 | 37 |
ExportImage(names []string, outStream io.Writer) error |
| 38 | 38 |
} |
| ... | ... |
@@ -269,7 +269,7 @@ func (s *imageRouter) getImagesGet(ctx context.Context, w http.ResponseWriter, r |
| 269 | 269 |
return nil |
| 270 | 270 |
} |
| 271 | 271 |
|
| 272 |
-func (s *router) postImagesLoad(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
| 272 |
+func (s *imageRouter) postImagesLoad(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
| 273 | 273 |
if err := httputils.ParseForm(r); err != nil {
|
| 274 | 274 |
return err |
| 275 | 275 |
} |
| 276 | 276 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,51 @@ |
| 0 |
+// Package backend includes types to send information to server backends. |
|
| 1 |
+// TODO(calavera): This package is pending of extraction to engine-api |
|
| 2 |
+// when the server package is clean of daemon dependencies. |
|
| 3 |
+package backend |
|
| 4 |
+ |
|
| 5 |
+import ( |
|
| 6 |
+ "io" |
|
| 7 |
+ "net/http" |
|
| 8 |
+ |
|
| 9 |
+ "github.com/docker/engine-api/types" |
|
| 10 |
+) |
|
| 11 |
+ |
|
| 12 |
+// ContainerAttachWithLogsConfig holds the streams to use when connecting to a container to view logs. |
|
| 13 |
+type ContainerAttachWithLogsConfig struct {
|
|
| 14 |
+ Hijacker http.Hijacker |
|
| 15 |
+ Upgrade bool |
|
| 16 |
+ UseStdin bool |
|
| 17 |
+ UseStdout bool |
|
| 18 |
+ UseStderr bool |
|
| 19 |
+ Logs bool |
|
| 20 |
+ Stream bool |
|
| 21 |
+ DetachKeys []byte |
|
| 22 |
+} |
|
| 23 |
+ |
|
| 24 |
+// ContainerWsAttachWithLogsConfig attach with websockets, since all |
|
| 25 |
+// stream data is delegated to the websocket to handle there. |
|
| 26 |
+type ContainerWsAttachWithLogsConfig struct {
|
|
| 27 |
+ InStream io.ReadCloser // Reader to attach to stdin of container |
|
| 28 |
+ OutStream io.Writer // Writer to attach to stdout of container |
|
| 29 |
+ ErrStream io.Writer // Writer to attach to stderr of container |
|
| 30 |
+ Logs bool // If true return log output |
|
| 31 |
+ Stream bool // If true return stream output |
|
| 32 |
+ DetachKeys []byte |
|
| 33 |
+} |
|
| 34 |
+ |
|
| 35 |
+// ContainerLogsConfig holds configs for logging operations. Exists |
|
| 36 |
+// for users of the backend to to pass it a logging configuration. |
|
| 37 |
+type ContainerLogsConfig struct {
|
|
| 38 |
+ types.ContainerLogsOptions |
|
| 39 |
+ OutStream io.Writer |
|
| 40 |
+ Stop <-chan bool |
|
| 41 |
+} |
|
| 42 |
+ |
|
| 43 |
+// ContainerStatsConfig holds information for configuring the runtime |
|
| 44 |
+// behavior of a backend.ContainerStats() call. |
|
| 45 |
+type ContainerStatsConfig struct {
|
|
| 46 |
+ Stream bool |
|
| 47 |
+ OutStream io.Writer |
|
| 48 |
+ Stop <-chan bool |
|
| 49 |
+ Version string |
|
| 50 |
+} |
| ... | ... |
@@ -6,11 +6,11 @@ import ( |
| 6 | 6 |
"time" |
| 7 | 7 |
|
| 8 | 8 |
"github.com/Sirupsen/logrus" |
| 9 |
+ "github.com/docker/docker/api/types/backend" |
|
| 9 | 10 |
"github.com/docker/docker/container" |
| 10 | 11 |
"github.com/docker/docker/daemon/logger" |
| 11 | 12 |
derr "github.com/docker/docker/errors" |
| 12 | 13 |
"github.com/docker/docker/pkg/stdcopy" |
| 13 |
- "github.com/docker/engine-api/types/backend" |
|
| 14 | 14 |
) |
| 15 | 15 |
|
| 16 | 16 |
// ContainerAttachWithLogs attaches to logs according to the config passed in. See ContainerAttachWithLogsConfig. |
| ... | ... |
@@ -81,7 +81,7 @@ func (daemon *Daemon) ContainerWsAttachWithLogs(prefixOrName string, c *backend. |
| 81 | 81 |
|
| 82 | 82 |
// ContainerAttachOnBuild attaches streams to the container cID. If stream is true, it streams the output. |
| 83 | 83 |
func (daemon *Daemon) ContainerAttachOnBuild(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error {
|
| 84 |
- return daemon.ContainerWsAttachWithLogs(cID, &ContainerWsAttachWithLogsConfig{
|
|
| 84 |
+ return daemon.ContainerWsAttachWithLogs(cID, &backend.ContainerWsAttachWithLogsConfig{
|
|
| 85 | 85 |
InStream: stdin, |
| 86 | 86 |
OutStream: stdout, |
| 87 | 87 |
ErrStream: stderr, |
| ... | ... |
@@ -10,7 +10,6 @@ import ( |
| 10 | 10 |
"github.com/docker/docker/container" |
| 11 | 11 |
"github.com/docker/docker/image" |
| 12 | 12 |
"github.com/docker/engine-api/types" |
| 13 |
- "github.com/docker/engine-api/types/backend" |
|
| 14 | 13 |
"github.com/docker/engine-api/types/filters" |
| 15 | 14 |
networktypes "github.com/docker/engine-api/types/network" |
| 16 | 15 |
"github.com/docker/go-connections/nat" |
| ... | ... |
@@ -45,7 +44,7 @@ func (daemon *Daemon) List() []*container.Container {
|
| 45 | 45 |
} |
| 46 | 46 |
|
| 47 | 47 |
// listContext is the daemon generated filtering to iterate over containers. |
| 48 |
-// This is created based on the user specification from backend.ContainersConfig. |
|
| 48 |
+// This is created based on the user specification from types.ContainerListOptions. |
|
| 49 | 49 |
type listContext struct {
|
| 50 | 50 |
// idx is the container iteration index for this context |
| 51 | 51 |
idx int |
| ... | ... |
@@ -65,17 +64,17 @@ type listContext struct {
|
| 65 | 65 |
// sinceFilter is a filter to stop the filtering when the iterator arrive to the given container |
| 66 | 66 |
// this is used for --filter=since= and --since=, the latter is deprecated. |
| 67 | 67 |
sinceFilter *container.Container |
| 68 |
- // ContainersConfig is the filters set by the user |
|
| 69 |
- *backend.ContainersConfig |
|
| 68 |
+ // ContainerListOptions is the filters set by the user |
|
| 69 |
+ *types.ContainerListOptions |
|
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 | 72 |
// Containers returns the list of containers to show given the user's filtering. |
| 73 |
-func (daemon *Daemon) Containers(config *backend.ContainersConfig) ([]*types.Container, error) {
|
|
| 73 |
+func (daemon *Daemon) Containers(config *types.ContainerListOptions) ([]*types.Container, error) {
|
|
| 74 | 74 |
return daemon.reduceContainers(config, daemon.transformContainer) |
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 | 77 |
// reduceContainers parses the user's filtering options and generates the list of containers to return based on a reducer. |
| 78 |
-func (daemon *Daemon) reduceContainers(config *backend.ContainersConfig, reducer containerReducer) ([]*types.Container, error) {
|
|
| 78 |
+func (daemon *Daemon) reduceContainers(config *types.ContainerListOptions, reducer containerReducer) ([]*types.Container, error) {
|
|
| 79 | 79 |
containers := []*types.Container{}
|
| 80 | 80 |
|
| 81 | 81 |
ctx, err := daemon.foldFilter(config) |
| ... | ... |
@@ -118,14 +117,11 @@ func (daemon *Daemon) reducePsContainer(container *container.Container, ctx *lis |
| 118 | 118 |
} |
| 119 | 119 |
|
| 120 | 120 |
// foldFilter generates the container filter based on the user's filtering options. |
| 121 |
-func (daemon *Daemon) foldFilter(config *backend.ContainersConfig) (*listContext, error) {
|
|
| 122 |
- psFilters, err := filters.FromParam(config.Filters) |
|
| 123 |
- if err != nil {
|
|
| 124 |
- return nil, err |
|
| 125 |
- } |
|
| 121 |
+func (daemon *Daemon) foldFilter(config *types.ContainerListOptions) (*listContext, error) {
|
|
| 122 |
+ psFilters := config.Filter |
|
| 126 | 123 |
|
| 127 | 124 |
var filtExited []int |
| 128 |
- err = psFilters.WalkValues("exited", func(value string) error {
|
|
| 125 |
+ err := psFilters.WalkValues("exited", func(value string) error {
|
|
| 129 | 126 |
code, err := strconv.Atoi(value) |
| 130 | 127 |
if err != nil {
|
| 131 | 128 |
return err |
| ... | ... |
@@ -201,14 +197,14 @@ func (daemon *Daemon) foldFilter(config *backend.ContainersConfig) (*listContext |
| 201 | 201 |
} |
| 202 | 202 |
|
| 203 | 203 |
return &listContext{
|
| 204 |
- filters: psFilters, |
|
| 205 |
- ancestorFilter: ancestorFilter, |
|
| 206 |
- images: imagesFilter, |
|
| 207 |
- exitAllowed: filtExited, |
|
| 208 |
- beforeFilter: beforeContFilter, |
|
| 209 |
- sinceFilter: sinceContFilter, |
|
| 210 |
- ContainersConfig: config, |
|
| 211 |
- names: daemon.nameIndex.GetAll(), |
|
| 204 |
+ filters: psFilters, |
|
| 205 |
+ ancestorFilter: ancestorFilter, |
|
| 206 |
+ images: imagesFilter, |
|
| 207 |
+ exitAllowed: filtExited, |
|
| 208 |
+ beforeFilter: beforeContFilter, |
|
| 209 |
+ sinceFilter: sinceContFilter, |
|
| 210 |
+ ContainerListOptions: config, |
|
| 211 |
+ names: daemon.nameIndex.GetAll(), |
|
| 212 | 212 |
}, nil |
| 213 | 213 |
} |
| 214 | 214 |
|
| ... | ... |
@@ -3,14 +3,16 @@ package daemon |
| 3 | 3 |
import ( |
| 4 | 4 |
"io" |
| 5 | 5 |
"strconv" |
| 6 |
+ "time" |
|
| 6 | 7 |
|
| 7 | 8 |
"github.com/Sirupsen/logrus" |
| 9 |
+ "github.com/docker/docker/api/types/backend" |
|
| 8 | 10 |
"github.com/docker/docker/container" |
| 9 | 11 |
"github.com/docker/docker/daemon/logger" |
| 10 | 12 |
"github.com/docker/docker/daemon/logger/jsonfilelog" |
| 11 | 13 |
derr "github.com/docker/docker/errors" |
| 12 | 14 |
"github.com/docker/docker/pkg/stdcopy" |
| 13 |
- "github.com/docker/engine-api/types/backend" |
|
| 15 |
+ timetypes "github.com/docker/engine-api/types/time" |
|
| 14 | 16 |
) |
| 15 | 17 |
|
| 16 | 18 |
// ContainerLogs hooks up a container's stdout and stderr streams |
| ... | ... |
@@ -21,7 +23,7 @@ func (daemon *Daemon) ContainerLogs(containerName string, config *backend.Contai |
| 21 | 21 |
return derr.ErrorCodeNoSuchContainer.WithArgs(containerName) |
| 22 | 22 |
} |
| 23 | 23 |
|
| 24 |
- if !(config.UseStdout || config.UseStderr) {
|
|
| 24 |
+ if !(config.ShowStdout || config.ShowStderr) {
|
|
| 25 | 25 |
return derr.ErrorCodeNeedStream |
| 26 | 26 |
} |
| 27 | 27 |
|
| ... | ... |
@@ -49,8 +51,17 @@ func (daemon *Daemon) ContainerLogs(containerName string, config *backend.Contai |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
logrus.Debug("logs: begin stream")
|
| 52 |
+ |
|
| 53 |
+ var since time.Time |
|
| 54 |
+ if config.Since != "" {
|
|
| 55 |
+ s, n, err := timetypes.ParseTimestamps(config.Since, 0) |
|
| 56 |
+ if err != nil {
|
|
| 57 |
+ return err |
|
| 58 |
+ } |
|
| 59 |
+ since = time.Unix(s, n) |
|
| 60 |
+ } |
|
| 52 | 61 |
readConfig := logger.ReadConfig{
|
| 53 |
- Since: config.Since, |
|
| 62 |
+ Since: since, |
|
| 54 | 63 |
Tail: tailLines, |
| 55 | 64 |
Follow: follow, |
| 56 | 65 |
} |
| ... | ... |
@@ -73,10 +84,10 @@ func (daemon *Daemon) ContainerLogs(containerName string, config *backend.Contai |
| 73 | 73 |
if config.Timestamps {
|
| 74 | 74 |
logLine = append([]byte(msg.Timestamp.Format(logger.TimeFormat)+" "), logLine...) |
| 75 | 75 |
} |
| 76 |
- if msg.Source == "stdout" && config.UseStdout {
|
|
| 76 |
+ if msg.Source == "stdout" && config.ShowStdout {
|
|
| 77 | 77 |
outStream.Write(logLine) |
| 78 | 78 |
} |
| 79 |
- if msg.Source == "stderr" && config.UseStderr {
|
|
| 79 |
+ if msg.Source == "stderr" && config.ShowStderr {
|
|
| 80 | 80 |
errStream.Write(logLine) |
| 81 | 81 |
} |
| 82 | 82 |
} |
| ... | ... |
@@ -5,10 +5,10 @@ import ( |
| 5 | 5 |
"errors" |
| 6 | 6 |
"runtime" |
| 7 | 7 |
|
| 8 |
+ "github.com/docker/docker/api/types/backend" |
|
| 8 | 9 |
"github.com/docker/docker/daemon/execdriver" |
| 9 | 10 |
"github.com/docker/docker/pkg/version" |
| 10 | 11 |
"github.com/docker/engine-api/types" |
| 11 |
- "github.com/docker/engine-api/types/backend" |
|
| 12 | 12 |
"github.com/docker/engine-api/types/versions/v1p20" |
| 13 | 13 |
) |
| 14 | 14 |
|