DDEV add a flask-wsgi 5000 route to existing drupal web build

36 views Asked by At

I have a running drupal-9 ddev site. My goal is to add support to run a Python-Flask app at ./bot/app.py which runs at localhost:800X.

Changes so far - this part works. .ddev/config.yaml

  • added python3, etc. webimage_extra_packages: += [python3, python-is-python3]
  • hooks:post-start:
    • exec: "cd bot && pip install -r requirements-test.txt"

But how do i start/add the python web app?

These do not work:

  • post-start: - exec: "cd bot && python -m flask run --host=0.0.0.0 --port=5001 --debug"
  • web_extra_daemons
web_extra_daemons:
  - name: "flask_dev_server"
    command: "python -m /home/loom23/.local/bin/flask run --host=0.0.0.0 --port=5001 --debug"
    directory: /var/www/html/bot

I have seen in other docker-compose configuations where a Flask-app is started in a Dockerfile - what is the best way to achieve this?

1

There are 1 answers

1
Abhijit On

To add a Flask-WSGI route to your existing Drupal build in a DDEV environment, try this

  1. Update your .ddev/config.yaml file to include the necessary configurations for running the Flask app after DDEV starts. It seems like you've already added the Python packages and executed a post-start hook for installing requirements.
webimage_extra_packages: [python3, python-is-python3]
hooks:
  post-start:
    - exec: "cd bot && pip install -r requirements-test.txt"
    - exec: "cd bot && python -m flask run --host=0.0.0.0 --port=8001 --debug"

This assumes that your Flask app should run on port 8001. Adjust the port number as needed.

  1. Ensure that your Flask app is configured to run with the specified host and port. The --host=0.0.0.0 makes the app accessible from outside the container.

  2. Verify that the Flask app is running correctly after DDEV starts.

By incorporating these changes, the Flask app should be started automatically when you run DDEV, and you can access it at http://localhost:8001 if you set the port as 8001.

Remember to adapt the configurations based on your specific project requirements.