Skip to content

Remote debugging

jcomedouteau edited this page Oct 28, 2024 · 32 revisions

With this method, we will launch a microservice in debug mode inside your IDE.

Example with shanoir-ng-studies

Step 1) Modify Dockerfile (/docker-compose/Dockerfile)

Edit the microservice, e.g. studies, to wait for remote connection on port 9912.

Therefore switch the lines (comment the 2. line, use the first line):

#CMD ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:9912", "-jar", "/shanoir-ng-studies.jar"]

CMD ["-jar", "/shanoir-ng-studies.jar"]

Step 2) Build new docker image

Use docker compose build studies (to bring your change in the Dockerfile into the container)

Step 3) Start shanoir-ng locally

Make sure your local project can write in /var/log/shanoir-ng-logs/. If not, create the directory: sudo mkdir /var/log/shanoir-ng-logs/ and modify the permissions: sudo chown -R user:group /var/log/shanoir-ng-logs/ (to see you username and group: ls -alh ~, it shows the current user and group owning the home directory).

You can use development mode below, but you do not have to, so a simple docker-compose up -d

Launch projet with docker-compose or bootstrap.sh:

  • in the root folder:
    • docker-compose -f docker-compose-dev.yml -f docker-compose-dev-front.yml build,
    • docker-compose -f docker-compose-dev.yml -f docker-compose-dev-front.yml up.

Note: you can create a nice alias in your ~/.bashrc (or equivalent, .zshrc on mac): alias dcd="docker-compose -f docker-compose-dev.yml -f docker-compose-dev-front.yml" then you can use it in many ways: dcd up, dcd build import or dcd up datasets...

You should see this in the logs of studies (with docker compose logs studies): studies | Listening for transport dt_socket at address: 9912

Step 4) Your IDE

Run and debug the microservice in your corresponding IDE.

Eclipse

0) Install Spring Boot plugin

In Eclipse, menu Help > Eclipse Marketplace..., search Spring Tools 3 and install.

1) Create a new Spring Boot App Debug configuration

In Eclipse

Right-click on the shanoir-ng-studies project, choose "Debug as > debug configurations..."

In the Debug Configurations window, double click the Spring Boot App in the left menu to create a new config.

In the Spring Boot tab, choose:

- Project: shanoir-ng-studies

- Main type: org.shanoir.ng.ShanoirStudiesApplication

- Port: 9912

In Visual Studio Code

Modify your User settings.json (located at /Users/Username/Library/Application Support/Code/User/settings.json on mac) to set the default java runtime environment to Java 21.

Then, create a .vscode/launch.json file in your shanoir project, so that it attaches to 9912:

{
    "configurations": [
        {
            "type": "java",
            "name": "Remote debug ShanoirStudiesApplication",
            "request": "attach",
            "projectName": "shanoir-ng-studies",
            "hostName": "localhost",
            "port": 9912
        }
    ]
}

Now you can launch the microservice in Eclipse (Debug button > choose the configuration you created) or in Visual Studio Code (go to the Run panel Cmd + Shift + D and choose the configuration you created in the top left menu). This will launch the service which will connect to the waiting container.

IntelliJ

Be sure beforehand that you have updated your DockerFile

0) Install Spring Boot plugin

1) Launch shanoir

In Service tab / Docker, every service should be green:

image

2) Deploy the microservice you want to debug and click on the container

image

3) The logs of the application should appear, check for the following log:

Listening for transport dt_socket at address: 9912

Then click on the button on the right side of it: "Attach debugger"

Your breakpoints are now available to debug.

Clone this wiki locally