Skip to content

Commit

Permalink
Docker patches
Browse files Browse the repository at this point in the history
  • Loading branch information
smickovskid committed Jan 8, 2025
1 parent 46ffce8 commit 7b1cec1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 44 deletions.
15 changes: 1 addition & 14 deletions framework/components/blockchain/besu.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,7 @@ func newBesu(in *Input) (*Output, error) {
},
Labels: framework.DefaultTCLabels(),
HostConfigModifier: func(h *container.HostConfig) {
h.PortBindings = nat.PortMap{
nat.Port(bindPortWs): []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: bindPortWs,
},
},
nat.Port(bindPort): []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: bindPort,
},
},
}
h.PortBindings = framework.MapTheSamePort(bindPortWs, bindPort)
},
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second).WithPollInterval(200 * time.Millisecond),
Cmd: entryPoint,
Expand Down
16 changes: 1 addition & 15 deletions framework/components/blockchain/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/go-connections/nat"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"

Expand Down Expand Up @@ -105,20 +104,7 @@ func newSolana(in *Input) (*Output, error) {
WithStartupTimeout(30 * time.Second).
WithPollInterval(100 * time.Millisecond),
HostConfigModifier: func(h *container.HostConfig) {
h.PortBindings = nat.PortMap{
nat.Port(bindPort): []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: bindPort,
},
},
nat.Port(wsBindPort): []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: wsBindPort,
},
},
}
h.PortBindings = framework.MapTheSamePort(bindPort, wsBindPort)
h.Mounts = append(h.Mounts, mount.Mount{
Type: mount.TypeBind,
Source: contractsDir,
Expand Down
10 changes: 4 additions & 6 deletions framework/components/clnode/clnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,17 @@ func generateEntryPoint() []string {
func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
httpPort := fmt.Sprintf("%s/tcp", DefaultHTTPPort)
innerDebuggerPort := fmt.Sprintf("%d/tcp", DefaultDebuggerPort)
debuggerPort := fmt.Sprintf("%d/tcp", in.Node.DebuggerPort)
portBindings := nat.PortMap{
nat.Port(httpPort): []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: fmt.Sprintf("%d/tcp", in.Node.HTTPPort),
HostPort: strconv.Itoa(in.Node.HTTPPort),
},
},
nat.Port(innerDebuggerPort): []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: debuggerPort,
HostPort: strconv.Itoa(in.Node.DebuggerPort),
},
},
}
Expand All @@ -160,7 +159,7 @@ func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
customPorts = append(customPorts, fmt.Sprintf("%s/tcp", pp[1]))

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

dockerPort := nat.Port(fmt.Sprintf("%s/tcp", p))
hostPort := fmt.Sprintf("%s/tcp", p)
portBindings[dockerPort] = []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: hostPort,
HostPort: p,
},
}
}
Expand Down
10 changes: 6 additions & 4 deletions framework/components/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package postgres
import (
"context"
"fmt"
"os"
"strconv"
"strings"
"time"

"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/testcontainers/testcontainers-go"
tcwait "github.com/testcontainers/testcontainers-go/wait"
"os"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -121,7 +123,7 @@ func NewPostgreSQL(in *Input) (*Output, error) {
nat.Port(bindPort): []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: fmt.Sprintf("%d/tcp", portToExpose),
HostPort: strconv.Itoa(portToExpose),
},
},
}
Expand Down
14 changes: 9 additions & 5 deletions framework/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ func GetHost(container tc.Container) (string, error) {
return host, nil
}

func MapTheSamePort(port string) nat.PortMap {
return nat.PortMap{
nat.Port(port): []nat.PortBinding{
func MapTheSamePort(ports ...string) nat.PortMap {
portMap := nat.PortMap{}
for _, port := range ports {
// need to split off /tcp or /udp
onlyPort := strings.SplitN(port, "/", 2)
portMap[nat.Port(port)] = []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: port,
HostPort: onlyPort[0],
},
},
}
}
return portMap
}

func DefaultTCLabels() map[string]string {
Expand Down

0 comments on commit 7b1cec1

Please sign in to comment.