Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Remote Debugging via delve #19

Open
DanielHabenicht opened this issue Mar 9, 2019 · 5 comments
Open

Enable Remote Debugging via delve #19

DanielHabenicht opened this issue Mar 9, 2019 · 5 comments

Comments

@DanielHabenicht
Copy link
Contributor

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

@zephinzer
Copy link
Owner

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

@DanielHabenicht
Copy link
Contributor Author

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.

@zephinzer
Copy link
Owner

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

@DanielHabenicht
Copy link
Contributor Author

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.

@rodrigo-garcia-edo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants