Dear Bitthal Ladiwal,
Thank you for your feedback.
You will need to ensure compatibility between gunicorn
and the bot, and avoids potential pitfalls in deployment. By aligning the file structure, port configurations, and startup command, the bot will deploy successfully to Azure App Service.
These are the steps you will need to take:
- Keep the file structure simple and align it with how gunicorn expects the main module. Place echo_bot.py in the same directory as app.py, and update import statements accordingly.
- Set the WEBSITES_PORT to 8000 (the default for gunicorn) in the ARM template:
Update config.py (or equivalent configuration file) to use port 8000 instead of 3978: "port": 8000{ "name": "WEBSITES_PORT", "value": "8000" }
- Modify the gunicorn startup command in the ARM template to explicitly include the port:
gunicorn --bind 0.0.0.0:8000 --worker-class aiohttp.worker.GunicornWebWorker --timeout 600 app:APP
- Ensure the requirements.txt file lists all dependencies accurately and check that the app service logs for errors using bash command: az webapp log tail --resource-group <your-resource-group> --name <your-app-name>
- This is a "Best Practices" tips: Avoid hardcoding ports in both the gunicorn command and configuration file. Instead, use environment variables:
Make sure theimport os PORT = int(os.environ.get("PORT", 8000))
WEBSITES_PORT
environment variable is set in your deployment pipeline to match the port defined in the startup command.
Goodluck.