相关文章推荐
慷慨大方的竹笋  ·  ProcessBuilder 和 ...·  1 年前    · 
眼睛小的番茄  ·  AIR学术 | ...·  1 年前    · 
很拉风的柚子  ·  Android ...·  1 年前    · 

Hello everyone.

I wish to deploy a node api on Azure App Service using Github Actions. The app I wish to deploy is on a subfolder called "api" of the repository.

The Github Actions part works fine, but the website doesn't work, and when I look in the logs, it shows this error : "Error: Cannot find module '../package.json'".

The app should look for package.json in ./, I don't know why it is searching in ../ .

Here is my Github Actions yaml :

# 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 - hobbeez  
  push:  
    branches:  
      - main  
  workflow_dispatch:  
jobs:  
  build:  
    runs-on: ubuntu-latest  
    steps:  
      - uses: actions/checkout@v2  
      - name: Set up Node.js version  
        uses: actions/setup-node@v1  
        with:  
          node-version: '16.x'  
      - name: npm install, build, and test  
        run: |  
          npm install  
          npm run build --if-present  
        working-directory: api  
      - name: Upload artifact for deployment job  
        uses: actions/upload-artifact@v2  
        with:  
          name: node-app  
          path: .  
  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@v2  
        with:  
          name: node-app  
      - name: 'Deploy to Azure Web App'  
        id: deploy-to-webapp  
        uses: azure/webapps-deploy@v2  
        with:  
          app-name: 'hobbeez'  
          slot-name: 'Production'  
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_16C52153CB9348578BF747E038921ED6 }}  
          package: .  

I added a ".deployment" file at the root of the repository to specify that it should deploy the "api" subfolder, here is what this file contains :

[config]  
project = api  

I tried to search for the answer for weeks, but I didn't manage to find a solution. Does anyone have an idea of what am I doing wrong ?

Thanks in advance.

Miaourt, Apologies for the delay in responding here.

Just to highlight, yes In order for Kudu to detect a Node.js app, you need a package.json file and an app.js/index.js in the root of your folder. It's also recommended to correctly set the start script in the package.json file.

As for the NODE_PATH, which is used for loading modules from the global folders. If the NODE_PATH environment variable is set to a colon-delimited list of absolute paths, then Node.js will search those paths for modules if they are not found elsewhere.

Example:

  • name: Upload artifact for deployment job
    uses: actions/upload-artifact@v2
    with:
    name: node-app
    path: build/
  • Kudu assumes by default that deployments from zip files are ready to run and do not require additional build steps during deployment ( e.g. npm install ).
    This can be overridden by setting the SCM_DO_BUILD_DURING_DEPLOYMENT deployment setting to true.

    Set a startup file, have the PM2 configuration file or your script file. You can find a working sample for Web Apps On Linux here .

    To isolate the issue further:

    1.Navigate through Kudu site on: https://<sitename>.scm.azurewebsites.net/api/logs/docker
    2.Review the logs / docker.log

    Checkout this doc: Customizing deployments

    Kindly let us know how it goes, if the issue still persists, provide some more details on about you’re app framework.

    Hi, thanks for your answer and sorry for the late reply.

    If I understand well, there is no possibility to deploy an app from a subfolder of my repository ?

    The app I want to deploy is in a subfolder called "api/" of my repository, that is why I haven't a package.json file in the root of the repository. But this documentation seems to indicate that it is possible to use a .deployment file to deploy only the content of that subfolder, am I wrong ?

    As for the NODE_PATH, I tried setting it in the api/ folder, but I had the exact same problem after the deployment.

    In the "build" section of my github actions file, I have a npm install to run :

           - name: npm install, build, and test  
             run: |  
               npm install  
               npm run build --if-present  
             working-directory: api  
    

    Do I need to add an additional build step during the deployment ? I tried to enable the SCM_DO_BUILD_DURING_DEPLOYMENT deployment setting anyway, but it ended up with an error during the deployment with github actions. (I didn't save the error, but I can try it again if you need it).

    Thanks again for your help.

    Miaourt, Thanks for the follow-up and additional info.

    From your webapp info, I notice that you’re receiving Application error. Checking further on the backend logs, I’ll follow-up with you privately.
    • _fatalException
    • at process._fatalException (node:internal/process/execution:167:25) {

    • Container hobbeez xxx didn't respond to HTTP pings on port: 8080, failing site start
    • Container hobbeez xxxxfor site hobbeez has exited, failing site start
    • '/opt/startup/startup.sh'

    I see that you’re leveraging Application is using Blessed Image and Nodejs App is using process.env.PORT.
    Azure App Service Linux Nodejs blessed images are setting 8080 to PORT environment variable.

    I see that your node application is timing out at 230 seconds. We recommend adding WEBSITES_CONTAINER_START_TIME_LIMIT:1800 to app configuration in the portal.
    Once this is set please stop and start the application and allow it to start completely.

    Observation: HTTP Logging is currently set to false. I would suggest you, turn on HTTP Logging to fetch more info

    Yes, as indicated in the Azure GitHub wiki page (you referenced), the subfolder works. To isolate it further, you may first start to deploy it to root of the repository.

    Review to see if app.listen() is using a hardcoded port value. If it is, change this to use process.env.PORT.

    Just to clarify, starting from Node 14 LTS, the container doesn't automatically start your app with PM2.
    To start your app with PM2, set the startup command to pm2 start <.js-file-or-PM2-file> --no-daemon