godev
godev copied to clipboard
Enable Remote Debugging via delve
https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code
Could you elaborate on a flow you’d use from the CLI with GoDev?
Something like this: https://github.com/lukehoban/webapp-go/tree/debugging
In short: Having the ability to start docker-compose run debug
and the hook up VSCode Remote Debugging. It would be nice to set some commands and flags to debug, but this is handled in #17.
@DanielHabenicht interesting, this will be useful- I’m relatively new to Go so let me play around with it for awhile first to get a hang of how to use it before I work on this!
Me too. :) I couldn't get it to work with the example repo, but have previously debugged successfully in your containers. If I find out how I got it working in your go-container I will post an update.
You can debug with delve with a docker/ docker-compose setup like this I am still figuring out how to fix the breakpoint detection in the IDE (there is something related with file paths that makes debug listen but do not detect path mappings).. but shouldn't be far from this.
FROM golang:1.12-alpine AS build-env
WORKDIR /ms-skeleton-go
COPY . .
RUN apk add --no-cache git \
# Compile Delve for debug
&& go get -u github.com/go-delve/delve/cmd/dlv \
&& CGO_ENABLE=0 go install -tags netgo -v -gcflags "all=-N -l" -ldflags "-X main.version=unknown -X 'main.build=$(date)'" ./...
FROM alpine:3.9
COPY --from=build-env /go/bin/cmd /service
COPY --from=build-env /go/bin/dlv /debugger
# Allow delve to run on Alpine based containers.
RUN apk add --no-cache libc6-compat
# application 8080, delve 40000
EXPOSE 8080 40000
# Service
#ENTRYPOINT ["/service"]
# Run delve
CMD ["/debugger", "--listen=:40000", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "/service"]
in docker-compose.yml
app:
env_file:
- .env
build: .
security_opt:
- apparmor:unconfined # for delve debugger
cap_add:
- SYS_PTRACE # needed to allow the containers to read /proc/$PID (delve debugger)
mem_limit: 64m
memswap_limit: 0
mem_swappiness: 0
depends_on:
mariadb:
condition: service_started
restart: on-failure
ports:
- 8080:8080
- 40000:40000