Skip to content

Commit eefe47d

Browse files
skudasovmchain0
andauthored
Add "host" network option and copy certificates for Anvil (#1856)
* dx-422-local-s3-provider * cli up command; key flags; setup; * test improved; * mod tidy * try host network mode for CI * check if that'd work for GAPv2 * more debug * use extra hosts * try only host network * cleanup * Revert "dx-422-local-s3-provider" This reverts commit 6ba53c8 * rm * changeset * fix port --------- Co-authored-by: mchain0 <[email protected]>
1 parent 7280adc commit eefe47d

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

framework/.changeset/v0.8.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Allow host network option for GAP integration

framework/components/blockchain/blockchain.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ type Input struct {
5454
SolanaPrograms map[string]string `toml:"solana_programs"`
5555
ContainerResources *framework.ContainerResources `toml:"resources"`
5656
CustomPorts []string `toml:"custom_ports"`
57+
58+
// GAPv2 specific params
59+
HostNetworkMode bool `toml:"host_network_mode"`
60+
CertificatesPath string `toml:"certificates_path"`
5761
}
5862

5963
// Output is a blockchain network output, ChainID and one or more nodes that forms the network

framework/components/blockchain/containers.go

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1414
)
1515

16+
const DefaultUbuntuCACertificatePath = "/etc/ssl/certs/ca-certificates.crt"
17+
1618
type ExposeWs = bool
1719

1820
const (
@@ -28,20 +30,36 @@ func baseRequest(in *Input, useWS ExposeWs) testcontainers.ContainerRequest {
2830
exposedPorts = append(exposedPorts, fmt.Sprintf("%s/tcp", in.WSPort))
2931
}
3032

31-
return testcontainers.ContainerRequest{
32-
Name: containerName,
33-
Labels: framework.DefaultTCLabels(),
34-
Networks: []string{framework.DefaultNetworkName},
35-
NetworkAliases: map[string][]string{
36-
framework.DefaultNetworkName: {containerName},
37-
},
38-
ExposedPorts: exposedPorts,
33+
req := testcontainers.ContainerRequest{
34+
Name: containerName,
35+
Labels: framework.DefaultTCLabels(),
3936
HostConfigModifier: func(h *container.HostConfig) {
40-
h.PortBindings = framework.MapTheSamePort(exposedPorts...)
4137
framework.ResourceLimitsFunc(h, in.ContainerResources)
38+
if in.HostNetworkMode {
39+
h.NetworkMode = "host"
40+
} else {
41+
h.PortBindings = framework.MapTheSamePort(exposedPorts...)
42+
}
4243
},
4344
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second).WithPollInterval(200 * time.Millisecond),
4445
}
46+
if !in.HostNetworkMode {
47+
req.ExposedPorts = exposedPorts
48+
req.Networks = []string{framework.DefaultNetworkName}
49+
req.NetworkAliases = map[string][]string{
50+
framework.DefaultNetworkName: {containerName},
51+
}
52+
}
53+
if in.CertificatesPath != "" {
54+
req.Files = []testcontainers.ContainerFile{
55+
{
56+
HostFilePath: in.CertificatesPath,
57+
ContainerFilePath: DefaultUbuntuCACertificatePath,
58+
FileMode: 0644,
59+
},
60+
}
61+
}
62+
return req
4563
}
4664

4765
func createGenericEvmContainer(in *Input, req testcontainers.ContainerRequest, useWS bool) (*Output, error) {
@@ -59,10 +77,18 @@ func createGenericEvmContainer(in *Input, req testcontainers.ContainerRequest, u
5977
return nil, err
6078
}
6179

62-
bindPort := req.ExposedPorts[0]
63-
mp, err := c.MappedPort(ctx, nat.Port(bindPort))
64-
if err != nil {
65-
return nil, err
80+
// specific case to bridge with GAPv2 in CI
81+
// we run blockchains on "host" network for connectivity
82+
var exposedPort string
83+
if in.HostNetworkMode {
84+
exposedPort = in.Port
85+
} else {
86+
bindPort := req.ExposedPorts[0]
87+
ep, err := c.MappedPort(ctx, nat.Port(bindPort))
88+
if err != nil {
89+
return nil, err
90+
}
91+
exposedPort = ep.Port()
6692
}
6793

6894
containerName := req.Name
@@ -76,8 +102,8 @@ func createGenericEvmContainer(in *Input, req testcontainers.ContainerRequest, u
76102
Container: c,
77103
Nodes: []*Node{
78104
{
79-
ExternalWSUrl: fmt.Sprintf("ws://%s:%s", host, mp.Port()),
80-
ExternalHTTPUrl: fmt.Sprintf("http://%s:%s", host, mp.Port()),
105+
ExternalWSUrl: fmt.Sprintf("ws://%s:%s", host, exposedPort),
106+
ExternalHTTPUrl: fmt.Sprintf("http://%s:%s", host, exposedPort),
81107
InternalWSUrl: fmt.Sprintf("ws://%s:%s", containerName, in.Port),
82108
InternalHTTPUrl: fmt.Sprintf("http://%s:%s", containerName, in.Port),
83109
},

0 commit comments

Comments
 (0)