diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1f36188 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,34 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Connect to server", + "type": "go", + "request": "attach", + "mode": "remote", + "remotePath": "${workspaceFolder}", + "debugAdapter": "dlv-dap", + "port": 40000, + "host": "127.0.0.1", + "showLog": true, + "logOutput": "dap", + + "ClientMod2Dir": { + // Add the info from `substitute-path-guess-helper` output. Example: + "main": "/usr/local/google/home/hakim/projects/go-docker-alpine-remote-debug", + "github.com/ccampo133/go-docker-alpine-remote-debug":"/usr/local/google/home/hakim/projects/go-docker-alpine-remote-debug" + } + + /* manual config :-( + "substitutePath": [ + { + "from": "${workspaceFolder}", + "to": "/app", + }], + */ + } + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b5d903e..31ef462 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,9 @@ WORKDIR /app # Turning off Cgo is required to install Delve on Alpine. ENV CGO_ENABLED=0 -# Download and install the Delve debugger. -RUN go install github.com/go-delve/delve/cmd/dlv@latest +# Build and install patched delve (checked out in the delve directory) +COPY delve /tmp/delve +RUN go install -C /tmp/delve ./cmd/dlv COPY go.mod . COPY go.sum . @@ -17,7 +18,8 @@ RUN go mod download COPY main.go . # Disable inlining and optimizations that can interfere with debugging. -RUN go build -gcflags "all=-N -l" -o /main main.go +#RUN go build -gcflags "all=-N -l" -o /main main.go +RUN go build -gcflags "all=-N -l" -o /main . FROM alpine:3.17 diff --git a/README.md b/README.md index 855712d..a3efa26 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,32 @@ +This is forked from github.com/ccampo133/go-docker-alpine-remote-debug for +testing delve DAP testing. It assumes there is a checked out copy of delve +under the `delve` directory. Let's assume you checked out this repo in +$WORKDIR. + +``` +git clone https://github.com/hyangah/go-docker-alpine-remote-debug $WORKDIR +cd $WORKDIR + +git clone https://github.com/go-delve/delve +cd delve +git fetch upstream pull/3781/head +go build ./cmd/dlv +``` + +From the $WORKDIR, running the `dlv substitue-path-guess-helper` gave me: + +``` +./delve/dlv substitute-path-guess-helper +{"ModuleDirectories":{"github.com/ccampo133/go-docker-alpine-remote-debug":"/usr/local/google/home/hakim/projects/go-docker-alpine-remote-debug"}} +``` + +Update `ClientMod2Dir` attribute in `$WORKDIR/.vscode/launch.json`. + +Read the "Dockerfile" to see how the container is built. + +Then, follow the remaining instruction below. + + # go-docker-alpine-remote-debug A simple example on how to enable remote debugging using [Delve](https://github.com/go-delve/delve) diff --git a/run.sh b/run.sh index 89d354e..5ce1d44 100755 --- a/run.sh +++ b/run.sh @@ -5,7 +5,7 @@ cmd="/bin/app" if [ "$REMOTE_DEBUG_PORT" ]; then echo "Starting application with remote debugging on port $REMOTE_DEBUG_PORT" - dlvFlags="--listen=:$REMOTE_DEBUG_PORT --headless=true --log --api-version=2 --accept-multiclient" + dlvFlags="--listen=:$REMOTE_DEBUG_PORT --headless=true --log --api-version=2 --accept-multiclient --log-output=dap,debugger" execFlags="" # Simply setting this environment variable is enough to force the debugger to # pause on start --- we don't care about the value.