pythonazureazure-web-app-service

Azure python webapp deploy shows as running even though it is successful


When I deploy my webapp using the azure CLI the command keeps running until it times out but the app itself deploys successfully and quickly. Sometimes, seemingly randomly, the cli command correctly detects this and shows a successful deploy.

Command:

az webapp up --subscription <subscription> --name <webapp-name> --resource-group  <rg> --plan  <app-service-plan> --runtime PYTHON:3.11 --debug --verbose --launch-browser --location northeurope

Web app code (simplified, but issue persists):

from dotenv import load_dotenv
load_dotenv()
from fastapi import FastAPI

app = FastAPI()

@app.get("/version")
async def version():
    print('Hit version endpoint')
    return {"version": "1.0.0"}

The app is configured the variable SCM_DO_BUILD_DURING_DEPLOYMENT and startup command python -m uvicorn main:app --host 0.0.0.0 --workers 4.

As shown above, I've tried simplifying the app as much as possible with no success or clear understanding of why it randomly doesn't pick up that the deploy was successful.

In case it is useful, I know the deployment is successful because I update the /version endpoint and because from the Azure web portal, under Deployment > Deployment Center > Logs I can see a successful run: enter image description here

The debug and verbose logs don't provide any useful feedback, it is simply an infinite loop of:

cli.azure.cli.core.util: Request URL: 'https://management.azure.com/subscriptions/...'
<request details>
cli.azure.cli.core.util: Response status: 202
<answer details indicating instancesInProgress: 1 and successfulInstances: 0>
cli.azure.cli.command_modules.appservice.custom: Status: Starting the site... Time: 623(s)
cli.azure.cli.command_modules.appservice.custom: InprogressInstances: 1, SuccessfulInstances: 0

Has anyone found this issue and found a way to make the deployments consistently show success?


Solution

  • Azure python webapp deployment with az webapp up CLI command shows the In progress state even though it is successfully running from the host could be a temporary issue with the CLI deployment command. It might occur when the CLI console doesn't receive the exact deployment status check from the web app instance after deployment.

    Check below to fix the issue:

    There is an alternative deployment command called az webapp deployment source config-zip available in Azure development. You can use this command for a successful web app deployment. Here, you can also include a --timeout parameter to increase the timeout rather than default time taken to avoid the status check related conflicts.

    Also check the LogStream from the Portal under Monitoring and also an app service logs clearly during the deployment as the debug logs are only showing the app is stuck and in an progress state check.

    enter image description here

    By referring to the MSDoc, I tried to deploy a sample Fast API Python application and was able to perform the deployment successfully as shown below.

    Note: Add --logs parameter along with the command to retrieve the log information and also you can use it to compare the logs displayed within the Portal from Log Stream.

    az webapp up --runtime PYTHON:3.11 --sku B1 --logs

    enter image description here

    enter image description here