adaltas / ece-devops-2023-fall

53 stars 12 forks source link

Problem with deploying to microsoft azure while using pnpm as package manager #3

Open BragdonD opened 1 year ago

BragdonD commented 1 year ago

I am encountering a severe difficulty to deploy the web app to microsoft azure, it keeps telling me that dependencies cannot be found...

I try to switch to npm as packet manager but I still get the same problem.

The only option I found is going into the debug console and run npm install manually there and restart the web app. But at this point it is no more CD, since it requires a human interaction...

Does anyone have an idea of how to solve this? Is it a bug or just I am doing something wrong?

Below are my files: package.json:

{
  "name": "ece-userapi",
  "version": "1.0.0",
  "description": "User API web application",
  "main": "src/index.js",
  "scripts": {
    "start": "node src/index.js",
    "dev": "nodemon src/index.js",
    "test": "mocha test/*.test.js"
  },
  "author": "Sergei Kudinov",
  "license": "",
  "dependencies": {
    "body-parser": "^1.20.2",
    "debug": "^4.3.4",
    "express": "^4.17.2",
    "mixme": "^0.5.4",
    "redis": "^3.1.2"
  },
  "devDependencies": {
    "chai": "^4.3.6",
    "chai-http": "^4.3.0",
    "eslint": "^8.9.0",
    "eslint-plugin-mocha": "^10.0.3",
    "mocha": "^9.2.0",
    "nodemon": "^3.0.1"
  },
  "mocha": {
    "timeout": 10000
  }
}

azure.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 - devops-lab4

on:
  workflow_run:
    workflows: ["Node.js CI"]
    types:
      - completed

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: '18.x'

      - name: Install dependencies
        run: |
          npm install

      - name: Zip Artifact for deployment job
        run: |
          zip -r node-app.zip .

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: node-app
          path: node-app.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@v2
        with:
          name: node-app

      - name: Unzip artifact for deployment job
        run: |
          unzip node-app.zip

      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'devops-lab4'
          slot-name: 'Production'
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_93F1C2FB34404DBEB8BBF656F2E9F859 }}
          package: .

CI delivery:

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x, 16.x, 18.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    # Service containers to run with `runner-job`
    services:
      # Label used to access the service container
      redis:
        # Docker Hub image
        image: redis
        # Set health checks to wait until redis has started
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          # Maps port 6379 on service container to the host
          - 6379:6379
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Install Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: Install dependencies
        run: npm install
      - name: Run Test
        run: npm run test
        env:
          REDIS_HOST: localhost
          REDIS_PORT: 6379

PS: Those are the files to run npm since I tried npm as last resort...

gonzaloetjo commented 1 year ago

Hi, thanks for the issue. Does the CI part work correctly? Also, it would be useful to have the logs of the job. You can find it in github actions section, by checking inside of each job.

BragdonD commented 1 year ago

@gonzaloetjo

All the jobs are passing successfully. It fails after the upload to azure platform: Screenshot from 2023-10-03 21-07-32

But now even after recommitting to patch the redis url, my app is working fine at: https://devops-lab4.azurewebsites.net/ which can be test by doing: https://devops-lab4.azurewebsites.net/user/thomas

Plus I am not sure if it is now working due to the previous force npm install

This were the previous error:

Container devops-lab4_0_e5a09cec couldn't be started: Logs = 2023-10-03T18:01:30.305375164Z    _____                               
2023-10-03T18:01:30.305408565Z   /  _  \ __________ _________   ____  
2023-10-03T18:01:30.305415065Z  /  /_\  \\___   /  |  \_  __ \_/ __ \ 
2023-10-03T18:01:30.305420365Z /    |    \/    /|  |  /|  | \/\  ___/ 
2023-10-03T18:01:30.305425465Z \____|__  /_____ \____/ |__|    \___  >
2023-10-03T18:01:30.305430465Z         \/      \/                  \/ 
2023-10-03T18:01:30.305435465Z A P P   S E R V I C E   O N   L I N U X
2023-10-03T18:01:30.305440165Z 
2023-10-03T18:01:30.305444665Z Documentation: http://aka.ms/webapp-linux
2023-10-03T18:01:30.305449566Z NodeJS quickstart: https://aka.ms/node-qs
2023-10-03T18:01:30.305454266Z NodeJS Version : v18.17.1
2023-10-03T18:01:30.305458866Z Note: Any data outside '/home' is not persisted
2023-10-03T18:01:30.305463466Z 
2023-10-03T18:01:31.984242546Z Starting OpenBSD Secure Shell server: sshd.
2023-10-03T18:01:32.768861214Z Starting periodic command scheduler: cron.
2023-10-03T18:01:33.002886924Z Could not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2023-10-03T18:01:33.004427047Z Could not find operation ID in manifest. Generating an operation id...
2023-10-03T18:01:33.004444747Z Build Operation ID: 115cd833-37a8-45c7-a05f-50d58641701d
2023-10-03T18:01:34.552568530Z Environment Variables for Application Insight's Pre-IPA Codeless Configuration exists..
2023-10-03T18:01:34.679373893Z Writing output script to '/opt/startup/startup.sh'
2023-10-03T18:01:34.814528286Z Running #!/bin/sh
2023-10-03T18:01:34.814586687Z 
2023-10-03T18:01:34.814594287Z # Enter the source directory to make sure the script runs where the user expects
2023-10-03T18:01:34.814599387Z cd "/home/site/wwwroot"
2023-10-03T18:01:34.814604287Z 
2023-10-03T18:01:34.814608987Z export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
2023-10-03T18:01:34.814613888Z if [ -z "$PORT" ]; then
2023-10-03T18:01:34.814618688Z      export PORT=8080
2023-10-03T18:01:34.814623588Z fi
2023-10-03T18:01:34.814628088Z 
2023-10-03T18:01:34.814632588Z export NODE_OPTIONS='--require /usr/local/lib/node_modules/applicationinsights/out/Bootstrap/Oryx.js ' $NODE_OPTIONS
2023-10-03T18:01:34.814637288Z npm start
2023-10-03T18:01:51.415248988Z npm info using n******@9.6.4
2023-10-03T18:01:51.416886315Z npm info using n******@v18.17.1
2023-10-03T18:01:51.557683017Z 
2023-10-03T18:01:51.557860020Z > e******@1.0.0 start
2023-10-03T18:01:51.557872920Z > node src/index.js
2023-10-03T18:01:51.557878620Z 
2023-10-03T18:01:52.843617846Z npm http fetch GET 200 https://registry.npmjs.org/npm 1238ms (cache updated)
2023-10-03T18:01:53.025390019Z npm http fetch GET 200 https://registry.npmjs.org/npm 1496ms (cache updated)
2023-10-03T18:01:53.217676963Z node:internal/modules/cjs/loader:1080
2023-10-03T18:01:53.217710064Z   throw err;
2023-10-03T18:01:53.217716764Z   ^
2023-10-03T18:01:53.217721764Z 
2023-10-03T18:01:53.217726464Z Error: Cannot find module 'depd'
2023-10-03T18:01:53.217891967Z Require stack:
2023-10-03T18:01:53.217899767Z - /home/site/wwwroot/node_modules/body-parser/index.js
2023-10-03T18:01:53.217904067Z - /home/site/wwwroot/node_modules/express/lib/express.js
2023-10-03T18:01:53.217908867Z - /home/site/wwwroot/node_modules/express/index.js
2023-10-03T18:01:53.217913667Z - /home/site/wwwroot/src/index.js
2023-10-03T18:01:53.217918467Z     at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
2023-10-03T18:01:53.217922667Z     at Module._load (node:internal/modules/cjs/loader:922:27)
2023-10-03T18:01:53.217927367Z     at Module.require (node:internal/modules/cjs/loader:1143:19)
2023-10-03T18:01:53.217932067Z     at Module.patchedRequire [as require] (/usr/local/lib/node_modules/applicationinsights/node_modules/diagnostic-channel/dist/src/patchRequire.js:14:46)
2023-10-03T18:01:53.217936768Z     at require (node:internal/modules/cjs/helpers:121:18)
2023-10-03T18:01:53.217941968Z     at Object. (/home/site/wwwroot/node_modules/body-parser/index.js:14:17)
2023-10-03T18:01:53.217946968Z     at Module._compile (node:internal/modules/cjs/loader:1256:14)
2023-10-03T18:01:53.217951268Z     at Module._extensions..js (node:internal/modules/cjs/loader:1310:1
=======[LONG LOG TRUNCATED BY DETECTOR]======
alamenai commented 10 months ago

I have the same issue:

image

Though the pipeline is passed but it failed to be installed on the Azure App Service.

image

This is my pipeline configuration:


# Node.js with React Pipeline
# Build a Node.js project that uses React using Azure DevOps.

trigger:
  - dev

pool:
  vmImage: ubuntu-latest

stages:
  - stage: Install
    displayName: "Install"
    jobs:
      - job: InstallJob
        displayName: "Install Node.js and Dependencies"
        steps:
          - task: NodeTool@0
            inputs:
              versionSpec: "^20.x"
            displayName: "Install Node.js"
          - script: |
              npm install -g pnpm
              pnpm install
            displayName: "Install Dependencies"

  - stage: Tests
    displayName: "Run Unit and Component Tests"
    jobs:
      - job: TestsJob
        displayName: "Run Unit and Component Tests"
        steps:
          - script: |
              npm install -g pnpm
              pnpm install
              pnpm test
              pnpm cypress-run-component
            displayName: "Run Unit and Component Tests"

  - stage: Build
    displayName: "Build Application"
    jobs:
      - job: BuildJob
        displayName: "Build Application"
        steps:
          - script: |
              npm install -g pnpm
              pnpm install
              pnpm build
            displayName: "Build Application"

  - stage: ArchiveAndPublish
    displayName: "Archive and Publish Artifacts"
    jobs:
      - job: ArchiveAndPublishJob
        displayName: "Archive Build Artifacts and Publish"
        steps:
          - task: ArchiveFiles@2
            inputs:
              rootFolderOrFile: "."
              includeRootFolder: false
              archiveType: "zip"
              archiveFile: "$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip"
              replaceExistingArchive: true
          - task: PublishBuildArtifacts@1
            inputs:
              PathtoPublish: "$(Build.ArtifactStagingDirectory)"
              ArtifactName: "drop"
              publishLocation: "Container"