I'm using Github to deploy a flask app into an Azure web app. I configured CI/CD with GitHub Actions through Azure following these setup instructions through the deployment centre which automatically created a workflow for me in my repo.
I have my frontend deployed separately and only want to deploy the backend folder via GitHub Actions and to the Azure web app (basically just want to deploy a subdirectory of my repo).
My repo structure is organized like so:
my-repo
├── .github/workflows # workflow file for GH actions
├── backend # my flask app that I want to deploy
│ ├── requirements.txt
│ └── ...
└── ... # other files and frontend stuff I don't want deployed
Here is my workflow file:
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions
name: Build and deploy Python app to Azure Web App - xxxxxxxxxxxxxxxx
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
env:
working_directory: "backend/"
steps:
- uses: actions/checkout@v2
- name: Set up Python version
uses: actions/setup-python@v1
with:
python-version: '3.11'
- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
working-directory: "backend/"
- name: Install dependencies
run: pip install -r requirements.txt
working-directory: "backend/"
# Optional: Add step to run tests here (PyTest, Django test suites, etc.)
- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v3
with:
working_directory: "backend/"
name: python-app
path: |
./backend/
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: python-app
path: ./backend/
- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-to-webapp
with:
app-name: 'xxxxxxxxxxxxxxxx'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_xxxxxxxxxxxxxxxxxxxxxxxxxxx }}
Upon deployment via GitHub Actions I am successfully able to build and deploy but I get No framework detected; using default app from /opt/defaultsite and Generating gunicorn command for 'application:app' on my Azure web app deployment logs, and then the app does not work (backend is not properly deployed). When I deploy manually through VS code and the Azure App Service extension this does not happen and instead I get Detected an app based on Flask and Generating gunicorn command for 'app:app' which is correct and then my app works. In this manual version I'm able to manually select which folder to upload for deployment.
I suspect it is something with uploading artifacts where it's unable to find my backend folder (the subdirectory). What's confusing is that I turned debug mode on for GitHub actions deployment and it's able to find the requirements.txt and seems to be able to find my backend files when uploading artifacts. Here is a snippet from the debug logs:
##[debug]File:/home/runner/work/xxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxx/backend/venv/lib/python3.11/site-packages/pip/_internal/commands/__pycache__/hash.cpython-311.pyc was found using the provided searchPath
I've tried a couple different ways to set the working-directory as backend/ like:
- Setting it at each step to use the path or working-directory specified
- Adding in a step at the beginning of all steps to
cd backend - Adding a
.deploymentfile into the root of my repo with this content:
[config]
project = /backend
But all trials have resulted in the same issue (no framework detected).
Would appreciate any ideas and help!





buildjob, you need to runsource venv/bin/activateagain beforepip install. Eachrunis a separate shell. An activatedvenvwon't be activated in the next one automatically. You may combine both steps if that's fine with you.source venv/bin/activate && pip install -r requirements.txtto theInstall dependenciesstep, made the build time a lot longer but unfortunately still had the same "No framework detected" log. It's weird that the Azure default workflow didn't have that step set at default.