Github Actions Workflow failing at deployment for Python Flask App

Sintrias 96 Reputation points
2022-01-20T17:59:13.87+00:00

I've been having so much trouble with deploying my Python 3.7 Flask app to my Azure Web App service. I've connected the service to the Github repository and setup the workflow file. I don't see what I'm doing wrong. Also, the project works fine on my local machine.

Resource JSON

{    
    "id": "/subscriptions/c53641f7-a6bb-404e-b328-0a5b04ca5a90/resourceGroups/CogexServices/providers/Microsoft.Web/sites/CogexNLP",  
    "name": "CogexNLP",  
    "type": "Microsoft.Web/sites",  
    "kind": "app,linux",  
    "location": "Central US",  
    "tags": {},  
    "properties": {  
        "name": "CogexNLP",  
        "state": "Running",  
        "hostNames": [  
            "cogexnlp.azurewebsites.net"  
        ],  
        "webSpace": "CogexServices-CentralUSwebspace-Linux",  
        "selfLink": "https://waws-prod-dm1-195.api.azurewebsites.windows.net:454/subscriptions/c53641f7-a6bb-404e-b328-0a5b04ca5a90/webspaces/CogexServices-CentralUSwebspace-Linux/sites/CogexNLP",  
        "repositorySiteName": "CogexNLP",  
        "owner": null,  
        "usageState": 0,  
        "enabled": true,  
        "adminEnabled": true,  
        "enabledHostNames": [  
            "cogexnlp.azurewebsites.net",  
            "cogexnlp.scm.azurewebsites.net"  
        ],  
        "siteProperties": {  
            "metadata": null,  
            "properties": [  
                {  
                    "name": "LinuxFxVersion",  
                    "value": "PYTHON|3.7"  
                },  
                {  
                    "name": "WindowsFxVersion",  
                    "value": null  
                }  
            ],  
            "appSettings": null  
        },  
        "availabilityState": 0,  
        "sslCertificates": null,  
        "csrs": [],  
        "cers": null,  
        "siteMode": null,  
        "hostNameSslStates": [  
            {  
                "name": "cogexnlp.azurewebsites.net",  
                "sslState": 0,  
                "ipBasedSslResult": null,  
                "virtualIP": null,  
                "thumbprint": null,  
                "toUpdate": null,  
                "toUpdateIpBasedSsl": null,  
                "ipBasedSslState": 0,  
                "hostType": 0  
            },  
            {  
                "name": "cogexnlp.scm.azurewebsites.net",  
                "sslState": 0,  
                "ipBasedSslResult": null,  
                "virtualIP": null,  
                "thumbprint": null,  
                "toUpdate": null,  
                "toUpdateIpBasedSsl": null,  
                "ipBasedSslState": 0,  
                "hostType": 1  
            }  
        ],  
        "computeMode": null,  
        "serverFarm": null,  
        "serverFarmId": "/subscriptions/c53641f7-a6bb-404e-b328-0a5b04ca5a90/resourceGroups/CogexServices/providers/Microsoft.Web/serverfarms/ASP-CogexServices-b337",  
        "reserved": true,  
        "isXenon": false,  
        "hyperV": false,  
        "lastModifiedTimeUtc": "2022-01-20T01:52:10.79",  
        "storageRecoveryDefaultState": "Running",  
        "contentAvailabilityState": 0,  
        "runtimeAvailabilityState": 0,  
        "siteConfig": {  
            "numberOfWorkers": 1,  
            "defaultDocuments": null,  
            "netFrameworkVersion": null,  
            "phpVersion": null,  
            "pythonVersion": null,  
            "nodeVersion": null,  
            "powerShellVersion": null,  
            "linuxFxVersion": "PYTHON|3.7",  
            "windowsFxVersion": null,  
            "requestTracingEnabled": null,  
            "remoteDebuggingEnabled": null,  
            "remoteDebuggingVersion": null,  
            "httpLoggingEnabled": null,  
            "azureMonitorLogCategories": null,  
            "acrUseManagedIdentityCreds": false,  
            "acrUserManagedIdentityID": null,  
            "logsDirectorySizeLimit": null,  
            "detailedErrorLoggingEnabled": null,  
            "publishingUsername": null,  
            "publishingPassword": null,  
            "appSettings": null,  
            "metadata": null,  
            "connectionStrings": null,  
            "machineKey": null,  
            "handlerMappings": null,  
            "documentRoot": null,  
            "scmType": null,  
            "use32BitWorkerProcess": null,  
            "webSocketsEnabled": null,  
            "alwaysOn": true,  
            "javaVersion": null,  
            "javaContainer": null,  
            "javaContainerVersion": null,  
            "appCommandLine": null,  
            "managedPipelineMode": null,  
            "virtualApplications": null,  
            "winAuthAdminState": null,  
            "winAuthTenantState": null,  
            "customAppPoolIdentityAdminState": null,  
            "customAppPoolIdentityTenantState": null,  
            "runtimeADUser": null,  
            "runtimeADUserPassword": null,  
            "loadBalancing": null,  
            "routingRules": null,  
            "experiments": null,  
            "limits": null,  
            "autoHealEnabled": null,  
            "autoHealRules": null,  
            "tracingOptions": null,  
            "vnetName": null,  
            "vnetRouteAllEnabled": null,  
            "vnetPrivatePortsCount": null,  
            "publicNetworkAccess": null,  
            "cors": null,  
            "push": null,  
            "apiDefinition": null,  
            "apiManagementConfig": null,  
            "autoSwapSlotName": null,  
            "localMySqlEnabled": null,  
            "managedServiceIdentityId": null,  
            "xManagedServiceIdentityId": null,  
            "keyVaultReferenceIdentity": null,  
            "ipSecurityRestrictions": null,  
            "scmIpSecurityRestrictions": null,  
            "scmIpSecurityRestrictionsUseMain": null,  
            "http20Enabled": false,  
            "minTlsVersion": null,  
            "scmMinTlsVersion": null,  
            "ftpsState": null,  
            "preWarmedInstanceCount": null,  
            "functionAppScaleLimit": 0,  
            "healthCheckPath": null,  
            "fileChangeAuditEnabled": null,  
            "functionsRuntimeScaleMonitoringEnabled": null,  
            "websiteTimeZone": null,  
            "minimumElasticInstanceCount": 0,  
            "azureStorageAccounts": null,  
            "http20ProxyFlag": null,  
            "sitePort": null,  
            "antivirusScanEnabled": null  
        },  
        "deploymentId": "CogexNLP",  
        "slotName": null,  
        "trafficManagerHostNames": null,  
        "sku": "PremiumV2",  
        "scmSiteAlsoStopped": false,  
        "targetSwapSlot": null,  
        "hostingEnvironment": null,  
        "hostingEnvironmentProfile": null,  
        "clientAffinityEnabled": false,  
        "clientCertEnabled": false,  
        "clientCertMode": 0,  
        "clientCertExclusionPaths": null,  
        "hostNamesDisabled": false,  
        "domainVerificationIdentifiers": null,  
        "customDomainVerificationId": "22B005ED232323FD15B2BD36671D111D1B0C2B29FF4E6A7856B4E6C963C62169",  
        "kind": "app,linux",  
        "inboundIpAddress": "20.40.202.9",  
        "possibleInboundIpAddresses": "20.40.202.9",  
        "ftpUsername": "CogexNLP\\$CogexNLP",  
        "ftpsHostName": "ftps://waws-prod-dm1-195.ftp.azurewebsites.windows.net/site/wwwroot",  
        "outboundIpAddresses": "52.154.210.160,52.154.213.80,52.158.222.77,52.158.222.103,52.158.222.107,52.158.222.165,20.40.202.9",  
        "possibleOutboundIpAddresses": "52.154.45.145,52.154.46.157,52.158.220.234,52.154.209.132,52.158.221.79,52.158.221.181,52.154.210.160,52.154.213.80,52.158.222.77,52.158.222.103,52.158.222.107,52.158.222.165,52.158.223.10,52.154.208.46,52.154.208.97,52.158.223.72,52.158.223.116,52.158.223.185,40.89.240.217,40.89.246.197,52.154.242.106,52.154.243.155,52.154.243.200,52.154.244.52,20.40.202.9",  
        "containerSize": 0,  
        "dailyMemoryTimeQuota": 0,  
        "suspendedTill": null,  
        "siteDisabledReason": 0,  
        "functionExecutionUnitsCache": null,  
        "maxNumberOfWorkers": null,  
        "homeStamp": "waws-prod-dm1-195",  
        "cloningInfo": null,  
        "hostingEnvironmentId": null,  
        "tags": {},  
        "resourceGroup": "CogexServices",  
        "defaultHostName": "cogexnlp.azurewebsites.net",  
        "slotSwapStatus": null,  
        "httpsOnly": false,  
        "redundancyMode": 0,  
        "inProgressOperationId": null,  
        "geoDistributions": null,  
        "privateEndpointConnections": [],  
        "buildVersion": null,  
        "targetBuildVersion": null,  
        "migrationState": null,  
        "eligibleLogCategories": "AppServiceAppLogs,AppServiceAuditLogs,AppServiceConsoleLogs,AppServiceHTTPLogs,AppServiceIPSecAuditLogs,AppServicePlatformLogs,ScanLogs,AppServiceFileAuditLogs,AppServiceAntivirusScanAuditLogs",  
        "storageAccountRequired": false,  
        "virtualNetworkSubnetId": null,  
        "keyVaultReferenceIdentity": "SystemAssigned"  
    }  
}  

Workflow YAML

# 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 - CogexNLP  
  
on:  
  push:  
    branches:  
      - master  
  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.7'  
  
      - name: Create and start virtual environment  
        run: |  
          python -m venv venv  
          source venv/bin/activate  
            
      - name: Update pip  
        run: python -m pip install --upgrade pip  
        
      - name: Install dependencies  
        run: |  
          pip install wheel  
          pip install -r requirements.txt  
            
      - name: Download en_core_web_sm  
        run: python -m spacy download en_core_web_sm  
          
      # 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: Setup environment  
        run: |  
          python -m pip install --upgrade pip  
          sudo apt-get install git  
            
      - 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: 'CogexNLP'  
          slot-name: 'Production'  
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_AE20318F7B5B406BA70B505F0BA1C0BB }}  

Jobs Summary Snippet
166846-image.png

Deployment Logs

Command: oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform python --platform-version 3.7 -i /tmp/8d9dbffdf16cab0 --compress-destination-dir -p virtualenv_name=antenv --log-file /tmp/build-debug.log     
Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx  
You can report issues at https://github.com/Microsoft/Oryx/issues  
  
Oryx Version: 0.2.20210826.1, Commit: f8651349d0c78259bb199593b526450568c2f94a, ReleaseTagName: 20210826.1  
  
Build Operation ID: |u25vnBpny0M=.e7f41a32_  
Repository Commit : 3558b6a0769e4eedaebe9bcc8a5ccb0e  
  
Detecting platforms...  
Detected following platforms:  
  python: 3.7.12  
Version '3.7.12' of platform 'python' is not installed. Generating script to install it...  
Warning: An outdated version of python was detected (3.7.12). Consider updating.\nVersions supported by Oryx: https://github.com/microsoft/Oryx  
  
  
Using intermediate directory '/tmp/8d9dbffdf16cab0'.  
  
Copying files to the intermediate directory...  
Done in 0 sec(s).  
  
Source directory     : /tmp/8d9dbffdf16cab0  
Destination directory: /home/site/wwwroot  
  
  
Downloading and extracting 'python' version '3.7.12' to '/tmp/oryx/platforms/python/3.7.12'...  
Downloaded in 1 sec(s).  
Verifying checksum...  
Extracting contents...  
Done in 4 sec(s).  
  
Python Version: /tmp/oryx/platforms/python/3.7.12/bin/python3.7  
Creating directory for command manifest file if it doesnot exist  
Removing existing manifest file  
Python Virtual Environment: antenv  
Creating virtual environment...  
Activating virtual environment...  
Running pip install...  
[10:30:40+0000] Collecting git+https://github.com/JeffMII/Questgen.ai.git (from -r requirements.txt (line 2))  
[10:30:40+0000]   Cloning https://github.com/JeffMII/Questgen.ai.git to /tmp/pip-req-build-67ctruzz  
  Running command git clone -q https://github.com/JeffMII/Questgen.ai.git /tmp/pip-req-build-67ctruzz  
[10:30:41+0000]   Installing build dependencies: started  
  ERROR: Command errored out with exit status -9:  
[10:34:17+0000]   Installing build dependencies: finished with status 'error'  
   command: /tmp/8d9dbffdf16cab0/antenv/bin/python /tmp/8d9dbffdf16cab0/antenv/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-qbutalr2/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- torch==1.9.0 'transformers>=3.0.2, <=4.2.2' 'pytorch_lightning>=0.8.1, <=0.8.4' sense2vec==2.0.0 strsim==0.0.3 'six>=1.15.0, <=1.16.0' 'networkx>=2.4.0, <=2.6.3' numpy==1.16.3 'scipy>=1.4.1, <=1.5.4' 'scikit-learn>=0.22.1, <=1.0.2' 'unidecode>=1.1.1, <=1.3.2' future==0.18.2 'joblib>=0.14.1, <=1.1.0' 'spacy>=3.0.0, <=3.2.1' 'pytz>=2020.1, <=2021.3' 'python-dateutil>=2.8.1, <=2.8.2' 'boto3>=1.14.40, <=1.20.39' flashtext==2.7 'pandas>=1.1.1, <=1.1.5' nltk==3.6.3 pke@git+https://github.com/JeffMII/pke.git wheel  
       cwd: None  
  Complete output (1 lines):  
  Collecting torch==1.9.0  
  ----------------------------------------  
ERROR: Command errored out with exit status -9: /tmp/8d9dbffdf16cab0/antenv/bin/python /tmp/8d9dbffdf16cab0/antenv/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-qbutalr2/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- torch==1.9.0 'transformers>=3.0.2, <=4.2.2' 'pytorch_lightning>=0.8.1, <=0.8.4' sense2vec==2.0.0 strsim==0.0.3 'six>=1.15.0, <=1.16.0' 'networkx>=2.4.0, <=2.6.3' numpy==1.16.3 'scipy>=1.4.1, <=1.5.4' 'scikit-learn>=0.22.1, <=1.0.2' 'unidecode>=1.1.1, <=1.3.2' future==0.18.2 'joblib>=0.14.1, <=1.1.0' 'spacy>=3.0.0, <=3.2.1' 'pytz>=2020.1, <=2021.3' 'python-dateutil>=2.8.1, <=2.8.2' 'boto3>=1.14.40, <=1.20.39' flashtext==2.7 'pandas>=1.1.1, <=1.1.5' nltk==3.6.3 pke@git+https://github.com/JeffMII/pke.git wheel Check the logs for full command output.  
WARNING: You are using pip version 20.1.1; however, version 21.3.1 is available.  
You should consider upgrading via the '/tmp/8d9dbffdf16cab0/antenv/bin/python -m pip install --upgrade pip' command.  
Running command git clone -q https://github.com/JeffMII/Questgen.ai.git /tmp/pip-req-build-67ctruzz\n  ERROR: Command errored out with exit status -9:\n   command: /tmp/8d9dbffdf16cab0/antenv/bin/python /tmp/8d9dbffdf16cab0/antenv/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-qbutalr2/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- torch==1.9.0 'transformers>=3.0.2, <=4.2.2' 'pytorch_lightning>=0.8.1, <=0.8.4' sense2vec==2.0.0 strsim==0.0.3 'six>=1.15.0, <=1.16.0' 'networkx>=2.4.0, <=2.6.3' numpy==1.16.3 'scipy>=1.4.1, <=1.5.4' 'scikit-learn>=0.22.1, <=1.0.2' 'unidecode>=1.1.1, <=1.3.2' future==0.18.2 'joblib>=0.14.1, <=1.1.0' 'spacy>=3.0.0, <=3.2.1' 'pytz>=2020.1, <=2021.3' 'python-dateutil>=2.8.1, <=2.8.2' 'boto3>=1.14.40, <=1.20.39' flashtext==2.7 'pandas>=1.1.1, <=1.1.5' nltk==3.6.3 pke@git+https://github.com/JeffMII/pke.git wheel\n       cwd: None\n  Complete output (1 lines):\n  Collecting torch==1.9.0\n  ----------------------------------------\nERROR: Command errored out with exit status -9: /tmp/8d9dbffdf16cab0/antenv/bin/python /tmp/8d9dbffdf16cab0/antenv/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-qbutalr2/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- torch==1.9.0 'transformers>=3.0.2, <=4.2.2' 'pytorch_lightning>=0.8.1, <=0.8.4' sense2vec==2.0.0 strsim==0.0.3 'six>=1.15.0, <=1.16.0' 'networkx>=2.4.0, <=2.6.3' numpy==1.16.3 'scipy>=1.4.1, <=1.5.4' 'scikit-learn>=0.22.1, <=1.0.2' 'unidecode>=1.1.1, <=1.3.2' future==0.18.2 'joblib>=0.14.1, <=1.1.0' 'spacy>=3.0.0, <=3.2.1' 'pytz>=2020.1, <=2021.3' 'python-dateutil>=2.8.1, <=2.8.2' 'boto3>=1.14.40, <=1.20.39' flashtext==2.7 'pandas>=1.1.1, <=1.1.5' nltk==3.6.3 pke@git+https://github.com/JeffMII/pke.git wheel Check the logs for full command output.\nWARNING: You are using pip version 20.1.1; however, version 21.3.1 is available.\nYou should consider upgrading via the '/tmp/8d9dbffdf16cab0/antenv/bin/python -m pip install --upgrade pip' command.\n/opt/Kudu/Scripts/starter.sh oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform python --platform-version 3.7 -i /tmp/8d9dbffdf16cab0 --compress-destination-dir -p virtualenv_name=antenv --log-file /tmp/build-debug.log   
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 22,706 Reputation points Moderator
    2022-01-22T07:33:19.113+00:00

    Thanks for asking question! It seems there is Build issues on Kudu.

    You may want to know if you are setting up a CI/CD pipeline for your Python apps to App Service without using containers, you cannot simply pip install and deploy your app and packages to App Service. Reason is the OS on your build server will most likely not match the runtime on Azure.

    To address this, simply create an app setting on your App Service named SCM_DO_BUILD_DURING_DEPLOYMENT with a value of true.

    This app setting will trigger the Oryx build pipeline to re-install your packages during deployment.

    Further Oryx is an open-source utility by Microsoft that automatically builds source code. Oryx runs in your web app’s SCM (site control manager) site. By setting this app setting, Oryx will pip install your dependencies on the runtime image so that the packages can take the appropriate dependencies on the OS libraries.

    Please review the following articles that will help you understand the Oryx System's Configurations and build logic
    o https://github.com/microsoft/Oryx/blob/master/doc/hosts/appservice.md
    o https://github.com/microsoft/Oryx/blob/master/doc/configuration.md
    o https://github.com/microsoft/Oryx/blob/master/doc/runtimes/python.md

    Also, review the linked article for deploying your app to Azure App Service Linux using GitHub Actions.

    More details: Using GitHub Actions for Python Applications

    Let us know if further query or issue remains.


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.