azureazure-functionsgithub-actionskudu

Deploying Azure function with Github Actions fails without providing clear reason


I am trying to deploy an Azure function with Github Actions, using the standard code from Microsoft docs with only a minor adjustment to use SSH with pip:

env:
  AZURE_FUNCTIONAPP_NAME: 'func-app-name'
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.'         # set this to the path to your function app project, defaults to the repository root
  PYTHON_VERSION: '3.11'                      # set this to the python version to use (e.g. '3.6', '3.7', '3.8')

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    environment: dev
    steps:
    - name: 'Checkout GitHub Action'
      uses: actions/checkout@v3

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

    - name: Install SSH key  # extra step
      uses: webfactory/ssh-agent@v0.9.0
      with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

    - name: 'Resolve Project Dependencies Using Pip'
      shell: bash
      run: |
        pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
        python -m pip install --upgrade pip
        pip install -r requirements.txt --target=".python_packages/lib/site-packages"
        popd

    - name: 'Run Azure Functions Action'
      uses: Azure/functions-action@v1
      id: fa
      with:
        app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
        package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
        publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
        scm-do-build-during-deployment: true
        enable-oryx-build: true

The deployment step fails. No clear reason is provided in the logs:

  with:
    app-name: func-app-name
    package: .
    publish-profile: ***
    scm-do-build-during-deployment: true
    enable-oryx-build: true
    respect-pom-xml: false
    respect-funcignore: false
    remote-build: false
  env:
    AZURE_FUNCTIONAPP_NAME: func-app-name
    AZURE_FUNCTIONAPP_PACKAGE_PATH: .
    PYTHON_VERSION: 3.11
    pythonLocation: /opt/hostedtoolcache/Python/3.11.9/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.11.9/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.9/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.9/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.9/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.11.9/x64/lib
    SSH_AUTH_SOCK: /tmp/ssh-***/agent.***
    SSH_AGENT_PID: ***
  
Successfully parsed SCM credential from publish-profile format.
Using SCM credential for authentication, GitHub Action will not perform resource validation.
Successfully acquired app settings from function app (with SCM credential)!
Will archive . into /home/runner/work/_temp/temp_web_package_***.zip as function app content
Will use Kudu https://<scmsite>/api/zipdeploy to deploy since publish-profile is detected.
Setting SCM_DO_BUILD_DURING_DEPLOYMENT in Kudu container to true
Update using context.kuduService.updateAppSettingViaKudu
Response with status code 204
App setting SCM_DO_BUILD_DURING_DEPLOYMENT propagated to Kudu container
Setting ENABLE_ORYX_BUILD in Kudu container to true
Update using context.kuduService.updateAppSettingViaKudu
Response with status code 204
App setting ENABLE_ORYX_BUILD propagated to Kudu container
Package deployment using ZIP Deploy initiated.
Fetching changes.
Cleaning up temp folders from previous zip deployments and extracting pushed zip file /tmp/zipdeploy/***.zip (128.94 MB) to /tmp/zipdeploy/extracted
Error: Failed to deploy web package to App Service.
Error: Execution Exception (state: PublishContent) (step: Invocation)
Error:   When request Azure resource at PublishContent, zipDeploy : Failed to use /home/runner/work/_temp/temp_web_package_***.zip as ZipDeploy content
Error:     Package deployment using ZIP Deploy failed. Refer logs for more details.
Error: Deployment Failed!

The deployments works fine if I do it from my local machine with:

func azure functionapp publish "func-app-name"

What could be the problem here?


Solution

  • To resolve the error, add the application setting WEBSITE_RUN_FROM_PACKAGE = 1 under FunctionApp=>Configuration=>Environment Variables=>App Settings.

    enter image description here

    This setting helps to run the GitHub actions correctly and deploys the function App without any errors.

    enter image description here

    The error Failed to use /home/runner/work/_temp/temp_web_package_***.zip as ZipDeploy content in the workflow indicates that the deployment of the ZIP package to Azure App Service failed, especially the failure occurs when Azure tries to use the ZIP file.

    When ZIP deployment fails, the go to approach is to use the Website_Run_from_package setting. It skips all the issues with the extraction process and directly mounts the ZIP file content avoiding the extraction.