skip to Main Content

I have a mono repo with more than one application in it. The application I’m trying to deploy is in the directory rest_api. The deploy as seen in github actions is successful, but start-up fails.

This is my start-up command gunicorn -w 1 -k uvicorn.workers.UvicornWorker main:app

This is what the github actions file look like:

name: Deploy rest_api (dev) to Azure

env:
  AZURE_WEBAPP_NAME: 'xxx-rest-api'
  PYTHON_VERSION: '3.11'       

on:
  push:
    branches: [ "dev" ]
  workflow_dispatch:

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Set up Python version
        uses: actions/[email protected]
        with:
          python-version: ${{ env.PYTHON_VERSION }}
          cache: 'pip'

      - name: Create and start virtual environment
        working-directory: rest_api
        run: |
          python -m venv venv
          source venv/bin/activate
      
      - name: Install dependencies
        working-directory: rest_api    
        run: |
          pip install --upgrade pip
          pip install -r requirements/base.txt
      
      - name: Upload artifact for deployment jobs
        uses: actions/upload-artifact@v3
        with:
          name: python-app
          path: |
            rest_api
            !venv/
            !rest_api/venv/

  deploy:
    permissions:
      contents: none
    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@v3
        with:
          name: python-app
          path: rest_api
          
      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: ${{ env.AZURE_WEBAPP_NAME }}
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_A79D58476BA645D1BF1A6116201A6E5F }}
          package: rest_api

This is the error:

2023-03-27T08:52:28.865320556Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -userStartupCommand 'gunicorn -w 1 -k uvicorn.workers.UvicornWorker main:app'
2023-03-27T08:52:28.925294508Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2023-03-27T08:52:28.925870805Z Could not find operation ID in manifest. Generating an operation id...
2023-03-27T08:52:28.925880705Z Build Operation ID: d2e6df02-e71b-45fd-b84c-a0d9d8114831
2023-03-27T08:52:29.307010231Z Oryx Version: 0.2.20230103.1, Commit: df89ea1db9625a86ba583272ce002847c18f94fe, ReleaseTagName: 20230103.1
2023-03-27T08:52:29.354907333Z Writing output script to '/opt/startup/startup.sh'
2023-03-27T08:52:29.472048349Z WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv.
2023-03-27T08:52:29.491003271Z WARNING: Could not find package directory /home/site/wwwroot/__oryx_packages__.
2023-03-27T08:52:30.408188883Z 
2023-03-27T08:52:30.408226683Z Error: class uri 'uvicorn.workers.UvicornWorker' invalid or not found: 
2023-03-27T08:52:30.408231383Z 
2023-03-27T08:52:30.408234383Z [Traceback (most recent call last):
2023-03-27T08:52:30.408237183Z   File "/opt/python/3.11.1/lib/python3.11/site-packages/gunicorn/util.py", line 99, in load_class
2023-03-27T08:52:30.408240383Z     mod = importlib.import_module('.'.join(components))
2023-03-27T08:52:30.408243083Z           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-03-27T08:52:30.408245783Z   File "/opt/python/3.11.1/lib/python3.11/importlib/__init__.py", line 126, in import_module
2023-03-27T08:52:30.408248583Z     return _bootstrap._gcd_import(name[level:], package, level)
2023-03-27T08:52:30.408251383Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-03-27T08:52:30.408262283Z   File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
2023-03-27T08:52:30.408265483Z   File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
2023-03-27T08:52:30.408268383Z   File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
2023-03-27T08:52:30.408271083Z   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2023-03-27T08:52:30.408273883Z   File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
2023-03-27T08:52:30.408276583Z   File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
2023-03-27T08:52:30.408279383Z   File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
2023-03-27T08:52:30.408282083Z ModuleNotFoundError: No module named 'uvicorn'
2023-03-27T08:52:30.408284783Z ]

My hunch is that the error relates to the app and the virtualenv not being in root.

2

Answers


  1. Chosen as BEST ANSWER

    I found out that the problem was requirements were not in rest_api/requirements.txt but in rest_api/requirements/requirements.txt.


  2. If you see an error like

    ModuleNotFoundError: No module named ‘example’

    This means that the Python couldn’t find one or more of your modules when the application started.

    This error most often occurs if you deploy your virtual environment with your code. Please note that the virtual environments aren’t portable, so a virtual environment shouldn’t be deployed with your application code.

    Instead, let Oryx create a virtual environment and install your packages on the web app by creating an app setting, SCM_DO_BUILD_DURING_DEPLOYMENT, and setting it to 1.

    This setting will force Oryx to install your packages whenever you deploy to App Service.

    How to add setting: enter image description here

    For more information, please see this article on virtual environment portability.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search