@@ -6,14 +6,12 @@ import (
66 "github.com/docker/docker/api/types/container"
77 "github.com/docker/docker/api/types/network"
88 "github.com/docker/docker/client"
9- "github.com/docker/go-connections/nat"
109 "github.com/icinga/icinga-testing/utils"
1110 "go.uber.org/zap"
12- "strconv"
1311 "time"
1412)
1513
16- const PORT = "3306/tcp "
14+ const PORT = "3306"
1715
1816type dockerCreator struct {
1917 * rootConnection
@@ -42,32 +40,14 @@ func NewDockerCreator(logger *zap.Logger, dockerClient *client.Client, container
4240 panic (err )
4341 }
4442
45- portNumber , err := utils .GetFreePort ()
46- if err != nil {
47- panic (err )
48- }
49- port , err := nat .NewPort ("tcp" , strconv .Itoa (portNumber ))
50- if err != nil {
51- panic (err )
52- }
43+ port := utils .NewPortDecision (dockerClient , PORT )
5344
5445 rootPassword := utils .RandomString (16 )
5546 cont , err := dockerClient .ContainerCreate (context .Background (), & container.Config {
56- ExposedPorts : nat.PortSet {
57- port : struct {}{},
58- PORT : struct {}{},
59- },
6047 Env : []string {"MYSQL_ROOT_PASSWORD=" + rootPassword },
6148 Cmd : nil ,
6249 Image : dockerImage ,
63- }, & container.HostConfig {PortBindings : nat.PortMap {
64- PORT : []nat.PortBinding {
65- {
66- HostIP : "0.0.0.0" ,
67- HostPort : port .Port (),
68- },
69- },
70- }}, & network.NetworkingConfig {
50+ }, & container.HostConfig {PortBindings : port .Map ()}, & network.NetworkingConfig {
7151 EndpointsConfig : map [string ]* network.EndpointSettings {
7252 networkName : {
7353 Aliases : []string {"mysql" },
@@ -96,14 +76,14 @@ func NewDockerCreator(logger *zap.Logger, dockerClient *client.Client, container
9676 }
9777 logger .Debug ("started mysql container" )
9878
99- containerAddress := utils .MustString (utils .DockerContainerAddress (context .Background (), dockerClient , cont .ID ))
100-
10179 d := & dockerCreator {
102- rootConnection : newRootConnection (containerAddress , port .Port (), "root" , rootPassword ),
103- logger : logger ,
104- client : dockerClient ,
105- containerId : cont .ID ,
106- containerName : containerName ,
80+ rootConnection : newRootConnection (
81+ port .Address (context .Background (), dockerClient , cont .ID ), port .Port (), "root" , rootPassword ,
82+ ),
83+ logger : logger ,
84+ client : dockerClient ,
85+ containerId : cont .ID ,
86+ containerName : containerName ,
10787 }
10888
10989 for attempt := 1 ; ; attempt ++ {
0 commit comments