Flask App deployment using Azure Web App from Github

Vijayakumar Elumalai 105 Reputation points
2023-08-23T12:37:58.23+00:00

i am trying to deploy the flask app into azure using Web App from Github. Deployment is done but getting application error after clicking default domain url. azure

Flask app is working fine in local machine. Is there any specific way to start the flask app in azure ? In local i am starting it like app.run() and working fine. Please guide me on this.

Workflow:

name: Build and deploy Python app to Azure Web App - HiringPredictions

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Python version
        uses: actions/setup-python@v1
        with:
          python-version: '3.10'

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate
      
      - name: Install dependencies
        run: pip install -r requirements.txt

      # Optional: Add step to run tests here (PyTest, Django test suites, etc.)

      - name: Upload artifact for deployment jobs
        uses: actions/upload-artifact@v2
        with:
          name: python-app
          path: |
            . 
            !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: .

      - name: 'Deploy to Azure Web App'
        uses: azure/webapps-deploy@v2
        id: deploy-to-webapp
        with:
          app-name: 'HiringPredictions'
          slot-name: 'Production'
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_D60DA2200CCD42C5A0F3BB09AF5DC6B9 }}
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,933 questions
{count} votes

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 17,731 Reputation points Microsoft Employee Moderator
    2023-08-24T23:11:36.0966667+00:00

    @Anonymous It seems like you have successfully deployed your Flask app to Azure Web App, but you are getting an application error after clicking the default domain URL. There could be several reasons for this error, such as incorrect configuration settings or missing dependencies.

    To start the Flask app in Azure, you need to specify the entry point of your application in the web.config file. You can add the following code to the web.config file to start your Flask app:

    <configuration>
      <appSettings>
        <add key="WSGI_HANDLER" value="app.app" />
        <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
      </appSettings>
      <system.webServer>
        <handlers>
          <add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\Python37\python.exe|D:\home\Python37\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
      </system.webServer>
    </configuration>
    
    
    

    Make sure to replace app.app with the name of your Flask app's entry point.

    Additionally, you can check the logs to see if there are any errors that could be causing the application error. You can access the logs by running the az webapp log tail command in the Azure CLI.

    If you are still having issues, you can try redeploying your app.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.