File: 0020-add-patch-to-build-with-docker-26.patch

package info (click to toggle)
crowdsec 1.4.6-10
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 18,492 kB
  • sloc: sh: 2,870; makefile: 386; python: 74
file content (122 lines) | stat: -rw-r--r-- 5,287 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
diff --git a/pkg/acquisition/modules/docker/docker.go b/pkg/acquisition/modules/docker/docker.go
index 117eadd..b9619d9 100644
--- a/pkg/acquisition/modules/docker/docker.go
+++ b/pkg/acquisition/modules/docker/docker.go
@@ -15,6 +15,7 @@ import (
 	"github.com/crowdsecurity/crowdsec/pkg/types"
 	"github.com/crowdsecurity/dlog"
 	dockerTypes "github.com/docker/docker/api/types"
+	dockerContainer "github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/client"
 
 	"github.com/pkg/errors"
@@ -55,7 +56,7 @@ type DockerSource struct {
 	logger                *log.Entry
 	Client                client.CommonAPIClient
 	t                     *tomb.Tomb
-	containerLogsOptions  *dockerTypes.ContainerLogsOptions
+	containerLogsOptions  *dockerContainer.LogsOptions
 }
 
 type ContainerConfig struct {
@@ -119,7 +120,7 @@ func (d *DockerSource) Configure(Config []byte, logger *log.Entry) error {
 		d.Config.Since = time.Now().UTC().Format(time.RFC3339)
 	}
 
-	d.containerLogsOptions = &dockerTypes.ContainerLogsOptions{
+	d.containerLogsOptions = &dockerContainer.LogsOptions{
 		ShowStdout: d.Config.FollowStdout,
 		ShowStderr: d.Config.FollowStdErr,
 		Follow:     true,
@@ -170,7 +171,7 @@ func (d *DockerSource) ConfigureByDSN(dsn string, labels map[string]string, logg
 		return err
 	}
 
-	d.containerLogsOptions = &dockerTypes.ContainerLogsOptions{
+	d.containerLogsOptions = &dockerContainer.LogsOptions{
 		ShowStdout: d.Config.FollowStdout,
 		ShowStderr: d.Config.FollowStdErr,
 		Follow:     false,
@@ -266,7 +267,7 @@ func (d *DockerSource) SupportedModes() []string {
 //OneShotAcquisition reads a set of file and returns when done
 func (d *DockerSource) OneShotAcquisition(out chan types.Event, t *tomb.Tomb) error {
 	d.logger.Debug("In oneshot")
-	runningContainer, err := d.Client.ContainerList(context.Background(), dockerTypes.ContainerListOptions{})
+	runningContainer, err := d.Client.ContainerList(context.Background(), dockerContainer.ListOptions{})
 	if err != nil {
 		return err
 	}
@@ -399,7 +400,7 @@ func (d *DockerSource) WatchContainer(monitChan chan *ContainerConfig, deleteCha
 		case <-ticker.C:
 			// to track for garbage collection
 			runningContainersID := make(map[string]bool)
-			runningContainer, err := d.Client.ContainerList(context.Background(), dockerTypes.ContainerListOptions{})
+			runningContainer, err := d.Client.ContainerList(context.Background(), dockerContainer.ListOptions{})
 			if err != nil {
 				if strings.Contains(strings.ToLower(err.Error()), "cannot connect to the docker daemon at") {
 					for idx, container := range d.runningContainerState {
diff --git a/pkg/acquisition/modules/docker/docker_test.go b/pkg/acquisition/modules/docker/docker_test.go
index cf6e350..eeaf67a 100644
--- a/pkg/acquisition/modules/docker/docker_test.go
+++ b/pkg/acquisition/modules/docker/docker_test.go
@@ -216,7 +216,7 @@ container_name_regexp:
 
 }
 
-func (cli *mockDockerCli) ContainerList(ctx context.Context, options dockerTypes.ContainerListOptions) ([]dockerTypes.Container, error) {
+func (cli *mockDockerCli) ContainerList(ctx context.Context, options dockerContainer.ListOptions) ([]dockerTypes.Container, error) {
 	if readLogs == true {
 		return []dockerTypes.Container{}, nil
 	}
diff --git a/pkg/metabase/container.go b/pkg/metabase/container.go
index b53803b..2368a9b 100644
--- a/pkg/metabase/container.go
+++ b/pkg/metabase/container.go
@@ -5,7 +5,6 @@ import (
 	"context"
 	"fmt"
 	"runtime"
-	"time"
 
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/container"
@@ -113,7 +112,7 @@ func (c *Container) Create() error {
 
 func (c *Container) Start() error {
 	ctx := context.Background()
-	if err := c.CLI.ContainerStart(ctx, c.Name, types.ContainerStartOptions{}); err != nil {
+	if err := c.CLI.ContainerStart(ctx, c.Name, container.StartOptions{}); err != nil {
 		return fmt.Errorf("failed while starting %s : %s", c.ID, err)
 	}
 
@@ -126,7 +125,7 @@ func StartContainer(name string) error {
 		return fmt.Errorf("failed to create docker client : %s", err)
 	}
 	ctx := context.Background()
-	if err := cli.ContainerStart(ctx, name, types.ContainerStartOptions{}); err != nil {
+	if err := cli.ContainerStart(ctx, name, container.StartOptions{}); err != nil {
 		return fmt.Errorf("failed while starting %s : %s", name, err)
 	}
 
@@ -139,8 +138,10 @@ func StopContainer(name string) error {
 		return fmt.Errorf("failed to create docker client : %s", err)
 	}
 	ctx := context.Background()
-	var to time.Duration = 20 * time.Second
-	if err := cli.ContainerStop(ctx, name, &to); err != nil {
+	timeoutSeconds := 20
+	var to container.StopOptions
+	to.Timeout = &timeoutSeconds
+	if err := cli.ContainerStop(ctx, name, to); err != nil {
 		return fmt.Errorf("failed while stopping %s : %s", name, err)
 	}
 	log.Printf("container stopped successfully")
@@ -154,7 +155,7 @@ func RemoveContainer(name string) error {
 	}
 	ctx := context.Background()
 	log.Printf("Removing docker metabase %s", name)
-	if err := cli.ContainerRemove(ctx, name, types.ContainerRemoveOptions{}); err != nil {
+	if err := cli.ContainerRemove(ctx, name, container.RemoveOptions{}); err != nil {
 		return fmt.Errorf("failed to remove container %s : %s", name, err)
 	}
 	return nil