Azure / functions-container-action

Enable GitHub developers to deploy to Azure Function Apps Containers using GitHub Actions
MIT License
26 stars 14 forks source link

Azure/functions-container-action@v1 - TypeError: Cannot read property 'getApplicationURL' #12

Closed bgarcial closed 3 years ago

bgarcial commented 3 years ago

I have an azure function (python code) containerized in a Dockerfile. I want to run it from Github actions, so I am doing in my workflow the following:


    - name: 'Run Azure Functions Container Action'
      uses: Azure/functions-container-action@v1
      id: fa
      with:
        app-name: my-spec-prod-azure-function
        image: containerregistry.azurecr.io/my-azure-function:latest

    - name: Azure logout
      run: |
        az logout

The thing here is I am using Azure/functions-container-action@v1 github action to run the container but it does not work, I got the following message error in my pipeline:

Run Azure/functions-container-action@v1
  with:
    app-name: my-spec-prod-azure-function
    image: containerregistry.azurecr.io/my-azure-function:latest
  env:
    AZURE_HTTP_USER_AGENT: 
    AZUREPS_HOST_ENVIRONMENT: 
    DOCKER_CONFIG: /home/runner/work/_temp/docker_login_1613723968334
Error: Error: Resource my-spec-prod-azure-function doesn't exist.
(node:4655) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getApplicationURL' of undefined
    at /home/runner/work/_actions/Azure/functions-container-action/v1/lib/main.js:68:68
    at Generator.throw (<anonymous>)
    at rejected (/home/runner/work/_actions/Azure/functions-container-action/v1/lib/main.js:6:65)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:4655) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4655) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Checking the azure actions workflow samples, you also use the same action (Azure/functions-container-action@v1) to deploy an azure function, they emphasize that here.

Here someone got a similar error description but I am afraid it is not for azure functions container but for appservices actions that use containers. Despite that, I also tried the azure/webapps-container-deploy@v1 action but it does not work, and I think that is not a suited action.

I checked your official marketplace site and you say this is the latest version to use:

- name: Azure Functions Container Action
  uses: Azure/functions-container-action@v1.0.1

So I changed Azure/functions-container-action@v1 by Azure/functions-container-action@v1.0.1 without success, I got a very similar error but with some hints or clue about setting environment variables.

Error: Unable to process command '::set-env name=AZURE_HTTP_USER_AGENT,::GITHUBACTIONS_DeployFunctionAppContainerToAzure_b32b908e01efeb4da360da24648fd5091bc18dcc93090b9c05ee3b76efe9b57e' successfully.
Error: The `set-env` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands
Error: Error: Resource my-spec-prod-azure-function doesn't exist.
(node:4508) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getApplicationURL' of undefined
    at /home/runner/work/_actions/Azure/functions-container-action/v1.0.1/lib/main.js:68:68
    at Generator.throw (<anonymous>)
    at rejected (/home/runner/work/_actions/Azure/functions-container-action/v1.0.1/lib/main.js:6:65)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:4508) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4508) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Regarding the The set-env command is disabled new error message, checking the log changes, here is not clear for me how or why the env variables like AZURE_HTTP_USER_AGENT and the other one should be set it up properly.

N-Usha commented 3 years ago

@Hazhzeng - Can you please look into this issue?

AmrutaKawade commented 3 years ago

We have already upgraded @actions/core version in our action. since you are pointing older version v1.0.1 its failing for you. latest version id v1.0.2 or just `v1. set-env error is coming because of this version only.

Now coming back to your first error. Are you using azure/login action before function-container-action as mentioned here?

bgarcial commented 3 years ago

@AmrutaKawade, By the time I filed this issue I tried the v1 and v1.0.1 versions and I got the error described above. I also tried these versions right now, without succeed

I didn't know there were a new v1.0.2 version for this github action. At the marketplace website the latest referenced version is v1.0.1.

I pointed up to v1.0.2 version and I got the same error as well. This one:

Run Azure/functions-container-action@v1.0.2
  with:
    app-name: rhd-spec-prod-fem-downloader-function
    image: rhdhvcontainerregistry.azurecr.io/af-fem-downloader:latest
  env:
    AZURE_HTTP_USER_AGENT: 
    AZUREPS_HOST_ENVIRONMENT: 
    DOCKER_CONFIG: /home/runner/work/_temp/docker_login_1613984821988
Error: Error: Resource rhd-spec-prod-fem-downloader-function doesn't exist.
(node:1724) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getApplicationURL' of undefined
    at /home/runner/work/_actions/Azure/functions-container-action/v1.0.2/lib/main.js:68:68
    at Generator.throw (<anonymous>)
    at rejected (/home/runner/work/_actions/Azure/functions-container-action/v1.0.2/lib/main.js:6:65)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:1724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1724) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I am using azure/login@v1 as a first step before building the container when azure functions live and before deploying it. The azure login and docker steps are successful for me, but not when running the azure functions action container. Here my entire workflow actions:

name: Deploy_Workflow

on:
  push:
    branches:
    - main

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

    - name: 'Login via Azure CLI'
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}

    - name: 'Docker Login'
      uses: azure/docker-login@v1
      with:
        login-server: containerregistry.azurecr.io
        username: ${{ secrets.REGISTRY_USERNAME }}
        password: ${{ secrets.REGISTRY_PASSWORD }}

    - name: 'Compose Customized Docker Image'
      shell: bash
      run: |
        docker image build --build-arg AZ_DEVOPS_TOKEN="${{ secrets.AZ_DEVOPS_TOKEN }}"  . -t containerregistry.azurecr.io/my-azure-function:latest
        docker push containerregistry.azurecr.io/my-azure-function:latest

    - name: 'Run Azure Functions Container Action'
      uses: Azure/functions-container-action@v1.0.2 
      id: fa
      with:
        app-name: my-spec-prod-azure-function
        image: containerregistry.azurecr.io/my-azure-function:latest

    - name: Azure logout
      run: |
        az logout
bgarcial commented 3 years ago

Dear @AmrutaKawade I already using the latest version, but the error persists. Since you point out you have already upgraded the @actions/core version in this Azure/functions-container-action@v1.0.2 or @v1 any ideas what could be going on?

bgarcial commented 3 years ago

Dear @AmrutaKawade, @Hazhzeng, and @N-Usha Is there any chance to consider this issue? :)

AmrutaKawade commented 3 years ago

@bgarcial underline issue is

Error: Resource my-spec-prod-azure-function doesn't exist.

check if resource exists.

Hazhzeng commented 3 years ago

Hi @bgarcial,

Sorry for the confusion. The v1 version is actually pointing to the latest v1.0.2 version bumping the GitHub Action SDK to 1.2.6. In this version, we already fix the issue introduced by set-env. This issue only exists in the older version v1.0.1. That's why you're seeing this.

However, as Amruta mentioned, the root cause of your issue is not related to set-env command. You're seeing this because your my-spec-prod-azure-function resource is not created. If you have any questions, please let me know.

bgarcial commented 3 years ago

@Hazhzeng @AmrutaKawade

Thanks for your reply. That's is the strange of the situation. Of course the azure function exist. I am able to call it and send parameters to it. The tenant data and service principal used in azure login action has permissions over that azure function. I will review tomorrow this again, could be highly probable the value of the AZURE_CREDENTIALS secrets could be generated pointing to a wrong resource group. Is the only thing comes up to my mind in this case. I will let you know guys.

bgarcial commented 3 years ago

@Hazhzeng @AmrutaKawade Indeed the AZURE_CREDENTIALS value was not pointing to the correct place where the azure function is hosted. So I want to apologize to you all guys and thanks for your support. I will close this issue, since it isn't.