使用 Github 存储库时如何更改 Azure 构建目录

问题描述 投票:0回答:1

我想使用 GitHub 存储库部署 NodeJS API,问题是我要部署的 API 目录位于 ./anti-scraping-backend。 Azure似乎没有提供更改目录的简单方法。我的yaml文件如下:

name: Build and deploy Node.js app to Azure Web App - anti-scraping-api

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js version
        uses: actions/setup-node@v3
        with:
          node-version: '20.x'

      - name: Change directory to anti-scraping-backend
        run: cd ./anti-scraping-backend 

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

      - name: Zip artifact for deployment
        run: zip release.zip ./* -r

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v3
        with:
          name: node-app
          path: release.zip

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    permissions:
      id-token: write #This is required for requesting the JWT

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v3
        with:
          name: node-app

      - name: Unzip artifact for deployment
        run: unzip release.zip
      
      - name: Login to Azure
        uses: azure/login@v1
        with:
          client-id: ${{ I DON'T THINK I CAN SHOW IT HERE }}
          tenant-id: ${{ I DON'T THINK I CAN SHOW IT HERE  }}
          subscription-id: ${{ I DON'T THINK I CAN SHOW IT HERE }}

      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'anti-scraping-api'
          slot-name: 'Production'
          package: ./anti-scraping-backend

Azure 日志说它正在尝试在根上构建,所以它当然失败了。

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/runner/work/Scraping-Anti-Scraping-Techniques/Scraping-Anti-Scraping-Techniques/package.json
npm ERR! errno -2
npm ERR! enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/home/runner/work/Scraping-Anti-Scraping-Techniques/Scraping-Anti-Scraping-Techniques/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

我尝试将包更改为

package: ./anti-scraping-backend
还尝试运行步骤命令
run: cd ./anti-scraping-backend 

node.js git azure github
1个回答
0
投票

如果您想使用 GitHub 操作运行部署特定目录,则需要使用

working-directory

我的目录:

Root/
|   
| - backend/
| - react_app/
| | - public/
| | - src/
| | - ...
| | - package.json

main_directorygitapp.yml
:

# 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 - directorygitapp

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js version
        uses: actions/setup-node@v3
        with:
          node-version: '20.x'

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

      - name: Zip artifact for deployment
        run: zip release.zip ./* -r

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

      - name: Unzip artifact for deployment
        run: unzip release.zip
      
      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'directorygitapp'
          slot-name: 'Production'
          package: .
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_xxxxxxxxxxxxxxxxxx }}

OUTPUT

© www.soinside.com 2019 - 2024. All rights reserved.