Skip to content

feat(engine): debug DLE locally in Docker container

Artyom Kartasov requested to merge dle-docker-debug into master

Description

  • add a new Makefile target to compile a debug binary
  • add a new image with delve to debug DLE locally in Docker container

Example of GoLand configuration

Configure Dockerfile

Add a new Dockerfile Run/Debug configuration. Make sure the "Run" options are configured similarly: Docker_configuration

Bind ports:

  • 2345:2345
  • 40000:40000

Bind mounts:

 /var/run/docker.sock:/var/run/docker.sock  
 /var/lib/dblab:/var/lib/dblab  
 /home/your_user/engine/configs:/home/dblab/configs  
 /tmp:/tmp  
 /lib/modules/:/lib/modules:ro  
 /proc:/host_proc:ro  
 /sys/kernel/debug:/sys/kernel/debug

Feel free to add your own mounts

Environment variables

 DOCKER_API_VERSION=1.39

Run options

--security-opt="apparmor=unconfined" --cap-add=SYS_PTRACE

Configure Go Remote

GoRemote_configuration

Running

Build your own debug binary (make build-debug) or uncomment the following lines in the debug Dockerfile:

# Build DLE (Uncomment if the binary doesn't compile locally).
# ADD . /dockerdev
# WORKDIR /dockerdev
# RUN GO111MODULE=on CGO_ENABLED=0 go build -gcflags="all=-N -l" -o /dblab-server-debug ./cmd/database-lab/main.go

...

# Replace if the binary doesn't compile locally.
# COPY --from=build-env /dblab-server-debug ./bin/dblab-server-debug

Then, run the configured Dockerfile environment (Shift+F10):

Deploying 'dblab-debug Dockerfile: database-lab/engine/Dockerfile.dblab-server-debug'…
Building image…
Preparing build context archive…
[==================================================>]282/282 files
Done

Sending build context to Docker daemon…
[==================================================>] 31.80MB
Done

Step 1/14 : FROM golang:1.18 AS build-env
---> 7d1902a99d63
....
Step 14/14 : CMD ["./dlv", "--listen=:40000", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "./bin/dblab-server-debug"]
---> Running in dcc60e81f37b
Removing intermediate container dcc60e81f37b
---> 327ab190e8b0

Successfully built 327ab190e8b0
Successfully tagged dblab-debug:latest
Existing container found: 98c90e6ea8b74ba0a34566f57890133325afc7c2aa2f4ce1e8a0992b32d2a11b, removing…
Creating container…
Container Id: df8fb795d50ca4c1431c5d6899b92a381a24871a26cc9bcc5fc5e887cd317080
Container name: 'dblab-debug'
Starting container 'dblab-debug'
'dblab-debug Dockerfile: database-lab/engine/Dockerfile.dblab-server-debug' has been deployed successfully.

And Run Remote Debug DLE Debug (Shift+F9) Run_debugging

Checklist

  • MR description has been reviewed
  • MR changes are functionally tested
  • MR does NOT have text changes OR there are text changes and they have been reviewed
  • MR does NOT have API/CLI changes OR there are API/CLI changes and they have been reviewed
  • MR does NOT have UI changes OR there are UI changes and they have been reviewed
Edited by Artyom Kartasov

Merge request reports