Skip to content

Commit 0dd918b

Browse files
authored
Docker copy and P2P fixes (#1349)
docker copy command, fix p2p
1 parent 9c9821d commit 0dd918b

File tree

18 files changed

+132
-123
lines changed

18 files changed

+132
-123
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- [Components Cleanup](framework/components/cleanup.md)
1919
- [Components Caching](framework/components/caching.md)
2020
- [Mocking Services](framework/components/mocking.md)
21+
- [Copying Files](framework/copying_files.md)
2122
- [External Environment](framework/components/external.md)
2223
- [Secrets]()
2324
- [Observability Stack](framework/observability/observability_stack.md)

book/src/framework/components/state.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ When deploying a component, you can explicitly configure port ranges if the defa
99
Defaults are:
1010
- [NodeSet](../components/chainlink/nodeset.md) (Node HTTP API): `10000..100XX`
1111
- [NodeSet](../components/chainlink/nodeset.md) (Node P2P API): `12000..120XX`
12+
- Shared `PostgreSQL` volume is called `postgresql_data`
1213
```
1314
[nodeset]
1415
# HTTP API port range start, each new node get port incremented (host machine)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copying Files
2+
3+
You can copy files to containers by using the `ContainerName` from the output and specifying the source `src` and destination `dst` paths.
4+
5+
However, using this API is discouraged and will be **deprecated** in the future, as it violates the principles of "black-box" testing. If your service relies on this functionality, consider designing a configuration or API to address the requirement instead.
6+
7+
```go
8+
bc, err := blockchain.NewBlockchainNetwork(&blockchain.Input{
9+
...
10+
})
11+
require.NoError(t, err)
12+
13+
err = dockerClient.CopyFile(bc.ContainerName, "local_file.txt", "/home")
14+
require.NoError(t, err)
15+
```

framework/.changeset/v0.2.7.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Do not expose P2P URL to prevent confusion
2+
- Add container names into outputs
3+
- Add `CopyFile` command for Docker

framework/components/blockchain/anvil.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ func deployAnvil(in *Input) (*Output, error) {
5555
return nil, err
5656
}
5757
return &Output{
58-
UseCache: true,
59-
ChainID: in.ChainID,
58+
UseCache: true,
59+
ChainID: in.ChainID,
60+
ContainerName: containerName,
6061
Nodes: []*Node{
6162
{
6263
HostWSUrl: fmt.Sprintf("ws://%s:%s", host, mp.Port()),

framework/components/blockchain/blockchain.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ type Input struct {
1717

1818
// Output is a blockchain network output, ChainID and one or more nodes that forms the network
1919
type Output struct {
20-
UseCache bool `toml:"use_cache"`
21-
ChainID string `toml:"chain_id"`
22-
Nodes []*Node `toml:"nodes"`
20+
UseCache bool `toml:"use_cache"`
21+
ContainerName string `toml:"container_name"`
22+
ChainID string `toml:"chain_id"`
23+
Nodes []*Node `toml:"nodes"`
2324
}
2425

2526
// Node represents blockchain node output, URLs required for connection locally and inside docker network

framework/components/clnode/clnode.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ type Output struct {
6464
type NodeOut struct {
6565
APIAuthUser string `toml:"api_auth_user"`
6666
APIAuthPassword string `toml:"api_auth_password"`
67+
ContainerName string `toml:"container_name"`
6768
HostURL string `toml:"url"`
68-
HostP2PURL string `toml:"p2p_url"`
6969
DockerURL string `toml:"docker_internal_url"`
7070
DockerP2PUrl string `toml:"p2p_docker_internal_url"`
7171
}
@@ -121,7 +121,7 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
121121
if err != nil {
122122
return nil, err
123123
}
124-
cfgPath, err := writeDefaultConfig(in)
124+
cfgPath, err := writeDefaultConfig()
125125
if err != nil {
126126
return nil, err
127127
}
@@ -147,7 +147,6 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
147147
}
148148

149149
httpPort := fmt.Sprintf("%s/tcp", DefaultHTTPPort)
150-
p2pPort := fmt.Sprintf("%s/udp", DefaultP2PPort)
151150
var containerName string
152151
if in.Node.Name != "" {
153152
containerName = in.Node.Name
@@ -158,7 +157,7 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
158157
for _, p := range in.Node.CustomPorts {
159158
customPorts = append(customPorts, fmt.Sprintf("%d/tcp", p))
160159
}
161-
exposedPorts := []string{httpPort, p2pPort}
160+
exposedPorts := []string{httpPort}
162161
exposedPorts = append(exposedPorts, customPorts...)
163162

164163
portBindings := nat.PortMap{
@@ -168,12 +167,6 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
168167
HostPort: fmt.Sprintf("%d/tcp", in.Node.HTTPPort),
169168
},
170169
},
171-
nat.Port(p2pPort): []nat.PortBinding{
172-
{
173-
HostIP: "0.0.0.0",
174-
HostPort: fmt.Sprintf("%d/udp", in.Node.P2PPort),
175-
},
176-
},
177170
}
178171
for _, p := range customPorts {
179172
portBindings[nat.Port(p)] = []nat.PortBinding{
@@ -283,13 +276,12 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
283276
}
284277

285278
mp := nat.Port(fmt.Sprintf("%d/tcp", in.Node.HTTPPort))
286-
mpP2P := nat.Port(fmt.Sprintf("%d/udp", in.Node.P2PPort))
287279

288280
return &NodeOut{
289281
APIAuthUser: DefaultAPIUser,
290282
APIAuthPassword: DefaultAPIPassword,
283+
ContainerName: containerName,
291284
HostURL: fmt.Sprintf("http://%s:%s", host, mp.Port()),
292-
HostP2PURL: fmt.Sprintf("http://%s:%s", host, mpP2P.Port()),
293285
DockerURL: fmt.Sprintf("http://%s:%s", containerName, DefaultHTTPPort),
294286
DockerP2PUrl: fmt.Sprintf("http://%s:%s", containerName, DefaultP2PPort),
295287
}, nil
@@ -300,7 +292,7 @@ type DefaultCLNodeConfig struct {
300292
SecureCookies bool
301293
}
302294

303-
func generateDefaultConfig(in *Input) (string, error) {
295+
func generateDefaultConfig() (string, error) {
304296
config := DefaultCLNodeConfig{
305297
HTTPPort: DefaultHTTPPort,
306298
SecureCookies: false,
@@ -348,8 +340,8 @@ func writeDefaultSecrets(pgOut *postgres.Output) (*os.File, error) {
348340
return WriteTmpFile(secretsOverrides, "secrets.toml")
349341
}
350342

351-
func writeDefaultConfig(in *Input) (*os.File, error) {
352-
cfg, err := generateDefaultConfig(in)
343+
func writeDefaultConfig() (*os.File, error) {
344+
cfg, err := generateDefaultConfig()
353345
if err != nil {
354346
return nil, err
355347
}

framework/components/clnode/clnode_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func checkBasicOutputs(t *testing.T, output *clnode.Output) {
2323
require.Contains(t, output.Node.DockerP2PUrl, "cl-node")
2424
require.NotNil(t, output.PostgreSQL)
2525
require.Contains(t, output.PostgreSQL.Url, "postgresql://chainlink:[email protected]")
26-
require.Contains(t, output.PostgreSQL.DockerInternalURL, "postgresql://chainlink:thispasswordislongenough@postgresql-")
26+
require.Contains(t, output.PostgreSQL.DockerInternalURL, "postgresql://chainlink:thispasswordislongenough@ns-postgresql")
2727
}
2828

2929
func TestComponentDockerNodeWithSharedDB(t *testing.T) {

framework/components/postgres/postgres.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ type Input struct {
3333

3434
type Output struct {
3535
Url string `toml:"url"`
36+
ContainerName string `toml:"container_name"`
3637
DockerInternalURL string `toml:"docker_internal_url"`
3738
}
3839

3940
func NewPostgreSQL(in *Input) (*Output, error) {
4041
ctx := context.Background()
4142

4243
bindPort := fmt.Sprintf("%s/tcp", Port)
43-
containerName := framework.DefaultTCName("postgresql")
44+
containerName := framework.DefaultTCName("ns-postgresql")
4445

4546
var sqlCommands []string
4647
for i := 0; i <= in.Databases; i++ {
@@ -126,6 +127,7 @@ func NewPostgreSQL(in *Input) (*Output, error) {
126127
return nil, err
127128
}
128129
return &Output{
130+
ContainerName: containerName,
129131
DockerInternalURL: fmt.Sprintf(
130132
"postgresql://%s:%s@%s:%s/%s?sslmode=disable",
131133
User,

framework/components/simple_node_set/node_set.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ func printURLs(out *Output) {
6565
httpURLs, p2pURLs, pgURLs := make([]string, 0), make([]string, 0), make([]string, 0)
6666
for _, n := range out.CLNodes {
6767
httpURLs = append(httpURLs, n.Node.HostURL)
68-
p2pURLs = append(p2pURLs, n.Node.HostP2PURL)
6968
pgURLs = append(pgURLs, n.PostgreSQL.Url)
7069
}
7170
framework.L.Info().Any("UI", httpURLs).Send()

0 commit comments

Comments
 (0)