Skip to content

Commit 7b1cec1

Browse files
committed
Docker patches
1 parent 46ffce8 commit 7b1cec1

File tree

5 files changed

+21
-44
lines changed

5 files changed

+21
-44
lines changed

framework/components/blockchain/besu.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,7 @@ func newBesu(in *Input) (*Output, error) {
6767
},
6868
Labels: framework.DefaultTCLabels(),
6969
HostConfigModifier: func(h *container.HostConfig) {
70-
h.PortBindings = nat.PortMap{
71-
nat.Port(bindPortWs): []nat.PortBinding{
72-
{
73-
HostIP: "0.0.0.0",
74-
HostPort: bindPortWs,
75-
},
76-
},
77-
nat.Port(bindPort): []nat.PortBinding{
78-
{
79-
HostIP: "0.0.0.0",
80-
HostPort: bindPort,
81-
},
82-
},
83-
}
70+
h.PortBindings = framework.MapTheSamePort(bindPortWs, bindPort)
8471
},
8572
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second).WithPollInterval(200 * time.Millisecond),
8673
Cmd: entryPoint,

framework/components/blockchain/solana.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/docker/docker/api/types/container"
1313
"github.com/docker/docker/api/types/mount"
14-
"github.com/docker/go-connections/nat"
1514
"github.com/testcontainers/testcontainers-go"
1615
"github.com/testcontainers/testcontainers-go/wait"
1716

@@ -105,20 +104,7 @@ func newSolana(in *Input) (*Output, error) {
105104
WithStartupTimeout(30 * time.Second).
106105
WithPollInterval(100 * time.Millisecond),
107106
HostConfigModifier: func(h *container.HostConfig) {
108-
h.PortBindings = nat.PortMap{
109-
nat.Port(bindPort): []nat.PortBinding{
110-
{
111-
HostIP: "0.0.0.0",
112-
HostPort: bindPort,
113-
},
114-
},
115-
nat.Port(wsBindPort): []nat.PortBinding{
116-
{
117-
HostIP: "0.0.0.0",
118-
HostPort: wsBindPort,
119-
},
120-
},
121-
}
107+
h.PortBindings = framework.MapTheSamePort(bindPort, wsBindPort)
122108
h.Mounts = append(h.Mounts, mount.Mount{
123109
Type: mount.TypeBind,
124110
Source: contractsDir,

framework/components/clnode/clnode.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,17 @@ func generateEntryPoint() []string {
135135
func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
136136
httpPort := fmt.Sprintf("%s/tcp", DefaultHTTPPort)
137137
innerDebuggerPort := fmt.Sprintf("%d/tcp", DefaultDebuggerPort)
138-
debuggerPort := fmt.Sprintf("%d/tcp", in.Node.DebuggerPort)
139138
portBindings := nat.PortMap{
140139
nat.Port(httpPort): []nat.PortBinding{
141140
{
142141
HostIP: "0.0.0.0",
143-
HostPort: fmt.Sprintf("%d/tcp", in.Node.HTTPPort),
142+
HostPort: strconv.Itoa(in.Node.HTTPPort),
144143
},
145144
},
146145
nat.Port(innerDebuggerPort): []nat.PortBinding{
147146
{
148147
HostIP: "0.0.0.0",
149-
HostPort: debuggerPort,
148+
HostPort: strconv.Itoa(in.Node.DebuggerPort),
150149
},
151150
},
152151
}
@@ -160,7 +159,7 @@ func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
160159
customPorts = append(customPorts, fmt.Sprintf("%s/tcp", pp[1]))
161160

162161
dockerPort := nat.Port(fmt.Sprintf("%s/tcp", pp[1]))
163-
hostPort := fmt.Sprintf("%s/tcp", pp[0])
162+
hostPort := pp[0]
164163
portBindings[dockerPort] = []nat.PortBinding{
165164
{
166165
HostIP: "0.0.0.0",
@@ -171,11 +170,10 @@ func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
171170
customPorts = append(customPorts, fmt.Sprintf("%s/tcp", p))
172171

173172
dockerPort := nat.Port(fmt.Sprintf("%s/tcp", p))
174-
hostPort := fmt.Sprintf("%s/tcp", p)
175173
portBindings[dockerPort] = []nat.PortBinding{
176174
{
177175
HostIP: "0.0.0.0",
178-
HostPort: hostPort,
176+
HostPort: p,
179177
},
180178
}
181179
}

framework/components/postgres/postgres.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package postgres
33
import (
44
"context"
55
"fmt"
6+
"os"
7+
"strconv"
8+
"strings"
9+
"time"
10+
611
"github.com/docker/docker/api/types/container"
712
"github.com/docker/go-connections/nat"
813
"github.com/smartcontractkit/chainlink-testing-framework/framework"
914
"github.com/testcontainers/testcontainers-go"
1015
tcwait "github.com/testcontainers/testcontainers-go/wait"
11-
"os"
12-
"strings"
13-
"time"
1416
)
1517

1618
const (
@@ -121,7 +123,7 @@ func NewPostgreSQL(in *Input) (*Output, error) {
121123
nat.Port(bindPort): []nat.PortBinding{
122124
{
123125
HostIP: "0.0.0.0",
124-
HostPort: fmt.Sprintf("%d/tcp", portToExpose),
126+
HostPort: strconv.Itoa(portToExpose),
125127
},
126128
},
127129
}

framework/docker.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ func GetHost(container tc.Container) (string, error) {
4747
return host, nil
4848
}
4949

50-
func MapTheSamePort(port string) nat.PortMap {
51-
return nat.PortMap{
52-
nat.Port(port): []nat.PortBinding{
50+
func MapTheSamePort(ports ...string) nat.PortMap {
51+
portMap := nat.PortMap{}
52+
for _, port := range ports {
53+
// need to split off /tcp or /udp
54+
onlyPort := strings.SplitN(port, "/", 2)
55+
portMap[nat.Port(port)] = []nat.PortBinding{
5356
{
5457
HostIP: "0.0.0.0",
55-
HostPort: port,
58+
HostPort: onlyPort[0],
5659
},
57-
},
60+
}
5861
}
62+
return portMap
5963
}
6064

6165
func DefaultTCLabels() map[string]string {

0 commit comments

Comments
 (0)