Help with Troubleshooting Issue with GitHub Actions Deployment to Microsoft Azure App Services

James Hizon 20 Reputation points
2025-02-13T17:42:08.6+00:00

I have been testing build and deploy constantly and have been stuck with troubleshooting for past few days while continuing to alter the "workflow file."

I have dabbled with additionally testing different "Startup command" sequence like instead of having "npm install && npm run build && npm run start," I just kept this all to be done on the "Workflow file" for the install and build so I can just run start in my workflow file. This way, I can ensure that we accurately detect my files for zipping and change to correct working directory as is needed with manually updating the "Workflow file."

This is my most recent error message:

7m 26s

8Run azure/webapps-deploy@v3

6Package deployment using OneDeploy initiated.

7Error: Failed to deploy web package to App Service.

8Error: Deployment Failed, Error: Failed to deploy web package using OneDeploy to App Service.

9Service Unavailable (CODE: 503)

10App Service Application URL: https://provensuccess-co.azurewebsites.net

And, this is my Workflow file as of recent (try to copy and paste to maybe chatgpt to reformat for readability):

#`` Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy``#`` More GitHub Actions for Azure: https://github.com/Azure/actions ``#`` Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy``#`` More GitHub Actions for Azure: https://github.com/Azure/actions ``name``: ``Build and deploy Node.js app to Azure Web App - provensuccess-co`` ``on``: ``push``: ``branches``: - ``main`` ``workflow_dispatch``: ``permissions``: ``id-token``: ``write #`` Required for OIDC authentication ``contents``: ``read #`` Required to access repository contents ``jobs``: ``build``: ``runs-on``: ``ubuntu-latest`` ``steps``: - ``name``: ``Checkout Code`` ``uses``: ``actions/checkout@v4`` - ``name``: ``Set up Node.js`` ``uses``: ``actions/setup-node@v3`` ``with``: ``node-version``: ``'``18.x``'`` - ``name``: ``Install Dependencies`` ``run``: ``| cd agentic-growth-ai npm ci`` - ``name``: ``Build the Application`` ``run``: ``| cd agentic-growth-ai npm run build`` ``env``: ``OPENAI_API_KEY``: ``${{ secrets.OPENAI_API_KEY }}`` ``#`` Zip the built app and move the zip to the root directory - ``name``: ``Zip Artifact for Deployment`` ``run``: ``| cd agentic-growth-ai zip -r ../release.zip . -x "node_modules/*" # Includes hidden files like .env, .next, etc. ``- ``name``: ``Upload Artifact for Deployment Job`` ``uses``: ``actions/upload-artifact@v4`` ``with``: ``name``: ``node-app`` ``path``: ``release.zip`` - ``name``: ``Verify zip contents`` ``run``: ``unzip -l release.zip`` ``deploy``: ``runs-on``: ``ubuntu-latest`` ``needs``: ``build`` ``environment``: ``name``: ``'``Production``'`` ``url``: ``${{ steps.deploy-to-webapp.outputs.webapp-url }}`` ``steps``: - ``name``: ``Download Artifact from Build Job`` ``uses``: ``actions/download-artifact@v4`` ``with``: ``name``: ``node-app`` ``path``: ``.`` - ``name``: ``List files after artifact download`` ``run``: ``ls -la #`` Should list release.zip in the workspace root ``#`` Unzip the artifact before deploying - ``name``: ``Unzip the Release Artifact`` ``run``: ``unzip release.zip -d ./release-unzipped`` ``#`` List files in the unzipped folder to verify - ``name``: ``List files after unzip`` ``run``: ``ls -la ./release-unzipped`` ``#`` Login to Azure using OIDC - ``name``: ``Login to Azure`` ``uses``: ``azure/login@v2`` ``with``: ``client-id``: ``${{ secrets.AZURE_CLIENT_ID }}`` ``tenant-id``: ``${{ secrets.AZURE_TENANT_ID }}`` ``subscription-id``: ``${{ secrets.AZURE_SUBSCRIPTION_ID }}`` ``#`` Deploy the unzipped folder to Azure - ``name``: ``Deploy to Azure Web App`` ``id``: ``deploy-to-webapp`` ``uses``: ``azure/webapps-deploy@v3`` ``with``: ``app-name``: ``'``provensuccess-co``'`` ``package``: ``release.zip`` - ``name``: ``Restart Azure App Service`` ``run``: ``az webapp restart --name provensuccess-co --resource-group provensuccess-rg

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,295 questions
{count} votes

Accepted answer
  1. Siva Nair 75 Reputation points Microsoft Vendor
    2025-02-14T11:55:21.5533333+00:00

    Hi James Hizon,

    Welcome to the Microsoft Q&A.

    To fix the issue, Lets follow few steps:

    Based on error log provided by you it seems like, startup script cannot find the 'next' command when trying to run 'next start -p $PORT'. The error message "sh: 1: next: not found" indicates that Next.js is not installed or not accessible in the deployment environment.

    The most likely cause is that 'node_modules' is missing in the deployment. This can happen if dependencies were not installed properly after deployment or were excluded when packaging the app. Even though your workflow installs dependencies before building (npm ci --legacy-peer-deps), it appears they might not be available on the Azure Web App container.

    1. Ensure Dependencies Are Installed in Azure- In your workflow, you attempt to SSH into the Azure App Service and install dependencies using:   az webapp ssh --resource-group provensuccess-rg --name 'provensuccess-co' --command "cd /home/site/wwwroot && npm install --legacy-peer-deps".However, this might not be running successfully. Try manually logging into the App Service via SSH and running 'npm install' to check for errors.
    2. Verify Deployment Package Includes 'node_modules'.Before zipping and deploying, check if node_modules exists locally. Run: ls -la agentic-growth-ai/node_modules. If it's missing, you may need to adjust your zip command to include it.
    3. Force Dependency Installation Before Running. Modify your startup command in Azure to ensure dependencies are installed before running the app:   npm install && npm run start. This ensures dependencies are always installed before launching the server.
    4. Check package.json Scripts. Ensure "start" in package.json is correctly set to: "start": "next start -p $PORT". Also, confirm that next is listed as a dependency in package.json.
    5. Try Running next build Locally on Azure:- If the next command is missing, try running: npx next build. If this fails, you may need to install next globally or within your project: npm install next.

    If you have any further assistant, do let me know.

    If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.


1 additional answer

Sort by: Most helpful
  1. James Hizon 20 Reputation points
    2025-02-14T03:13:48.38+00:00

    hm... ok I think I am stuck elsewhere:

    2025-02-14T03:05:37  No new trace in the past 1 min(s).
    2025-02-14T03:05:37.913Z INFO  - Starting container for site
    2025-02-14T03:05:37.919Z INFO  - docker run -d --expose=8081 --name provensuccess-co_0_4fdc3f8f_msiProxy -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=provensuccess-co.azurewebsites.net -e WEBSITE_INSTANCE_ID=4a9f6b890cf67de3ac9e3e730d3918d91171efbfce68dbba805f22c3e6e3071e -e HTTP_LOGGING_ENABLED=1 mcr.microsoft.com/appsvc/msitokenservice:stage5 REDACTED
    FO  - Starting container for site
    2025-02-14T03:05:50.931Z INFO  - docker run -d -p 7531:8080 --name provensuccess-co_0_4fdc3f8f -e WEBSITE_USE_DIAGNOSTIC_SERVER=true -e WEBSITE_SITE_NAME=provensuccess-co -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=provensuccess-co.azurewebsites.net -e WEBSITE_INSTANCE_ID=4a9f6b890cf67de3ac9e3e730d3918d91171efbfce68dbba805f22c3e6e3071e -e HTTP_LOGGING_ENABLED=1 appsvc/node:18-lts_20240819.2.tuxprod REDACTED
    2025-02-14T03:05:53.422Z INFO  - Initiating warmup request to container provensuccess-co_0_4fdc3f8f_msiProxy for site provensuccess-co
    2025-02-14T03:05:53.504Z INFO  - Container provensuccess-co_0_4fdc3f8f_msiProxy for site provensuccess-co initialized successfully and is ready to serve requests.
    2025-02-14T03:05:53.512Z INFO  - Initiating warmup request to container provensuccess-co_0_4fdc3f8f for site provensuccess-co
    2025-02-14T03:05:52.914691728Z    _____                               
    2025-02-14T03:05:52.914732979Z   /  _  \ __________ _________   ____  
    2025-02-14T03:05:52.914735826Z  /  /_\  \\___   /  |  \_  __ \_/ __ \ 
    2025-02-14T03:05:52.914737955Z /    |    \/    /|  |  /|  | \/\  ___/ 
    2025-02-14T03:05:52.914739842Z \____|__  /_____ \____/ |__|    \___  >
    2025-02-14T03:05:52.914741998Z         \/      \/                  \/ 
    2025-02-14T03:05:52.914743922Z A P P   S E R V I C E   O N   L I N U X
    2025-02-14T03:05:52.914745723Z 
    2025-02-14T03:05:52.914747385Z Documentation: http://aka.ms/webapp-linux
    2025-02-14T03:05:52.914749119Z NodeJS quickstart: https://aka.ms/node-qs
    2025-02-14T03:05:52.914750850Z NodeJS Version : v18.20.4
    2025-02-14T03:05:52.914752650Z Note: Any data outside '/home' is not persisted
    2025-02-14T03:05:52.914754517Z 
    2025-02-14T03:05:55.323308120Z Starting OpenBSD Secure Shell server: sshd.
    2025-02-14T03:05:55.340884102Z WEBSITES_INCLUDE_CLOUD_CERTS is not set to true.
    2025-02-14T03:05:55.496753700Z Starting periodic command scheduler: cron.
    2025-02-14T03:05:55.563601400Z Could not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
    2025-02-14T03:05:55.563616527Z Could not find operation ID in manifest. Generating an operation id...
    2025-02-14T03:05:55.565322930Z Build Operation ID: 3eecefd9-9647-497c-9c61-3e7350d5331c
    2025-02-14T03:05:56.325007492Z Environment Variables for Application Insight's IPA Codeless Configuration exists..
    2025-02-14T03:05:56.363333500Z Writing output script to '/opt/startup/startup.sh'
    2025-02-14T03:05:56.433238977Z Running #!/bin/sh
    2025-02-14T03:05:56.433256459Z 
    2025-02-14T03:05:56.433275955Z # Enter the source directory to make sure the script runs where the user expects
    2025-02-14T03:05:56.433278966Z cd "/home/site/wwwroot"
    2025-02-14T03:05:56.433281456Z 
    2025-02-14T03:05:56.433283549Z export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
    2025-02-14T03:05:56.433285941Z if [ -z "$PORT" ]; then
    2025-02-14T03:05:56.433288227Z 		export PORT=8080
    2025-02-14T03:05:56.433290814Z fi
    2025-02-14T03:05:56.433292831Z 
    2025-02-14T03:05:56.433294835Z PATH="$PATH:/home/site/wwwroot" PORT=8080 npm run start --prefix /home/site/wwwroot
    2025-02-14T03:05:59.303597596Z npm info using npm@10.7.0
    2025-02-14T03:05:59.304085706Z npm info using node@v18.20.4
    2025-02-14T03:06:06.166675120Z 
    2025-02-14T03:06:06.166697064Z > agentic-growth-ai@0.1.0 start
    2025-02-14T03:06:06.166700164Z > next start -p $PORT
    2025-02-14T03:06:06.166702183Z 
    2025-02-14T03:06:06.357042831Z sh: 1: next: not found
    
    2025-02-14T03:06:06.928Z ERROR - Container provensuccess-co_0_4fdc3f8f for site provensuccess-co has exited, failing site start
    2025-02-14T03:06:06.940Z ERROR - Container provensuccess-co_0_4fdc3f8f didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
    2025-02-14T03:06:07.017Z INFO  - Stopping site provensuccess-co because it failed during startup.
    2025-02-14T03:07:39  No new trace in the past 1 min(s).
    2025-02-14T03:08:39  No new trace in the past 2 min(s).
    2025-02-14T03:09:39  No new trace in the past 3 min(s).
    

    I've been continually trying to ensure that we do in fact communicate with port:8080 with adding to startup command like this:

    PORT=8080 npm run start --prefix /home/site/wwwroot

    ...or, adding this Dockerfile:

    # Use official Node.js image as base image
    FROM node:18-lts
    
    # Set working directory
    WORKDIR /home/site/wwwroot
    
    # Copy package.json and package-lock.json first (for caching)
    COPY package*.json ./
    
    # Install dependencies
    RUN npm install --production
    
    # Copy the rest of your application code
    COPY . .
    
    # Expose port (Azure expects 8080)
    EXPOSE 8080
    
    # Set the environment variable for the port
    ENV PORT=8080
    
    # Start the app
    CMD ["npm", "run", "start"]
    
    

    Again, this is my current updated workflow file (updated so I have .next, .node_modules, package.json and other essential files):

    ame: Build and deploy Node.js app to Azure Web App - provensuccess-co on: push: branches: - main workflow_dispatch: permissions: id-token: write contents: read jobs: build: runs-on: ubuntu-latest steps: - name: Checkout Code uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v3 with: node-version: '18.18' - name: Clear npm cache run: npm cache clean --force - name: Install Dependencies run: | cd agentic-growth-ai npm ci --legacy-peer-deps - name: Build the Application run: | cd agentic-growth-ai npm run build env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} # Zip the built app, ensuring node_modules/ is INCLUDED - name: Zip Artifact for Deployment run: | cd agentic-growth-ai zip -r ../release.zip . -x ".git/" "__MACOSX/*" # Keep node_modules - name: Upload Artifact for Deployment Job uses: actions/upload-artifact@v4 with: name: node-app path: release.zip - name: Verify zip contents run: unzip -l release.zip # Optional: Wait before deploying to avoid potential overlapping deployments - name: Wait before deploying run: sleep 30 # Optional, for ensuring app stability after build (can be adjusted) deploy: runs-on: ubuntu-latest needs: build environment: name: 'Production' url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} steps: - name: Download Artifact from Build Job uses: actions/download-artifact@v4 with: name: node-app path: . - name: List files after artifact download run: ls -la # Should list release.zip in the workspace root # Unzip the artifact before deploying - name: Unzip the Release Artifact run: unzip release.zip -d ./release-unzipped # List files in the unzipped folder to verify - name: List files after unzip run: ls -la ./release-unzipped - name: Force Logout of Azure (Ensure Fresh Token) run: az logout || true # Login to Azure using OIDC - name: Login to Azure uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - name: Verify Azure Account After Login run: az account show # Optional: Check if the app is ready before proceeding (health check) - name: Wait for app to be ready (Timeout Limit) run: | echo "Checking if app is ready..." for i in {1..12}; do # Try for 2 minutes max (12 attempts, 10s each) if curl -s --max-time 5 http://your-app-url/health-check; then echo "App is ready!" exit 0 fi echo "App not ready, retrying in 10s..." sleep 10 done echo "App did not become ready in time, continuing deployment anyway." # Deploy the unzipped folder to Azure - name: Deploy to Azure Web App id: deploy-to-webapp uses: azure/webapps-deploy@v3 with: app-name: 'provensuccess-co' package: ./release-unzipped # OPTION 1: Install Dependencies on Azure App Service (Retry Enabled) - name: SSH into Azure App Service & Install Dependencies run: | echo "Attempting to SSH into Azure App Service and install dependencies..." MAX_RETRIES=5 for ((i=1; i<=MAX_RETRIES; i++)); do echo "Attempt #$i to install dependencies..." az webapp ssh --resource-group provensuccess-rg --name 'provensuccess-co' --command "cd /home/site/wwwroot && npm install --legacy-peer-deps" if [ $? -eq 0 ]; then echo "Dependencies installed successfully!" exit 0 fi echo "Failed to install dependencies, retrying in 10s..." sleep 10 done echo "Dependency installation failed after $MAX_RETRIES attempts." exit 1 # Fail the workflow if dependencies cannot be installed

    ... you can copy & paste to GPT to reformat it. Even with gpt response, I feel like I am stuck going in circles.

    Any further assistance is much appreciated. :)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.