Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
331 stars 100 forks source link

[BUG] Deployment of function to Azure function app fails #1374

Closed zinyosrim closed 6 months ago

zinyosrim commented 7 months ago

I'm trying to deploy a python azure function application to azure. It's basically a HTTP trigger which posts parsed json content from the request to service bus. When running the application locally it behaves as expected: The HTTP trigger works fine, sending messages to service bus as well.

But, I can't deploy this app. Neither from vscode, nor command line.

❯ func start
Found Python version 3.11.6 (python3).

Azure Functions Core Tools
Core Tools Version:       4.0.5455 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.27.5.21554

[2023-11-28T12:54:07.838Z] Customer packages not in sys path. This should never happen! 
[2023-11-28T12:54:08.885Z] Worker process started and initialized.

Functions:

        webhook_listener:  http://localhost:7071/api/webhook

For detailed output, run func with --verbose flag.
[2023-11-28T12:54:13.838Z] Host lock lease acquired by instance ID '000000000000000000000000C5847AB5'.
[2023-11-28T12:56:41.390Z] Executing 'Functions.webhook_listener' (Reason='This function was programmatically called via the host APIs.', Id=3770f75c-8b15-44ff-9dee-cda70dcbb91a)
[2023-11-28T12:56:41.418Z] INFO - Processing a new webhook request
[2023-11-28T12:56:41.422Z] ManagedIdentityCredential will use IMDS
[2023-11-28T12:56:41.422Z] Processing a new webhook request
[2023-11-28T12:56:41.422Z] No environment configuration found.
[2023-11-28T12:56:43.764Z] DefaultAzureCredential acquired a token from AzureCliCredential
[2023-11-28T12:56:44.966Z] INFO - Webhook successfully processed and sent to Service Bus
[2023-11-28T12:56:44.966Z] Webhook successfully processed and sent to Service Bus
[2023-11-28T12:56:45.028Z] Executed 'Functions.webhook_listener' (Succeeded, Id=3770f75c-8b15-44ff-9dee-cda70dcbb91a, Duration=3650ms)

When I try to deploy the app from VS Code

Investigative information

Repro steps

  1. Create a function app on azure portal
  2. Create a function in VSCODE, Azure tab workspace (tried this with project as well)
  3. Deploy to function app -> deployment fails

Actual behavior

13:58:29 cc-webhookhandler: Added feature flag "EnableWorkerIndexing" because it is required for the new programming model
13:58:30 cc-webhookhandler: Verifying that app settings have propagated... (Attempt 1/12)
13:58:31 cc-webhookhandler: Starting deployment...
13:58:31 cc-webhookhandler: Creating zip package...
13:58:31 cc-webhookhandler: Zip package size: 15.8 kB
13:58:32 cc-webhookhandler: Fetching changes.
13:58:33 cc-webhookhandler: Cleaning up temp folders from previous zip deployments and extracting pushed zip file /tmp/zipdeploy/8ee50529-3db8-49fe-9f9c-61cce7ce1b84.zip (0.03 MB) to /tmp/zipdeploy/extracted
13:58:35 cc-webhookhandler: Updating submodules.
13:58:36 cc-webhookhandler: Preparing deployment for commit id '04d59108-c'.
13:58:36 cc-webhookhandler: PreDeployment: context.CleanOutputPath False
13:58:36 cc-webhookhandler: PreDeployment: context.OutputPath /home/site/wwwroot
13:58:36 cc-webhookhandler: Repository path is /tmp/zipdeploy/extracted
13:58:36 cc-webhookhandler: Running oryx build...
13:58:36 cc-webhookhandler: Command: oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform python --platform-version 3.11 -p packagedir=.python_packages/lib/site-packages
13:58:37 cc-webhookhandler: Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx
13:58:37 cc-webhookhandler: You can report issues at https://github.com/Microsoft/Oryx/issues
13:58:37 cc-webhookhandler: Oryx Version: 0.2.20230210.1, Commit: a49c8f6b8abbe95b4356552c4c884dea7fd0d86e, ReleaseTagName: 20230210.1
13:58:37 cc-webhookhandler: Build Operation ID: 1cdd01f697cc23eb
13:58:37 cc-webhookhandler: Repository Commit : 04d59108-ccbe-4920-8d51-47bde0ed59b0
13:58:37 cc-webhookhandler: OS Type           : bullseye
13:58:37 cc-webhookhandler: Image Type        : githubactions
13:58:37 cc-webhookhandler: Detecting platforms...
13:58:38 cc-webhookhandler: Detected following platforms:
13:58:38 cc-webhookhandler:   python: 3.11.6
13:58:38 cc-webhookhandler: Version '3.11.6' of platform 'python' is not installed. Generating script to install it...
13:58:39 cc-webhookhandler: Source directory     : /tmp/zipdeploy/extracted
13:58:39 cc-webhookhandler: Destination directory: /home/site/wwwroot
13:58:39 cc-webhookhandler: Downloading and extracting 'python' version '3.11.6' to '/tmp/oryx/platforms/python/3.11.6'...
13:58:39 cc-webhookhandler: Detected image debian flavor: bullseye.
13:58:41 cc-webhookhandler: Downloaded in 2 sec(s).
13:58:41 cc-webhookhandler: Verifying checksum...
13:58:41 cc-webhookhandler: Extracting contents...
13:58:46 cc-webhookhandler: performing sha512 checksum for: python...
13:58:46 cc-webhookhandler: Done in 7 sec(s).
13:58:46 cc-webhookhandler: image detector file exists, platform is python..
13:58:46 cc-webhookhandler: OS detector file exists, OS is bullseye..
13:58:46 cc-webhookhandler: Python Version: /tmp/oryx/platforms/python/3.11.6/bin/python3.11
13:58:46 cc-webhookhandler: Creating directory for command manifest file if it does not exist
13:58:46 cc-webhookhandler: Removing existing manifest file
13:58:46 cc-webhookhandler: Running pip install...
13:58:48 cc-webhookhandler: Done in 2 sec(s).
13:58:48 cc-webhookhandler: [12:58:47+0000] Collecting azure-functions
13:58:48 cc-webhookhandler: [12:58:47+0000]   Downloading azure_functions-1.17.0-py3-none-any.whl (165 kB)
13:58:48 cc-webhookhandler: [12:58:47+0000] Installing collected packages: azure-functions
13:58:48 cc-webhookhandler: [12:58:47+0000] Successfully installed azure-functions-1.17.0
13:58:48 cc-webhookhandler: WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
13:58:48 cc-webhookhandler: WARNING: You are using pip version 21.2.4; however, version 23.3.1 is available.
13:58:48 cc-webhookhandler: You should consider upgrading via the '/tmp/oryx/platforms/python/3.11.6/bin/python3.11 -m pip install --upgrade pip' command.
13:58:48 cc-webhookhandler: Not a vso image, so not writing build commands
13:58:48 cc-webhookhandler: Preparing output...
13:58:48 cc-webhookhandler: Copying files to destination directory '/home/site/wwwroot'...
13:58:48 cc-webhookhandler: Done in 0 sec(s).
13:58:48 cc-webhookhandler: Removing existing manifest file
13:58:48 cc-webhookhandler: Creating a manifest file...
13:58:48 cc-webhookhandler: Manifest file created.
13:58:48 cc-webhookhandler: Copying .ostype to manifest output directory.
13:58:48 cc-webhookhandler: Done in 9 sec(s).
13:58:50 cc-webhookhandler: Running post deployment command(s)...
13:58:50 cc-webhookhandler: Generating summary of Oryx build
13:58:50 cc-webhookhandler: Deployment Log file does not exist in /tmp/oryx-build.log
13:58:50 cc-webhookhandler: The logfile at /tmp/oryx-build.log is empty. Unable to fetch the summary of build
13:58:50 cc-webhookhandler: Triggering recycle (preview mode disabled).
13:58:50 cc-webhookhandler: Linux Consumption plan has a 1.5 GB memory limit on a remote build container.
13:58:50 cc-webhookhandler: To check our service limit, please visit https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale#service-limits
13:58:50 cc-webhookhandler: Writing the artifacts to a squashfs file
13:58:50 cc-webhookhandler: Parallel mksquashfs: Using 1 processor
13:58:50 cc-webhookhandler: Creating 4.0 filesystem on /home/site/artifacts/functionappartifact.squashfs, block size 131072.
13:58:51 cc-webhookhandler: [===============================================================|] 149/149 100%
13:58:51 cc-webhookhandler: Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
13:58:51 cc-webhookhandler:     compressed data, compressed metadata, compressed fragments,
13:58:51 cc-webhookhandler:     compressed xattrs, compressed ids
13:58:51 cc-webhookhandler:     duplicates are removed
13:58:51 cc-webhookhandler: Filesystem size 430.52 Kbytes (0.42 Mbytes)
13:58:51 cc-webhookhandler:     28.51% of uncompressed filesystem size (1509.84 Kbytes)
13:58:51 cc-webhookhandler: Inode table size 1552 bytes (1.52 Kbytes)
13:58:51 cc-webhookhandler:     28.82% of uncompressed inode table size (5386 bytes)
13:58:51 cc-webhookhandler: Directory table size 1620 bytes (1.58 Kbytes)
13:58:51 cc-webhookhandler:     37.12% of uncompressed directory table size (4364 bytes)
13:58:51 cc-webhookhandler: Number of duplicate files found 3
13:58:51 cc-webhookhandler: Number of inodes 168
13:58:51 cc-webhookhandler: Number of files 151
13:58:51 cc-webhookhandler: Number of fragments 12
13:58:51 cc-webhookhandler: Number of symbolic links  0
13:58:51 cc-webhookhandler: Number of device nodes 0
13:58:51 cc-webhookhandler: Number of fifo nodes 0
13:58:51 cc-webhookhandler: Number of socket nodes 0
13:58:51 cc-webhookhandler: Number of directories 17
13:58:51 cc-webhookhandler: Number of ids (unique uids + gids) 1
13:58:51 cc-webhookhandler: Number of uids 1
13:58:51 cc-webhookhandler:     root (0)
13:58:51 cc-webhookhandler: Number of gids 1
13:58:51 cc-webhookhandler:     root (0)
13:58:51 cc-webhookhandler: Creating placeholder blob for linux consumption function app...
13:58:51 cc-webhookhandler: SCM_RUN_FROM_PACKAGE placeholder blob scm-latest-cc-webhookhandler.zip located
13:58:51 cc-webhookhandler: Uploading built content /home/site/artifacts/functionappartifact.squashfs for linux consumption function app...
13:58:51 cc-webhookhandler: Resetting all workers for cc-webhookhandler.azurewebsites.net
13:58:51 cc-webhookhandler: Deployment successful. deployer = ms-azuretools-vscode deploymentPath = Functions App ZipDeploy. Extract zip. Remote build.
13:59:07 cc-webhookhandler: Syncing triggers...
13:59:16 cc-webhookhandler: Querying triggers...
13:59:18 cc-webhookhandler: No HTTP triggers found.

When I go to the azure portal, don't see any functions in my app.

Known workarounds

Tried a deploy via func azure functionapp publish cc-webhookhandler:

.....
Creating placeholder blob for linux consumption function app...
SCM_RUN_FROM_PACKAGE placeholder blob scm-latest-cc-webhookhandler.zip located
Uploading built content /home/site/artifacts/functionappartifact.squashfs for linux consumption function app...
Resetting all workers for cc-webhookhandler.azurewebsites.net
Deployment successful. deployer = Push-Deployer deploymentPath = Functions App ZipDeploy. Extract zip. Remote build.
Remote build succeeded!
[2023-11-28T13:27:06.347Z] Syncing triggers...
# the output stops here
azure-common==1.1.28
azure-core==1.29.5
azure-functions==1.17.0
azure-identity==1.15.0
azure-keyvault-secrets==4.7.0
azure-servicebus==7.11.4
.....

Deploying this code in the same environment works fine.

try:
    import azure.functions as func
    import logging
except:
    pass

app = func.FunctionApp()

@app.function_name(name="http_trigger")
@app.route(route="hello")
def hello(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

Whats going wrong here?

bhagyshricompany commented 7 months ago

Thanks for reporting will check and update.

bhagyshricompany commented 7 months ago

Hi @zinyosrim one way you can try without using "try and pass" otherwise follow this process and test if you get any error see in problem tab in vs code. Go to your function app and deploy

image

its working fine after deployment on azure.

image image image image image
microsoft-github-policy-service[bot] commented 6 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.