0

I tried to link my github repo to my azure function app which is typically done through the UI. However, github is throwing me some errors in the dependencies section of the build.

Run pip install -r requirements.txt
  pip install -r requirements.txt
  shell: /usr/bin/bash -e {0}
  env:
    AZURE_FUNCTIONAPP_PACKAGE_PATH: .
    PYTHON_VERSION: 3.10
    pythonLocation: /opt/hostedtoolcache/Python/3.10.11/x64
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'

Notice:  A new release of pip is available: 23.0.1 -> 23.1.2
Notice:  To update, run: pip install --upgrade pip
Error: Process completed with exit code 1.

I'm very new to CI/CD, especially in this format. Any help on what it needs from me would be very helpful and appreciated. I am working on Windows with Python 3.10.6

Below is my github actions workflow file.

# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure Functions: https://aka.ms/python-webapps-actions

name: Build and deploy Python project to Azure Function App - AutoAnalytics

on:
  push:
    branches:
      - main
  workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
  PYTHON_VERSION: '3.10' # set this to the python version to use (supports 3.6, 3.7, 3.8)

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Setup Python version
        uses: actions/setup-python@v1
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - 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

      - name: Upload artifact for deployment job
        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-function.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: python-app
          path: .

      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: 'APP_NAME'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_PROFILE_PATH }}
          scm-do-build-during-deployment: true
          enable-oryx-build: true
Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Mitchell.Laferla
  • 221
  • 2
  • 12
  • 1
    Please include your GHA workflow in your question. From that error log, looks like either the checkout step is missing or the path is not correct. – Azeem May 22 '23 at 16:54
  • @Azeem thanks for the feedback, just added that info. I'm looking into both of those suggestions, let me know if you have any advice. Thanks – Mitchell.Laferla May 22 '23 at 17:14
  • 1
    Sure thing. Is `requirements.txt` located on the root of repo? Also, `venv` activated in one step won't work for the next one as steps are run into different shells. If you need `venv` then you have to activate it once per step. – Azeem May 22 '23 at 17:19
  • @Azzem I added a blank requirements.txt file to the root in my repo. The error is obviously saying it cannot find the req doc to reference for dependencies and since it cannot locate it that's the source of the error. I'm confused as to why it can't seem to find the file. Is there a way to confirm the "root" of the repository? - name: Create and start virtual environment run: | python -m venv venv source venv/bin/activate - name: Install dependencies run: pip install -r requirements.txt The step b4 activates the venv so I think its ok. – Mitchell.Laferla May 22 '23 at 18:58
  • 1
    I've tested a similar workflow [here](https://github.com/GuillaumeFalourd/poc-github-actions/actions/runs/5049766971/jobs/9059633310) using this [workflow configuration](https://github.com/GuillaumeFalourd/poc-github-actions/blob/main/.github/workflows/workflow-tester80.yml) for the first job and didn't get the error (just added a `requirements.txt` file at the repo root). Do you still have an error after adding the file (even if empty)? – GuiFalourd May 22 '23 at 19:49
  • @Mitchell.Laferla: Run `ls -l` as the first command after checkout before creating `venv`. Also, add your repo directory listing in your question. Each `run` is a different shell. `venv` will be activated only under "**Create and start virtual environment**" and it won't be available under "**Install dependencies**" as it's not activated there. – Azeem May 23 '23 at 05:11

1 Answers1

1

Thank you @Azeem and @GuiFalourd for your comments. Make sure your github repo has requirements.txt and other Function files places the same way I have in my repository here:-

Make sure to have init.py and functions.json in one separate folder and rest all the files outside of it in the root of your repo as suggested by @Azeem and @GuiFalourd like below:-

My repository:-

enter image description here

My requirements.txt:-

azure-functions

Now, I ran the Github Actions deployment directly via Azure Deployment Center function was deployed successfully, Refer below:-

enter image description here

Github workflow:-

You can find my github workflow in this Link.

Code:-

Code reference

name: Build and deploy Python project to Azure Function App - siliconfunc432

on:
  push:
    branches:
      - main
  workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
  PYTHON_VERSION: '3.10' # set this to the python version to use (supports 3.6, 3.7, 3.8)

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Setup Python version
        uses: actions/setup-python@v1
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - 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

      - name: Upload artifact for deployment job
        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-function.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: python-app
          path: .

      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: 'siliconfunc432'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_3DB3646163EA4EC884AD53503517FE4B }}
          scm-do-build-during-deployment: true
          enable-oryx-build: true

Output:-

Github Workflow executed successfully:-

enter image description here

Function was deployed like below:-

enter image description here

enter image description here

enter image description here

Refer my SO Thread answer here where I deployed a Python Function app with Github Actions.

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11