Skip to content

Commit 05a8624

Browse files
masterashuCopilot
andcommitted
 Refactor dockerfile and tiltfile to allow debug all go container in docker compose
Co-authored-by: Copilot <copilot@github.com>
1 parent 56f1811 commit 05a8624

5 files changed

Lines changed: 89 additions & 20 deletions

File tree

.env.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ PG_USER=postgres
2929
PG_PASSWORD=postgres
3030
PG_DATABASE=postgres
3131

32+
# Set to 1 for enabling go debugger in dockerfile and Tilt Setup
33+
DOCKER_GO_DEBUG_FLOW_API=
34+
DOCKER_GO_DEBUG_FLOW_WORKER=
35+
DOCKER_GO_DEBUG_FLOW_SNAPSHOT_WORKER=
36+
3237
PEERDB_CATALOG_HOST=host.docker.internal
3338
PEERDB_CATALOG_PORT=9901
3439
PEERDB_CATALOG_USER=postgres
@@ -44,4 +49,4 @@ AWS_EC2_METADATA_DISABLED="true"
4449
MINIO_ROOT_USER=_peerdb_minioadmin
4550
MINIO_ROOT_PASSWORD=_peerdb_minioadmin
4651

47-
TZ='UTC'
52+
TZ='UTC'

.vscode/launch.json

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "Docker Go Debug",
5+
"name": "Tilt Debug: Flow Worker",
66
"type": "go",
77
"request": "attach",
88
"mode": "remote",
@@ -16,7 +16,43 @@
1616
"to": "/root/flow"
1717
}
1818
],
19-
"port": 40000,
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,
2056
"host": "127.0.0.1"
2157
}
2258
]

Tiltfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@ flow_ignore = ['flow/e2e/', 'flow/**/*_test.go']
88

99
docker_build('flow-api', '.',
1010
dockerfile='stacks/flow.Dockerfile',
11-
target='flow-api',
11+
target='flow-api-debug' if os.getenv('DOCKER_GO_DEBUG_FLOW_API') == '1' else 'flow-api',
1212
only=['flow/', 'stacks/flow.Dockerfile'],
1313
ignore=flow_ignore,
1414
build_args={'PEERDB_VERSION_SHA_SHORT': os.getenv('PEERDB_VERSION_SHA_SHORT', 'unknown')},
1515
)
1616

1717
docker_build('flow-worker', '.',
1818
dockerfile='stacks/flow.Dockerfile',
19-
target='flow-worker-debug',
19+
target='flow-worker-debug' if os.getenv('DOCKER_GO_DEBUG_FLOW_WORKER') == '1' else 'flow-worker',
2020
only=['flow/', 'stacks/flow.Dockerfile'],
21-
build_args={'DEBUG_BUILD':'1'},
21+
build_args={'DEBUG_BUILD': os.getenv('DOCKER_GO_DEBUG_FLOW_WORKER','')},
2222
ignore=flow_ignore,
2323
)
2424

2525
docker_build('flow-snapshot-worker', '.',
2626
dockerfile='stacks/flow.Dockerfile',
27-
target='flow-snapshot-worker',
27+
target='flow-snapshot-worker-debug' if os.getenv('DOCKER_GO_DEBUG_FLOW_SNAPSHOT_WORKER') == '1' else 'flow-snapshot-worker',
2828
only=['flow/', 'stacks/flow.Dockerfile'],
29+
build_args={'DEBUG_BUILD': os.getenv('DOCKER_GO_DEBUG_FLOW_SNAPSHOT_WORKER','')},
2930
ignore=flow_ignore,
3031
)
3132

docker-compose-dev.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ services:
129129
- 8112:8112
130130
- 8113:8113
131131
- 5732:5732
132+
- 4003:40000
132133
environment:
133134
<<: [*catalog-config, *flow-worker-env, *minio-config]
134135
PEERDB_ALLOWED_TARGETS:
@@ -148,6 +149,8 @@ services:
148149
context: .
149150
dockerfile: stacks/flow.Dockerfile
150151
target: flow-snapshot-worker
152+
ports:
153+
- 4002:40000
151154
environment:
152155
<<: [*catalog-config, *flow-worker-env, *minio-config]
153156
depends_on:
@@ -162,7 +165,12 @@ services:
162165
dockerfile: stacks/flow.Dockerfile
163166
target: flow-worker
164167
ports:
165-
- 40000:40000
168+
- 4001:40000
169+
# 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.
170+
# security_opt:
171+
# - "seccomp:unconfined" # Required for Delve
172+
# cap_add:
173+
# - SYS_PTRACE # Required for Delve
166174
environment:
167175
<<: [*catalog-config, *flow-worker-env, *minio-config]
168176
extra_hosts:

stacks/flow.Dockerfile

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,30 @@ RUN apk add --no-cache ca-certificates geos && \
3737
USER peerdb
3838
WORKDIR /home/peerdb
3939
COPY --from=builder --chown=peerdb /root/peer-flow .
40+
ENTRYPOINT [ "/home/peerdb/peer-flow" ]
41+
42+
# Debug Image with Delve installed and the binary built with debug flags
43+
FROM flow-base AS flow-base-debug
44+
USER root
45+
COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
46+
EXPOSE 40000
47+
ENTRYPOINT ["dlv", "--headless", "--continue", "--accept-multiclient", "--listen=:40000", "--api-version=2", "exec", "/home/peerdb/peer-flow", "--"]
4048

4149
FROM flow-base AS flow-api
4250

4351
ARG PEERDB_VERSION_SHA_SHORT
4452
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
4553

4654
EXPOSE 8112 8113
47-
ENTRYPOINT ["./peer-flow", "api", "--port", "8112", "--gateway-port", "8113"]
55+
CMD ["api", "--port", "8112", "--gateway-port", "8113"]
56+
57+
FROM flow-base-debug AS flow-api-debug
58+
59+
ARG PEERDB_VERSION_SHA_SHORT
60+
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
61+
62+
EXPOSE 8112 8113
63+
CMD ["api", "--port", "8112", "--gateway-port", "8113"]
4864

4965
FROM flow-base AS flow-worker
5066

@@ -54,28 +70,31 @@ ENV OTEL_EXPORTER_OTLP_COMPRESSION=gzip
5470
ARG PEERDB_VERSION_SHA_SHORT
5571
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
5672

57-
ENTRYPOINT ["./peer-flow", "worker"]
73+
CMD ["worker"]
74+
75+
FROM flow-base-debug AS flow-worker-debug
76+
ENV OTEL_METRIC_EXPORT_INTERVAL=10000
77+
ENV OTEL_EXPORTER_OTLP_COMPRESSION=gzip
78+
ARG PEERDB_VERSION_SHA_SHORT
79+
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
80+
CMD ["./peer-flow", "--", "worker"]
81+
5882

5983
FROM flow-base AS flow-snapshot-worker
6084

6185
ARG PEERDB_VERSION_SHA_SHORT
6286
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
63-
ENTRYPOINT ["./peer-flow", "snapshot-worker"]
87+
CMD ["snapshot-worker"]
6488

89+
FROM flow-base-debug AS flow-snapshot-worker-debug
6590

66-
FROM flow-base AS flow-worker-debug
67-
ENV OTEL_METRIC_EXPORT_INTERVAL=10000
68-
ENV OTEL_EXPORTER_OTLP_COMPRESSION=gzip
6991
ARG PEERDB_VERSION_SHA_SHORT
7092
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
71-
USER root
72-
COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
73-
USER peerdb
74-
EXPOSE 40000
75-
ENTRYPOINT ["dlv", "--headless", "--continue", "--accept-multiclient", "--listen=:40000", "--api-version=2", "exec", "./peer-flow", "--", "worker"]
93+
CMD ["snapshot-worker"]
94+
7695

7796
FROM flow-base AS flow-maintenance
7897

7998
ARG PEERDB_VERSION_SHA_SHORT
8099
ENV PEERDB_VERSION_SHA_SHORT=${PEERDB_VERSION_SHA_SHORT}
81-
ENTRYPOINT ["./peer-flow", "maintenance"]
100+
CMD ["maintenance"]

0 commit comments

Comments
 (0)