Skip to content

Commit dfe2ae0

Browse files
feat(sui): support host port mapping (#2044)
* feat(sui): support host port mapping Allow a different port other than 9000 for sui to be mapped on the host since 9000 can be consumed by other apps. JIRA: https://smartcontract-it.atlassian.net/browse/CLD-500 * test(ton): use dev image The latest image for ton is no longer working as it cant be started up, dev still works
1 parent d92df0e commit dfe2ae0

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

framework/components/blockchain/sui.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/block-vision/sui-go-sdk/models"
1212
"github.com/docker/docker/api/types/container"
13+
"github.com/docker/go-connections/nat"
1314
"github.com/go-resty/resty/v2"
1415
"github.com/testcontainers/testcontainers-go"
1516
"github.com/testcontainers/testcontainers-go/wait"
@@ -81,10 +82,9 @@ func defaultSui(in *Input) {
8182
if in.Image == "" {
8283
in.Image = "mysten/sui-tools:devnet"
8384
}
84-
if in.Port != "" {
85-
framework.L.Warn().Msgf("'port' field is set but only default port can be used: %s", DefaultSuiNodePort)
85+
if in.Port == "" {
86+
in.Port = DefaultSuiNodePort
8687
}
87-
in.Port = DefaultSuiNodePort
8888
}
8989

9090
func newSui(in *Input) (*Output, error) {
@@ -97,7 +97,8 @@ func newSui(in *Input) (*Output, error) {
9797
return nil, err
9898
}
9999

100-
bindPort := fmt.Sprintf("%s/tcp", in.Port)
100+
// Sui container always listens on port 9000 internally
101+
containerPort := fmt.Sprintf("%s/tcp", DefaultSuiNodePort)
101102

102103
// default to amd64, unless otherwise specified
103104
imagePlatform := "linux/amd64"
@@ -107,15 +108,29 @@ func newSui(in *Input) (*Output, error) {
107108

108109
req := testcontainers.ContainerRequest{
109110
Image: in.Image,
110-
ExposedPorts: []string{in.Port, DefaultFaucetPort},
111+
ExposedPorts: []string{containerPort, DefaultFaucetPort},
111112
Name: containerName,
112113
Labels: framework.DefaultTCLabels(),
113114
Networks: []string{framework.DefaultNetworkName},
114115
NetworkAliases: map[string][]string{
115116
framework.DefaultNetworkName: {containerName},
116117
},
117118
HostConfigModifier: func(h *container.HostConfig) {
118-
h.PortBindings = framework.MapTheSamePort(bindPort, DefaultFaucetPort)
119+
// Map user-provided host port to container's default port (9000)
120+
h.PortBindings = nat.PortMap{
121+
nat.Port(containerPort): []nat.PortBinding{
122+
{
123+
HostIP: "0.0.0.0",
124+
HostPort: in.Port,
125+
},
126+
},
127+
nat.Port(DefaultFaucetPort): []nat.PortBinding{
128+
{
129+
HostIP: "0.0.0.0",
130+
HostPort: DefaultFaucetPortNum,
131+
},
132+
},
133+
}
119134
framework.ResourceLimitsFunc(h, in.ContainerResources)
120135
},
121136
ImagePlatform: imagePlatform,
@@ -165,7 +180,7 @@ func newSui(in *Input) (*Output, error) {
165180
Nodes: []*Node{
166181
{
167182
ExternalHTTPUrl: fmt.Sprintf("http://%s:%s", host, in.Port),
168-
InternalHTTPUrl: fmt.Sprintf("http://%s:%s", containerName, in.Port),
183+
InternalHTTPUrl: fmt.Sprintf("http://%s:%s", containerName, DefaultSuiNodePort),
169184
},
170185
},
171186
}, nil

framework/examples/myproject/smoke_ton.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[blockchain_a]
22
type = "ton"
3-
image = "ghcr.io/neodix42/mylocalton-docker:latest"
3+
image = "ghcr.io/neodix42/mylocalton-docker:dev"
44
port = "8000"
55

66
[blockchain_a.custom_env]

0 commit comments

Comments
 (0)