Skip to content

Commit ded6df1

Browse files
masterashuCopilot
andauthored
Add go remote debugging support in TILT (#4216)
Summary of Changes: * Added go compiler flags to flow build command in flow.dockerfile (disabled optimizations, recommended for debugging) * Added a new stage in flow.dockerfile with dlv (delve debugger) entrypoint which exposes endpoint to attach debugger to and updated the same in Tiltfile * VSCode launch config which attaches the debugger and resolved breakpoints etc. --------- Co-authored-by: Copilot <copilot@github.com>
1 parent fa5ae4d commit ded6df1

6 files changed

Lines changed: 189 additions & 35 deletions

File tree

.env.example

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,24 @@ AWS_EC2_METADATA_DISABLED="true"
5050
MINIO_ROOT_USER=_peerdb_minioadmin
5151
MINIO_ROOT_PASSWORD=_peerdb_minioadmin
5252

53-
TZ='UTC'
53+
# Set to 1 for enabling go debugger in dockerfile and Tilt Setup
54+
DOCKER_GO_DEBUG_FLOW_API=
55+
DOCKER_GO_DEBUG_FLOW_WORKER=
56+
DOCKER_GO_DEBUG_FLOW_SNAPSHOT_WORKER=
57+
58+
TZ='UTC'
59+
60+
## Port Overrides for parallel tilt and docker-compose runs.
61+
# PEERDB_CATALOG_PORT=19901
62+
# PEERDB_NEXUS_PORT=19900
63+
# PEERDB_SWITCHBOARD_PORT=15732
64+
# PEERBD_UI_PORT=13030
65+
# TEMPORAL_PORT=17233
66+
# TEMPORAL_UI_PORT=18085
67+
# FLOW_API_PORT=18112
68+
# FLOW_API_HTTP_PORT=18113
69+
# DOCKER_GO_DEBUG_PORT_FLOW_WORKER=14001
70+
# DOCKER_GO_DEBUG_PORT_FLOW_SNAPSHOT_WORKER=14002
71+
# DOCKER_GO_DEBUG_PORT_FLOW_API=14003
72+
# MINIO_PORT=19001
73+
# MINIO_CONSOLE_PORT=19002

.vscode/launch.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Tilt Debug: Flow Worker",
6+
"type": "go",
7+
"request": "attach",
8+
"mode": "remote",
9+
"remotePath": "/root",
10+
"debugAdapter": "dlv-dap",
11+
"hideSystemGoroutines": true,
12+
"showGlobalVariables": true,
13+
"substitutePath": [
14+
{
15+
"from": "${workspaceFolder}/flow",
16+
"to": "/root/flow"
17+
}
18+
],
19+
"port": 4001,
20+
"host": "127.0.0.1"
21+
},
22+
{
23+
"name": "Tilt Debug: Flow Snapshot Worker",
24+
"type": "go",
25+
"request": "attach",
26+
"mode": "remote",
27+
"remotePath": "/root",
28+
"debugAdapter": "dlv-dap",
29+
"hideSystemGoroutines": true,
30+
"showGlobalVariables": true,
31+
"substitutePath": [
32+
{
33+
"from": "${workspaceFolder}/flow",
34+
"to": "/root/flow"
35+
}
36+
],
37+
"port": 4002,
38+
"host": "127.0.0.1"
39+
},
40+
{
41+
"name": "Tilt Debug: Flow API",
42+
"type": "go",
43+
"request": "attach",
44+
"mode": "remote",
45+
"remotePath": "/root",
46+
"debugAdapter": "dlv-dap",
47+
"hideSystemGoroutines": true,
48+
"showGlobalVariables": true,
49+
"substitutePath": [
50+
{
51+
"from": "${workspaceFolder}/flow",
52+
"to": "/root/flow"
53+
}
54+
],
55+
"port": 4003,
56+
"host": "127.0.0.1"
57+
}
58+
]
59+
}

Tiltfile

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,46 @@ update_settings(max_parallel_updates=10)
22

33
allow_k8s_contexts(k8s_context()) # to unblock local() in local set-ups with a Kubernetes context configured, like Docker Desktop
44

5-
docker_compose('./docker-compose-dev.yml')
5+
def resolve_env(var_name, default=None):
6+
for line in str(read_file('.env')).splitlines():
7+
if line.startswith(var_name + '='):
8+
return line.strip().split('=', 1)[1]
9+
return default
10+
11+
docker_compose('./docker-compose-dev.yml', project_name='peerdb-' + resolve_env('DEFAULT_TILT_PORT', '10350'), env_file='.env')
12+
13+
peerbd_ui_port = resolve_env('PEERBD_UI_PORT', '3030')
14+
temporal_port = resolve_env('TEMPORAL_PORT', '7233')
15+
temporal_ui_port = resolve_env('TEMPORAL_UI_PORT', '8085')
16+
flow_api_grpc_port = resolve_env('FLOW_API_PORT', '8112')
17+
flow_api_http_port = resolve_env('FLOW_API_HTTP_PORT', '8113')
18+
docker_go_debug_port_flow_worker = resolve_env('DOCKER_GO_DEBUG_PORT_FLOW_WORKER', '4001')
19+
docker_go_debug_port_flow_snapshot_worker = resolve_env('DOCKER_GO_DEBUG_PORT_FLOW_SNAPSHOT_WORKER', '4002')
20+
docker_go_debug_port_flow_api = resolve_env('DOCKER_GO_DEBUG_PORT_FLOW_API', '4003')
621

722
flow_ignore = ['flow/e2e/', 'flow/**/*_test.go']
823

924
docker_build('flow-api', '.',
1025
dockerfile='stacks/flow.Dockerfile',
11-
target='flow-api',
26+
target='flow-api-debug' if resolve_env('DOCKER_GO_DEBUG_FLOW_API') in ('1', 'true') else 'flow-api',
1227
only=['flow/', 'stacks/flow.Dockerfile'],
1328
ignore=flow_ignore,
14-
build_args={'PEERDB_VERSION_SHA_SHORT': os.getenv('PEERDB_VERSION_SHA_SHORT', 'unknown')},
29+
build_args={'DEBUG_BUILD': resolve_env('DOCKER_GO_DEBUG_FLOW_API',''),'PEERDB_VERSION_SHA_SHORT': os.getenv('PEERDB_VERSION_SHA_SHORT', 'unknown')},
1530
)
1631

1732
docker_build('flow-worker', '.',
1833
dockerfile='stacks/flow.Dockerfile',
19-
target='flow-worker',
34+
target='flow-worker-debug' if resolve_env('DOCKER_GO_DEBUG_FLOW_WORKER') in ('1', 'true') else 'flow-worker',
2035
only=['flow/', 'stacks/flow.Dockerfile'],
36+
build_args={'DEBUG_BUILD': resolve_env('DOCKER_GO_DEBUG_FLOW_WORKER','')},
2137
ignore=flow_ignore,
2238
)
2339

2440
docker_build('flow-snapshot-worker', '.',
2541
dockerfile='stacks/flow.Dockerfile',
26-
target='flow-snapshot-worker',
42+
target='flow-snapshot-worker-debug' if resolve_env('DOCKER_GO_DEBUG_FLOW_SNAPSHOT_WORKER') in ('1', 'true') else 'flow-snapshot-worker',
2743
only=['flow/', 'stacks/flow.Dockerfile'],
44+
build_args={'DEBUG_BUILD': resolve_env('DOCKER_GO_DEBUG_FLOW_SNAPSHOT_WORKER','')},
2845
ignore=flow_ignore,
2946
)
3047

@@ -51,14 +68,14 @@ local_resource(
5168
)
5269

5370
dc_resource('peerdb-ui', resource_deps=['proto-gen'], labels=['PeerDB'], links=[
54-
link('http://localhost:3030', 'PeerDB UI'),
71+
link('http://localhost:' + str(peerbd_ui_port), 'PeerDB UI'),
5572
])
5673
dc_resource('flow-api', resource_deps=['proto-gen'], labels=['PeerDB'], links=[
57-
link('http://localhost:8112', 'Flow API gRPC'),
58-
link('http://localhost:8113', 'Flow API HTTP'),
74+
link('http://localhost:' + str(flow_api_grpc_port), 'Flow API gRPC'),
75+
link('http://localhost:' + str(flow_api_http_port), 'Flow API HTTP'),
5976
])
6077
dc_resource('temporal-ui', labels=['PeerDB'], links=[
61-
link('http://localhost:8085', 'Temporal UI'),
78+
link('http://localhost:' + str(temporal_ui_port), 'Temporal UI'),
6279
])
6380
dc_resource('catalog', labels=['PeerDB'])
6481
dc_resource('temporal', labels=['PeerDB'])
@@ -235,13 +252,6 @@ def connector_test(connector, extra_deps=[], vars_overrides={}):
235252
)
236253

237254
# These are overrides to provide different MySQL flavors with the same test definitions.
238-
239-
def resolve_env(var_name):
240-
for line in str(read_file('.env')).splitlines():
241-
if line.startswith(var_name + '='):
242-
return line.strip().split('=', 1)[1]
243-
return None
244-
245255
mysql_gtid_vars = {
246256
'CI_MYSQL_PORT': resolve_env('CI_MYSQL_GTID_PORT'),
247257
'CI_MYSQL_VERSION': resolve_env('CI_MYSQL_GTID_VERSION'),

ancillary-docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,5 @@ volumes:
215215

216216
networks:
217217
default:
218-
name: peerdb_network
218+
name: peerdb_network_${DEFAULT_TILT_PORT:-default}
219219
external: true

docker-compose-dev.yml

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
name: peerdb-quickstart-dev
22

3+
# Public facing ports for services to prevent conflicts.
4+
# Overridable using environment variables for flexibility when using multiple tilt environments
5+
x-ports:
6+
- &peerdb-catalog-port ${PEERDB_CATALOG_PORT:-9901}:5432
7+
- &peerdb-nexus-port ${PEERDB_NEXUS_PORT:-9900}:9900
8+
- &peerdb-switchboard-port ${PEERDB_SWITCHBOARD_PORT:-5732}:5732
9+
- &peerdb-ui-port ${PEERBD_UI_PORT:-3030}:3000
10+
- &temporal-port ${TEMPORAL_PORT:-7233}:7233
11+
- &temporal-ui-port ${TEMPORAL_UI_PORT:-8085}:8080
12+
- &flow-api-grpc-port ${FLOW_API_PORT:-8112}:8112
13+
- &flow-api-http-port ${FLOW_API_HTTP_PORT:-8113}:8113
14+
- &flow-worker-debug-port ${DOCKER_GO_DEBUG_PORT_FLOW_WORKER:-4001}:40000
15+
- &flow-snapshot-worker-debug-port ${DOCKER_GO_DEBUG_PORT_FLOW_SNAPSHOT_WORKER:-4002}:40000
16+
- &flow-api-debug-port ${DOCKER_GO_DEBUG_PORT_FLOW_API:-4003}:40000
17+
- &minio-port ${MINIO_PORT:-9001}:9000
18+
- &minio-console-port ${MINIO_CONSOLE_PORT:-9002}:36987
19+
320
x-minio-config: &minio-config
421
PEERDB_CLICKHOUSE_AWS_CREDENTIALS_AWS_ACCESS_KEY_ID: _peerdb_minioadmin
522
MINIO_ROOT_USER: _peerdb_minioadmin
623
PEERDB_CLICKHOUSE_AWS_CREDENTIALS_AWS_SECRET_ACCESS_KEY: _peerdb_minioadmin
724
MINIO_ROOT_PASSWORD: _peerdb_minioadmin
825
PEERDB_CLICKHOUSE_AWS_CREDENTIALS_AWS_REGION: us-east-1
9-
PEERDB_CLICKHOUSE_AWS_CREDENTIALS_AWS_ENDPOINT_URL_S3: http://host.docker.internal:9001
26+
PEERDB_CLICKHOUSE_AWS_CREDENTIALS_AWS_ENDPOINT_URL_S3: http://host.docker.internal:${MINIO_PORT:-9001}
1027
PEERDB_CLICKHOUSE_AWS_S3_BUCKET_NAME: peerdb
1128

1229
x-catalog-config: &catalog-config
@@ -44,7 +61,7 @@ services:
4461
image: postgres:18-alpine@sha256:54451ecb8ab38c24c3ec123f2fd501303a3a1856a5c66e98cecf2460d5e1e9d7
4562
command: -c config_file=/etc/postgresql.conf
4663
ports:
47-
- 9901:5432
64+
- *peerdb-catalog-port
4865
environment:
4966
PGUSER: postgres
5067
POSTGRES_PASSWORD: postgres
@@ -77,7 +94,7 @@ services:
7794
- DYNAMIC_CONFIG_FILE_PATH=config/dynamicconfig/development-sql.yaml
7895
image: temporalio/auto-setup:1.29@sha256:d33d1402e8b895329e27a0d0e7cc2f034e0aa70f0dab6aa95b306d7ae2716f67
7996
ports:
80-
- 7233:7233
97+
- *temporal-port
8198
volumes:
8299
- ./volumes/temporal-dynamicconfig:/etc/temporal/config/dynamicconfig
83100
labels:
@@ -114,7 +131,7 @@ services:
114131
- TEMPORAL_CSRF_COOKIE_INSECURE=true
115132
image: temporalio/ui:2.49.1@sha256:a066bdf5c4de689cabaf80cc357871f1db5e6d750a6bcfc42e877b913e31ef24
116133
ports:
117-
- 8085:8080
134+
- *temporal-ui-port
118135

119136
flow-api:
120137
container_name: flow_api
@@ -126,9 +143,10 @@ services:
126143
args:
127144
PEERDB_VERSION_SHA_SHORT: ${PEERDB_VERSION_SHA_SHORT:-}
128145
ports:
129-
- 8112:8112
130-
- 8113:8113
131-
- 5732:5732
146+
- *flow-api-grpc-port
147+
- *flow-api-http-port
148+
- *peerdb-switchboard-port
149+
- *flow-api-debug-port
132150
environment:
133151
<<: [*catalog-config, *flow-worker-env, *minio-config]
134152
PEERDB_ALLOWED_TARGETS:
@@ -148,6 +166,8 @@ services:
148166
context: .
149167
dockerfile: stacks/flow.Dockerfile
150168
target: flow-snapshot-worker
169+
ports:
170+
- *flow-snapshot-worker-debug-port
151171
environment:
152172
<<: [*catalog-config, *flow-worker-env, *minio-config]
153173
depends_on:
@@ -161,6 +181,13 @@ services:
161181
context: .
162182
dockerfile: stacks/flow.Dockerfile
163183
target: flow-worker
184+
ports:
185+
- *flow-worker-debug-port
186+
# The below options were mentioned to be required, but it works without them, so leaving them commented out for now. If you run into issues with Delve, try uncommenting these.
187+
# security_opt:
188+
# - "seccomp:unconfined" # Required for Delve
189+
# cap_add:
190+
# - SYS_PTRACE # Required for Delve
164191
environment:
165192
<<: [*catalog-config, *flow-worker-env, *minio-config]
166193
extra_hosts:
@@ -186,7 +213,7 @@ services:
186213
RUST_LOG: info
187214
RUST_BACKTRACE: 1
188215
ports:
189-
- 9900:9900
216+
- *peerdb-nexus-port
190217
depends_on:
191218
catalog:
192219
condition: service_healthy
@@ -199,7 +226,7 @@ services:
199226
dockerfile: stacks/peerdb-ui.Dockerfile
200227
target: dev
201228
ports:
202-
- 3030:3000
229+
- *peerdb-ui-port
203230
volumes:
204231
# Mount local ui/ directory for hot reload
205232
- ./ui:/app
@@ -229,8 +256,8 @@ services:
229256
volumes:
230257
- minio-data:/data
231258
ports:
232-
- "9001:9000"
233-
- "9002:36987"
259+
- *minio-port
260+
- *minio-console-port
234261
environment:
235262
<<: *minio-config
236263
entrypoint: >
@@ -248,4 +275,4 @@ volumes:
248275

249276
networks:
250277
default:
251-
name: peerdb_network
278+
name: peerdb_network_${DEFAULT_TILT_PORT:-default}

stacks/flow.Dockerfile

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# syntax=docker/dockerfile:1.23@sha256:2780b5c3bab67f1f76c781860de469442999ed1a0d7992a5efdf2cffc0e3d769
22

33
FROM golang:1.26-alpine@sha256:f85330846cde1e57ca9ec309382da3b8e6ae3ab943d2739500e08c86393a21b1 AS builder
4+
# Allow build flags to be passed in at build time, for example debug flags
5+
ARG DEBUG_BUILD
6+
ENV DEBUG_BUILD=${DEBUG_BUILD}
7+
48
RUN apk add --no-cache gcc geos-dev musl-dev
59
WORKDIR /root/flow
610

@@ -21,7 +25,10 @@ ENV CGO_ENABLED=1
2125
# Generate the typed handler wrapper
2226
RUN go generate
2327
ENV GOCACHE=/root/.cache/go-build
24-
RUN --mount=type=cache,target="/root/.cache/go-build" go build -o /root/peer-flow
28+
RUN --mount=type=cache,target="/root/.cache/go-build" go build ${DEBUG_BUILD:+-gcflags} ${DEBUG_BUILD:+"all=-N -l"} -o /root/peer-flow
29+
RUN --mount=type=cache,target="/root/.cache/go-build" if [[ "$DEBUG_BUILD" = "1" ]]; then \
30+
go install github.com/go-delve/delve/cmd/dlv@latest; \
31+
fi
2532

2633
FROM alpine:3.23@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11 AS flow-base
2734
ENV TZ=UTC
@@ -32,14 +39,31 @@ RUN apk add --no-cache ca-certificates geos && \
3239
USER peerdb
3340
WORKDIR /home/peerdb
3441
COPY --from=builder --chown=peerdb /root/peer-flow .
42+
ENTRYPOINT [ "/home/peerdb/peer-flow" ]
43+
44+
# Debug Image with Delve installed and the binary built with debug flags
45+
FROM flow-base AS flow-base-debug
46+
USER root
47+
COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
48+
ENV TEMPORAL_DEBUG=1
49+
EXPOSE 40000
50+
ENTRYPOINT ["dlv", "--headless", "--continue", "--accept-multiclient", "--listen=:40000", "--api-version=2", "exec", "/home/peerdb/peer-flow", "--"]
3551

3652
FROM flow-base AS flow-api
3753

3854
ARG PEERDB_VERSION_SHA_SHORT
3955
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
4056

4157
EXPOSE 8112 8113
42-
ENTRYPOINT ["./peer-flow", "api", "--port", "8112", "--gateway-port", "8113"]
58+
CMD ["api", "--port", "8112", "--gateway-port", "8113"]
59+
60+
FROM flow-base-debug AS flow-api-debug
61+
62+
ARG PEERDB_VERSION_SHA_SHORT
63+
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
64+
65+
EXPOSE 8112 8113
66+
CMD ["api", "--port", "8112", "--gateway-port", "8113"]
4367

4468
FROM flow-base AS flow-worker
4569

@@ -53,17 +77,31 @@ ENV OTEL_EXPORTER_OTLP_COMPRESSION=gzip
5377
ARG PEERDB_VERSION_SHA_SHORT
5478
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
5579

56-
ENTRYPOINT ["./peer-flow", "worker"]
80+
CMD ["worker"]
81+
82+
FROM flow-base-debug AS flow-worker-debug
83+
ENV OTEL_METRIC_EXPORT_INTERVAL=10000
84+
ENV OTEL_EXPORTER_OTLP_COMPRESSION=gzip
85+
ARG PEERDB_VERSION_SHA_SHORT
86+
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
87+
CMD ["worker"]
88+
5789

5890
FROM flow-base AS flow-snapshot-worker
5991

6092
ARG PEERDB_VERSION_SHA_SHORT
6193
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
62-
ENTRYPOINT ["./peer-flow", "snapshot-worker"]
94+
CMD ["snapshot-worker"]
95+
96+
FROM flow-base-debug AS flow-snapshot-worker-debug
97+
98+
ARG PEERDB_VERSION_SHA_SHORT
99+
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
100+
CMD ["snapshot-worker"]
63101

64102

65103
FROM flow-base AS flow-maintenance
66104

67105
ARG PEERDB_VERSION_SHA_SHORT
68106
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
69-
ENTRYPOINT ["./peer-flow", "maintenance"]
107+
CMD ["maintenance"]

0 commit comments

Comments
 (0)