How to hot reload grpc-server in python?
Asked Answered
A

1

8

I'm developing some python microservices with grpc and i'm using docker for the cassandra database and the microservices. Is there a way to setup reload on change within docker-compose?

I'm guessing that first I need the code mounted as a volume but I don't see a way to reload on GRPC server like for example flask does.

Astyanax answered 23/10, 2020 at 17:5 Comment(2)
Hi Luis. We like to use github.com/gorakhargosh/watchdog in combination with docker. All you do is add watchdog to your requirements.txt file, and in your docker-compose.yml file add command: watchmedo auto-restart --recursive --pattern="*.py" --directory="/path/to/your/app" python -- -m serverKulak
I think this solves my problems. Thanks! Mind putting it as an answer? so I can accept itAstyanax
K
8

We use watchdog[watchmedo] with our grpc services and Docker.

Install watchdog or add to your requirements.txt file

python -m pip install watchdog[watchmedo]

Then in your docker-compose.yml add watchmedo auto-restart --recursive --pattern="*.py" --directory="/usr/src/app/" python -- -m app to your container where --directory is the directory to where your app is contained inside the docker container, and python -- -m app is the file that starts your grpc Server. In this example the file that starts the server is called app.py:

  app:
    build:
      context: ./app/
      dockerfile: ./Dockerfile
      target: app
    command: watchmedo auto-restart --recursive --pattern="*.py" --directory="/usr/src/app/" python -- -m app
    volumes:
      - ./app/:/usr/src/app/
Kulak answered 27/10, 2020 at 8:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.