Skip to content

Commit e3009ac

Browse files
committed
expose debugger if flag
1 parent d1a9e74 commit e3009ac

File tree

4 files changed

+35
-40
lines changed

4 files changed

+35
-40
lines changed

book/src/framework/components/debug.md

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,7 @@ Use `RESTY_DEBUG=true` to debug any API calls.
1010

1111
Use `SETH_LOG_LEVEL=trace|debug|info|warn` to debug [Seth](../../libs/seth.md).
1212

13-
## Using Delve (TBD)
14-
15-
You can use [Delve]() inside your containers to debug aplications.
16-
17-
Build them with `go build -gcflags="all=-N -l" -o myapp` and use an example `Dockerfile`:
18-
```
19-
FROM golang:1.20
20-
21-
# Install Delve
22-
RUN go install github.com/go-delve/delve/cmd/dlv@latest
23-
24-
# Set working directory
25-
WORKDIR /app
26-
27-
# Copy the application binary and source code (if needed for debugging)
28-
COPY myapp /app/myapp
29-
COPY . /app
30-
31-
# Expose the port for Delve
32-
EXPOSE 40000
33-
34-
# Start Delve in headless mode for remote debugging
35-
ENTRYPOINT ["dlv", "exec", "./myapp", "--headless", "--listen=:40000", "--api-version=2", "--accept-multiclient"]
36-
37-
```
38-
39-
Adding `Delve` to all our components is WIP right now.
40-
41-
To expose `Delve` port follow this [guide](state.md).
42-
13+
## Using Delve
4314

15+
All `dlv` debuggers are exposed on ports `40000, 40001, 40002 ...`
4416

framework/components/clnode/clnode.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"strconv"
1011
"strings"
1112
"sync"
1213
"text/template"
@@ -23,6 +24,7 @@ import (
2324
const (
2425
DefaultHTTPPort = "6688"
2526
DefaultP2PPort = "6690"
27+
DefaultDebuggerPort = 40000
2628
TmpImageName = "chainlink-tmp:latest"
2729
CustomPortSeparator = ":"
2830
)
@@ -54,6 +56,7 @@ type NodeInput struct {
5456
HTTPPort int `toml:"port"`
5557
P2PPort int `toml:"p2p_port"`
5658
CustomPorts []string `toml:"custom_ports"`
59+
DebuggerPort int `toml:"debugger_port"`
5760
}
5861

5962
// Output represents Chainlink node output, nodes and databases connection URLs
@@ -114,18 +117,38 @@ func NewNode(in *Input, pgOut *postgres.Output) (*Output, error) {
114117
return out, nil
115118
}
116119

120+
func generateEntryPoint() []string {
121+
entrypoint := []string{
122+
"/bin/sh", "-c",
123+
}
124+
if os.Getenv("CTF_CLNODE_DLV") == "true" {
125+
entrypoint = append(entrypoint, "dlv exec /usr/local/bin/chainlink --continue --listen=0.0.0.0:40000 --headless=true --api-version=2 --accept-multiclient -- -c /config/config -c /config/overrides -c /config/user-overrides -s /config/secrets -s /config/secrets-overrides -s /config/user-secrets-overrides node start -d -p /config/node_password -a /config/apicredentials")
126+
} else {
127+
entrypoint = append(entrypoint, "chainlink -c /config/config -c /config/overrides -c /config/user-overrides -s /config/secrets -s /config/secrets-overrides -s /config/user-secrets-overrides node start -d -p /config/node_password -a /config/apicredentials")
128+
}
129+
return entrypoint
130+
}
131+
117132
// generatePortBindings generates exposed ports and port bindings
118133
// exposes default CL node port
119134
// exposes custom_ports in format "host:docker" or map 1-to-1 if only "host" port is provided
120135
func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
121136
httpPort := fmt.Sprintf("%s/tcp", DefaultHTTPPort)
137+
innerDebuggerPort := fmt.Sprintf("%d/tcp", DefaultDebuggerPort)
138+
debuggerPort := fmt.Sprintf("%d/tcp", in.Node.DebuggerPort)
122139
portBindings := nat.PortMap{
123140
nat.Port(httpPort): []nat.PortBinding{
124141
{
125142
HostIP: "0.0.0.0",
126143
HostPort: fmt.Sprintf("%d/tcp", in.Node.HTTPPort),
127144
},
128145
},
146+
nat.Port(innerDebuggerPort): []nat.PortBinding{
147+
{
148+
HostIP: "0.0.0.0",
149+
HostPort: debuggerPort,
150+
},
151+
},
129152
}
130153
customPorts := make([]string, 0)
131154
for _, p := range in.Node.CustomPorts {
@@ -157,7 +180,7 @@ func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
157180
}
158181
}
159182
}
160-
exposedPorts := []string{httpPort}
183+
exposedPorts := []string{httpPort, strconv.Itoa(DefaultDebuggerPort)}
161184
exposedPorts = append(exposedPorts, customPorts...)
162185
return exposedPorts, portBindings, nil
163186
}
@@ -219,11 +242,8 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
219242
framework.DefaultNetworkName: {containerName},
220243
},
221244
ExposedPorts: exposedPorts,
222-
Entrypoint: []string{
223-
"/bin/sh", "-c",
224-
"chainlink -c /config/config -c /config/overrides -c /config/user-overrides -s /config/secrets -s /config/secrets-overrides -s /config/user-secrets-overrides node start -d -p /config/node_password -a /config/apicredentials",
225-
},
226-
WaitingFor: wait.ForHTTP("/").WithPort(DefaultHTTPPort).WithStartupTimeout(1 * time.Minute).WithPollInterval(200 * time.Millisecond),
245+
Entrypoint: generateEntryPoint(),
246+
WaitingFor: wait.ForHTTP("/").WithPort(DefaultHTTPPort).WithStartupTimeout(1 * time.Minute).WithPollInterval(200 * time.Millisecond),
227247
}
228248
if in.Node.HTTPPort != 0 && in.Node.P2PPort != 0 {
229249
req.HostConfigModifier = func(h *container.HostConfig) {

framework/components/simple_node_set/node_set.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func sharedDBSetup(in *Input, bcOut *blockchain.Output) (*Output, error) {
129129
Node: &clnode.NodeInput{
130130
HTTPPort: httpPortRangeStart + i,
131131
P2PPort: p2pPortRangeStart + i,
132+
DebuggerPort: clnode.DefaultDebuggerPort + i,
132133
CustomPorts: in.NodeSpecs[overrideIdx].Node.CustomPorts,
133134
Image: in.NodeSpecs[overrideIdx].Node.Image,
134135
Name: nodeName,

framework/examples/myproject/smoke.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
[blockchain_a]
33
# choose "anvil", "geth" or "besu"
4-
# uncomment the second line for "anvil"
5-
type = "besu"
6-
# docker_cmd_params = ["-b", "1"]
4+
# use docker_cmd_params = ["-b", "1"] for "anvil"
5+
type = "anvil"
6+
docker_cmd_params = ["-b", "1"]
77

88
[data_provider]
99
port = 9111
@@ -18,4 +18,6 @@
1818
[[nodeset.node_specs]]
1919

2020
[nodeset.node_specs.node]
21-
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
21+
docker_file = "plugins/chainlink.Dockerfile"
22+
docker_ctx = "/Users/fahrenheit/GolandProjects/chainlink"
23+
# image = "public.ecr.aws/chainlink/chainlink:v2.17.0"

0 commit comments

Comments
 (0)