Delve debugging with hot reload
Asked Answered
T

1

8

My current development setup is a docker file that compiles the code on every save with CompileDaemon, and debug with Delve.

Currently I get almost everything to work. The only problem is that the port is already in use when I try to start the debug again.

Is their a better way to accomplish live reload with debug inside a docker container?

Dockerfile:

FROM golang:latest

RUN go get github.com/githubnemo/CompileDaemon && \
  go get github.com/go-delve/delve/cmd/dlv  
WORKDIR /app
COPY go.* ./
RUN go mod download

COPY ./ ./

EXPOSE 5000 2345
# echo 1 is to block build command 
ENTRYPOINT CompileDaemon --build="echo 1" --command="dlv debug --headless --listen=:2345 --api-version=2 --accept-multiclient cmd/app/main.go"
Temper answered 21/8, 2020 at 22:38 Comment(2)
Did you find a solution?Abdomen
also curious, did you get live reload to work?Expugnable
M
0

This works if you use gracefulkill and command stop in CompileDaemon because I want the subprocess of my application that is spun with dlv to be killed, and internally, CompileDaemon uses os.process.Kill() which doesn't kill the entire process tree, just the dlv one. If only dlv is killed, the go process would still be running and so the new dlv cannot start the same process on the same port, that leads to error like [GIN-debug] [ERROR] listen tcp :5100: bind: address already in use.

To ensure that the go process is killed, the full command that works for me is :

ENTRYPOINT CompileDaemon -log-prefix=false -command-stop=true -graceful-kill=true -build="go build -o __debug_service ./" -command="dlv debug --listen=:2001 --continue --headless=true --api-version=2 --accept-multiclient"
Macromolecule answered 21/11, 2023 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.