godev icon indicating copy to clipboard operation
godev copied to clipboard

Enable Remote Debugging via delve

Open DanielHabenicht opened this issue 5 years ago • 5 comments

https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code

DanielHabenicht avatar Mar 09 '19 00:03 DanielHabenicht

Could you elaborate on a flow you’d use from the CLI with GoDev?

zephinzer avatar Mar 10 '19 10:03 zephinzer

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 avatar Mar 10 '19 15:03 DanielHabenicht

@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!

zephinzer avatar Mar 12 '19 15:03 zephinzer

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.

DanielHabenicht avatar Mar 17 '19 11:03 DanielHabenicht

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

rodrigo-garcia-edo avatar Jun 17 '19 12:06 rodrigo-garcia-edo