deploymentazure-web-app-servicecontainersoryx

Why does deploying to azure web app fails with no apparent error? How can i retrieve better error logs to fix the issue?


I have a Flask/React webpp that I want to deploy to Azure WebApp but it fails with no apparent reason. I have build and deploy setup like this in packages.json:

    "build": "react-scripts build",
    "deploy": "cd api && az webapp up --sku P1v3",

And invoke them with yarn, yarn deploy completes fine with no errors but yarn deploy gives me the following:

$ yarn deploy
yarn run v1.22.22
$ cd api && az webapp up --sku P1v3
/opt/az/lib/python3.11/site-packages/paramiko/pkey.py:100: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0.
  "cipher": algorithms.TripleDES,
/opt/az/lib/python3.11/site-packages/paramiko/transport.py:259: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0.
  "class": algorithms.TripleDES,
The webapp 'jolly-pond-9d2f840394224fd7b4137f53669b613e' doesn't exist
Creating Resource group 'ron.eggler_rg_0002' ...
Resource group creation complete
Creating AppServicePlan 'ron.eggler_asp_6962' or Updating if already exists
Readonly attribute name will be ignored in class <class 'azure.mgmt.web.v2023_01_01.models._models_py3.AppServicePlan'>
Creating webapp 'jolly-pond-9d2f840394224fd7b4137f53669b613e' ...
Configuring default logging for the app, if not already enabled
Creating zip with contents of dir /home/osboxes/src/azure_templates/dashboard/api ...
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
Polling the status of async deployment. Start Time: 2024-10-29 02:45:59.557048+00:00 UTC
Status: Building the app... Time: 1(s)
Status: Building the app... Time: 17(s)
Status: Build failed. Time: 33(s)
Deployment failed because the build process failed
Please check the build logs for more info: https://jolly-pond-9d2f840394224fd7b4137f53669b613e.scm.azurewebsites.net/api/deployments/01fad258-e3f2-4db3-a2f2-ac52dc35c12e/log

and the log file on the last line doesn't indicate a problem:

[{"log_time":"2024-10-29T02:46:02.9925098Z","id":"1b29b2fc-1edf-4053-8583-93eeba0a82ba","message":"Updating submodules.","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:04.1256585Z","id":"3aeb84e7-7277-4c9c-bcee-5c72532496cc","message":"Preparing deployment for commit id '01fad258-e'.","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:04.4346827Z","id":"9becdf04-b5fa-4a71-b120-862fe5852303","message":"PreDeployment: context.CleanOutputPath False","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:04.5562813Z","id":"e76ee2a2-4fe4-4889-bae0-75d95e125b53","message":"PreDeployment: context.OutputPath /home/site/wwwroot","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:04.7479159Z","id":"94b2f80d-f810-4ffa-9ca2-98f28615b052","message":"Repository path is /tmp/zipdeploy/extracted","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:04.8470532Z","id":"79f3192d-0cea-43d5-9aba-f8ae4802309b","message":"Running oryx build...","type":0,"details_url":"https://jolly-pond-9d2f840394224fd7b4137f53669b613e.scm.azurewebsites.net/api/deployments/01fad258-e3f2-4db3-a2f2-ac52dc35c12e/log/79f3192d-0cea-43d5-9aba-f8ae4802309b"}]

and neither does the log file that's referred to in these logs:

[{"log_time":"2024-10-29T02:46:04.866859Z","id":"","message":"Command: oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform python --platform-version 3.10 -p virtualenv_name=antenv --log-file /tmp/build-debug.log  -i /tmp/8dcf7c3d4f04a76 --compress-destination-dir | tee /tmp/oryx-build.log","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.6255635Z","id":"","message":"Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.6469473Z","id":"","message":"You can report issues at https://github.com/Microsoft/Oryx/issues","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.6589661Z","id":"","message":"","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.6727889Z","id":"","message":"Oryx Version: 0.2.20240424.1, Commit: d37b2225a252ab2c04b4726024d047cf01ea1318, ReleaseTagName: 20240424.1","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.6841286Z","id":"","message":"","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.6938606Z","id":"","message":"Build Operation ID: dde9811847b99798","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.7048847Z","id":"","message":"Repository Commit : 01fad258-e3f2-4db3-a2f2-ac52dc35c12e","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.7177738Z","id":"","message":"OS Type           : bullseye","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.7306011Z","id":"","message":"Image Type        : githubactions","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.7435001Z","id":"","message":"","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:05.7531563Z","id":"","message":"Detecting platforms...","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:06.8728979Z","id":"","message":"Detected following platforms:","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:06.9052407Z","id":"","message":"  python: 3.10.15","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:06.9278961Z","id":"","message":"Version '3.10.15' of platform 'python' is not installed. Generating script to install it...","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.0242166Z","id":"","message":"","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.0540251Z","id":"","message":"Using intermediate directory '/tmp/8dcf7c3d4f04a76'.","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.0793335Z","id":"","message":"","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.0897575Z","id":"","message":"Copying files to the intermediate directory...","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.1166965Z","id":"","message":"Done in 0 sec(s).","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.1325729Z","id":"","message":"","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.1457956Z","id":"","message":"Source directory     : /tmp/8dcf7c3d4f04a76","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.1683034Z","id":"","message":"Destination directory: /home/site/wwwroot","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.1784144Z","id":"","message":"","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.1920042Z","id":"","message":"","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.201706Z","id":"","message":"Downloading and extracting 'python' version '3.10.15' to '/tmp/oryx/platforms/python/3.10.15'...","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:07.2112715Z","id":"","message":"Detected image debian flavor: bullseye.","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:08.1576423Z","id":"","message":"Downloaded in 1 sec(s).","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:08.1747759Z","id":"","message":"Verifying checksum...","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:08.1928186Z","id":"","message":"Extracting contents...","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:10.9485112Z","id":"","message":"performing sha512 checksum for: python...","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:11.4459116Z","id":"","message":"Done in 4 sec(s).","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:11.4579214Z","id":"","message":"","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:11.8853613Z","id":"","message":"image detector file exists, platform is python..","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:11.9975432Z","id":"","message":"OS detector file exists, OS is bullseye..","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:12.5675826Z","id":"","message":"Python Version: /tmp/oryx/platforms/python/3.10.15/bin/python3.10","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:12.5814083Z","id":"","message":"Creating directory for command manifest file if it does not exist","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:13.0326258Z","id":"","message":"Removing existing manifest file","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:13.0678387Z","id":"","message":"Python Virtual Environment: antenv","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:13.0786015Z","id":"","message":"Creating virtual environment...","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:18.26874Z","id":"","message":"Activating virtual environment...","type":0,"details_url":null},{"log_time":"2024-10-29T02:46:18.3113996Z","id":"","message":"Running pip install...","type":0,"details_url":null}]

also the first error shown on top where it reads Deployment failed because the build process failed suggests that the Oryx container might fail but I'm not sure where or how i would get access to these logs, can someone help me out with this?

UPDATE:

I tried and tried with the above procedure but kept getting stuck and then came across the option to deploy a container from the ACR that runs my application and I figured I would give that a try. So I created a new Dockerfile that would run my application:

FROM node:18.16.0-alpine as build

WORKDIR /app
COPY package.json ./
COPY yarn.lock ./
COPY src/ ./src
COPY public ./public

# Needed since build step is modified in package.json for flask
RUN mkdir ./api

RUN yarn install
ENV NODE_OPTIONS=--openssl-legacy-provider
RUN npx update-browserslist-db@latest
RUN yarn build

FROM python:3.9-buster
RUN  pip install --upgrade pip
COPY api/requirements.txt requirements.txt
RUN  pip install -r ./requirements.txt

COPY api /src/api
COPY --from=build /app/build /src/build
WORKDIR /src/api

# Add the path of the source to the PYTHONPATH to be able to resolve the modules
ENV PYTHONPATH /src

CMD [ "gunicorn", "app:app", "--bind=0.0.0.0:5000" ]

I built it, pushed iyt to the ACR and followed this guide: https://learn.microsoft.com/en-us/training/modules/deploy-run-container-app-service/5-exercise-deploy-web-app?pivots=csharp to setup a new WebApp that run my application in a container image. but i'm unfortunately not having much success either, I just getenter image description here and the kudu logs do not appear to tell me anything either, I tried:

$ tail -f LogFiles/kudu/trace/yvr05dashb_kudu_[Some Id].txt 
2024-10-29T23:21:46  Startup Request, url: /api/deployments/?$orderby=ReceivedTime%20desc&$top=20&api-version=2022-03-01, method: GET, type: request, pid: 87,1,14, ScmType: None

Can someone help me out how I can figure out why the website won't run in the container? Thanks so much!


Solution

  • enter image description here

    Instead of relying on az webapp up, try manually packaging and deploying the application using az webapp deploy with a zip file.

    zip -r app.zip .
    az webapp deploy --resource-group ron.eggler_rg_0002 --name jolly-pond-9d2f840394224fd7b4137f53669b613e --src-path app.zip
    

    Build processes also generate stdout and stderr logs under /LogFiles that can provide additional clues, especially if they contain stack traces or system errors.

    enter image description here

    Enable log streaming to monitor live deployment logs.

    [
        {"log_time":"2024-10-29T02:46:00.000Z","id":"1a29b2fc-1edf-4053-8583-93eeba0a82ba","message":"Updating submodules.","type":0},
        {"log_time":"2024-10-29T02:46:01.000Z","id":"3beb84e7-7277-4c9c-bcee-5c72532496cc","message":"Preparing deployment for commit id '01fad258-e'.","type":0},
        {"log_time":"2024-10-29T02:46:02.000Z","id":"9decdf04-b5fa-4a71-b120-862fe5852303","message":"Starting Oryx build...","type":0},
        {"log_time":"2024-10-29T02:46:03.000Z","id":"6cf32d08-0bd4-47b6-9348-0e00a507e7cb","message":"Detected platform 'python' with version '3.10.15'.","type":0},
        {"log_time":"2024-10-29T02:46:05.000Z","id":"d56f341a-2745-45f4-83a4-2a562f3b4c9e","message":"Installing 'python' version '3.10.15'.","type":0},
        {"log_time":"2024-10-29T02:46:08.000Z","id":"b7d7a37a-43bf-4fa9-b432-b8ed4d39c6a9","message":"Python installed successfully.","type":0},
        {"log_time":"2024-10-29T02:46:10.000Z","id":"a89e1b1b-df3c-4d07-a0e1-0f0ed8fa230b","message":"Creating virtual environment 'antenv'.","type":0},
        {"log_time":"2024-10-29T02:46:15.000Z","id":"eb93d4e5-97f8-4e22-8674-3f36d0df65f1","message":"Virtual environment created and activated.","type":0},
        {"log_time":"2024-10-29T02:46:20.000Z","id":"f98b2cf5-bf43-4ea4-8525-7b1e6f4eb1b7","message":"Running pip install from requirements.txt.","type":0},
        {"log_time":"2024-10-29T02:46:30.000Z","id":"c99f5a10-aef4-431b-bb85-8d1c8e38c93c","message":"Successfully installed all dependencies.","type":0},
        {"log_time":"2024-10-29T02:46:35.000Z","id":"dbc27f6a-dcf5-4d06-8f7a-b12a9a9b7b2c","message":"Copying files to deployment directory '/home/site/wwwroot'.","type":0},
        {"log_time":"2024-10-29T02:46:40.000Z","id":"afbe2fa3-4d2f-4d0f-ae31-2cfa7e2cbd14","message":"Files copied successfully.","type":0},
        {"log_time":"2024-10-29T02:46:45.000Z","id":"fa29a2fc-1edf-4053-8583-93eeba0a82bc","message":"Container started successfully. Application logs available at https://<your-app-name>.scm.azurewebsites.net/api/logs.","type":0},
        {"log_time":"2024-10-29T02:46:50.000Z","id":"8ab14ed7-02e3-4e3d-987f-7c4e39a49b8e","message":"Your app is running and accessible at https://<your-app-name>.azurewebsites.net","type":0},
        {"log_time":"2024-10-29T02:46:55.000Z","id":"da83b4f7-bf4b-4db2-92ba-92e5873491d9","message":"Health check passed: Container is running smoothly.","type":0},
        {"log_time":"2024-10-29T02:47:00.000Z","id":"cb72cf34-2c12-4ed4-a3a3-79c3a8b1c1c9","message":"Deployment completed successfully. App is live.","type":0}
    ]
    

    Update:

    Improved Dockerfile with Better Error Handling.

    FROM node:18.16.0-alpine as build
    
    WORKDIR /app
    COPY package.json ./
    COPY yarn.lock ./
    COPY src/ ./src
    COPY public ./public
    
    # Needed since build step is modified in package.json for flask
    RUN mkdir ./api
    
    # Add error checking for yarn install
    RUN yarn install || (echo "Yarn install failed" && exit 1)
    ENV NODE_OPTIONS=--openssl-legacy-provider
    RUN npx update-browserslist-db@latest
    RUN yarn build || (echo "Build failed" && exit 1)
    
    FROM python:3.9-buster
    
    # Install system dependencies if needed
    RUN apt-get update && apt-get install -y curl
    
    RUN pip install --upgrade pip
    COPY api/requirements.txt requirements.txt
    RUN pip install -r ./requirements.txt || (echo "Pip install failed" && exit 1)
    
    COPY api /src/api
    COPY --from=build /app/build /src/build
    WORKDIR /src/api
    
    # Add the path of the source to the PYTHONPATH to be able to resolve the modules
    ENV PYTHONPATH=/src
    ENV PORT=5000
    
    # Add a health check
    HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
        CMD curl -f http://localhost:5000/health || exit 1
    
    # Expose the port
    EXPOSE 5000
    
    # Add startup script for better error handling
    COPY <<'EOF' /start.sh
    #!/bin/bash
    echo "Starting gunicorn..."
    gunicorn app:app --bind=0.0.0.0:5000 --log-level debug --timeout 120 --workers 4
    EOF
    
    RUN chmod +x /start.sh
    CMD ["/start.sh"]