How to runremote debugging for fastapi based python web app in vscode

Hi,
I am running an webapplication in python in vs code Though okteto development env is up, I am unable to run in debug mode.
VS Code allows attach option. Now when run debugger in vscode via launch.json its unable to find remote service. Please help. Below launch.json

 {
            "name": "Python Debugger: Remote Attach1",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ]
        }

Hi @midprasanta,

Could you please provide your Okteto manifest? Please make sure to redact any sensitive values from it.

Please attach any screenshots or log outputs you have when the error occurs.

If needed, you can refer to our guide for Python development in Okteto. Step 4 specifically discusses remote debugging. You can find the guide here:

Hi @provecho ,
Below manifest file. It is working now when I comment reverse port mapping


deploy:
  - kubectl apply -f k8s.yml
dev:
  hello-world:
    command: bash
    environment:
      - FLASK_ENV=development
    sync:
      - .:/usr/src/app
    forward:
      - 8080:8080
      - 5678:5678
    reverse:
      # - 9000:5678
    volumes:
      - /root/.cache/pip

However code does not reload on its own when I make change in source. Any suggestion please.

Hi @midprasanta,

For debugging in VS Code with Okteto, ensure file synchronization is working properly. Check file sync status with okteto status --info. Confirm files aren’t ignored in .stignore. Details:

Regarding code hot reload, consider using a custom command in okteto up. For Flask, try flask run --debug. Documentation:

https://flask.palletsprojects.com/en/latest/quickstart/#debug-mode

HI @provecho,
Is there anyway I can reduce time of make application up? I have virtual env copied in okteto pod. But without installing its not working.

deploy:
  - helm uninstall abcd
  - helm install abcd ./charts/abcd--set image.repository="k3d-abcd.localhost:5000/abcd" --set env.OPENSEARCH_HOST=172.17.0.1 --set env.OPENSEARCH_INDEX=abcd-articles --kube-context k3d-abcd--namespace abcd
dev:
  abcd:
    image: okteto/python:3
    command: pip install poetry==1.7.0 && pip install uvicorn && chmod 777 ./.venv/bin/activate && ./.venv/bin/activate && poetry install && poetry shell && bash
    forward:
      - 8080:8080
      - 5678:5678
    reverse:
    # - 9000:9000
    volumes:
    - /root/.cache/pypoetry
    sync:
    - .:/usr/src/app  

Hi @midprasanta,

You can improve your setup by adding a build section in the Okteto manifest to create a specific container image for the development environment. Check out the example in the okteto/movies repository, specifically for the service frontend. Utilize the target property in the Dockerfile to build up to a certain stage and set the image in the dev section using OKTETO environment variables. Here are the relevant links for reference:

Example Okteto manifest: okteto/movies

Okteto manifest documentation: Build Object

Okteto environment variables: Built-in Environment Variables for Images in Okteto Registry