Azure Web应用程序部署github操作,部署失败

gstyhher  于 2022-12-14  发布在  Git
关注(0)|答案(1)|浏览(224)

尝试使用GitHub操作将React应用部署到Azure Web应用,将在单个资源组(默认为asgithub-RG)下动态创建资源,并使用服务主体帐户作为asgithub-RG资源组的贡献者

  • 我遵循的步骤

1.使用CLI登录
1.根据PR详细信息和名称创建应用服务计划
1.根据PR详细信息和名称创建Web应用程序

  1. npm ci和npm建筑
    1.上载对象
    1.下载人工因素
    1.部署到Azure
  • Github行动 *
name: Deploy Pull Request to Azure Web App
on:
  pull_request: 
    branches: [ "develop" ]
    types: [opened, synchronize, closed]
  workflow_dispatch:

env:
  BRANCH_NAME: ${{ github.event.pull_request.head.ref }} # get branch name from pull request
  PR_NUMBER: ${{ github.event.pull_request.number }}
  AZURE_WEBAPP_NAME: ${{ github.event.pull_request.head.repo.name }}-${{ github.event.pull_request.head.ref }} # add GTCRM- prefix to branch name
  AZURE_WEBAPP_PACKAGE_PATH: '.'      # set this to the path to your web app project, defaults to the repository root
  NODE_VERSION: '18-lts'                # set this to the node version to use
  RESOURCE_GROUP: 'asgithub-RG'
permissions:
  contents: read
  pull-requests: write
  actions: write

jobs:
  pre-build:
    if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.pull_request.draft == false 
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3

    - name: Login via Azure CLI
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    
    # Create a new resource group to hold the deployment slot
    - name: Create App service plan
      uses: Azure/cli@v1
      with: 
        inlineScript: |
          az appservice plan create --name ${{ env.AZURE_WEBAPP_NAME }}-${{ env.PR_NUMBER }}-plan --resource-group ${{ env.RESOURCE_GROUP }} --sku B1 --is-linux

    # Set the deployment slot's app setting to point to the staging slot
    - name: Set app setting
      uses: Azure/cli@v1
      with: 
        inlineScript: |
          az webapp create --resource-group ${{ env.RESOURCE_GROUP }} --plan ${{ env.AZURE_WEBAPP_NAME }}-${{ env.PR_NUMBER }}-plan --name ${{ env.AZURE_WEBAPP_NAME }}-${{ env.PR_NUMBER }} --runtime "NODE:${{ env.NODE_VERSION }}" --output table
          

  build:
    runs-on: ubuntu-latest
    needs: pre-build
    steps:
      - uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18.4.0
          cache: 'npm'

      # Cache node_modules
      - name: Cache node_modules
        uses: actions/cache@v3.1.0-beta.2
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}

       # Install dependencies
      - name: Install Dependencies
        if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: |
          npm install
          npm run ci --if-present
          

      # tar the build folder
      - name: Zip Package
        run: |
          zip -r node-app.zip .

      # Upload the zip file to the deployment slot
      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v3
        with:
          name: node-app
          path: node-app.zip

# Deploy the zip file to the deployment slot
  deploy:
    permissions:
      contents: read
      pull-requests: write
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Development'

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

#    #Unpack the artifact
#    - name: Unzip artifact
#      run: unzip node-app.zip

    - name: Login via Azure CLI
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}

    - name: 'Deploy to Azure WebApp'
      id: deploy-to-webapp
      uses: Azure/webapps-deploy@v2.2.5
      with:
        app-name: ${{ env.AZURE_WEBAPP_NAME }}-${{ env.PR_NUMBER }}
        package: node-app.zip

**问题1:***我从一个GitHub存储库执行所有7个步骤,在GitHub中执行正常,而在Azure Web应用中部署失败 *
日志

2022-12-10T10:54:48.581727176Z: \[INFO\]     \____\_

2022-12-10T10:54:48.581757676Z: \[INFO\]    /  \_  \\ \_________\_ \________\_   \___\_

2022-12-10T10:54:48.581762376Z: \[INFO\]   /  /_\\  \\_\_\_   /  |  \_  \_\_ \_/ \_\_ \\

2022-12-10T10:54:48.581765977Z: \[INFO\]  /    |    /    /|  |  /|  | /\\  \__\_/

2022-12-10T10:54:48.581769477Z: \[INFO\]  \____|__  /_\___\_ \____/ |__|    \__\_  \>

2022-12-10T10:54:48.581773177Z: \[INFO\]          /      /                  /

2022-12-10T10:54:48.581776477Z: \[INFO\]  A P P   S E R V I C E   O N   L I N U X

2022-12-10T10:54:48.581779777Z: \[INFO\]

2022-12-10T10:54:48.581782777Z: \[INFO\]  Documentation: http://aka.ms/webapp-linux

2022-12-10T10:54:48.581785977Z: \[INFO\]  NodeJS quickstart: https://aka.ms/node-qs

2022-12-10T10:54:48.581788977Z: \[INFO\]  NodeJS Version : v18.12.0

2022-12-10T10:54:48.581792277Z: \[INFO\]  Note: Any data outside '/home' is not persisted

2022-12-10T10:54:48.581795477Z: \[INFO\]

2022-12-10T10:54:49.216708277Z: \[INFO\]  Starting OpenBSD Secure Shell server: sshd.

2022-12-10T10:54:49.446358441Z: \[INFO\]  Starting periodic command scheduler: cron.

2022-12-10T10:54:49.598691233Z: \[INFO\]  Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'

2022-12-10T10:54:49.606104102Z: \[INFO\]  Could not find operation ID in manifest. Generating an operation id...

2022-12-10T10:54:49.606179104Z: \[INFO\]  Build Operation ID: 5aceb568-51a8-4ee6-9f9d-835f90d52e7a

2022-12-10T10:54:50.732891663Z: \[INFO\]  Environment Variables for Application Insight's IPA Codeless Configuration exists..

2022-12-10T10:54:50.895699980Z: \[INFO\]  Writing output script to '/opt/startup/startup.sh'

2022-12-10T10:54:51.128069973Z: \[INFO\]  Running #!/bin/sh

2022-12-10T10:54:51.128097374Z: \[INFO\]

2022-12-10T10:54:51.128102674Z: \[INFO\]  # Enter the source directory to make sure the script runs where the user expects

2022-12-10T10:54:51.128106774Z: \[INFO\]  cd "/home/site/wwwroot"

2022-12-10T10:54:51.128110674Z: \[INFO\]

2022-12-10T10:54:51.128114474Z: \[INFO\]  export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH

2022-12-10T10:54:51.128118574Z: \[INFO\]  if \[ -z "$PORT" \]; then

2022-12-10T10:54:51.128122474Z: \[INFO\]        export PORT=8080

2022-12-10T10:54:51.128126674Z: \[INFO\]  fi

2022-12-10T10:54:51.128130374Z: \[INFO\]

2022-12-10T10:54:51.215962971Z: \[INFO\]  npm start

2022-12-10T10:54:53.801869544Z: \[ERROR\]  npm info it worked if it ends with ok

2022-12-10T10:54:53.803157767Z: \[ERROR\]  npm info using npm@6.14.15

2022-12-10T10:54:53.812627941Z: \[ERROR\]  npm info using node@v18.12.0

2022-12-10T10:54:55.390189353Z: \[ERROR\]  npm info lifecycle my-app@0.1.0\~prestart: my-app@0.1.0

2022-12-10T10:54:55.449869038Z: \[ERROR\]  npm info lifecycle my-app@0.1.0\~start: my-app@0.1.0

2022-12-10T10:54:55.481953221Z: \[INFO\]

2022-12-10T10:54:55.482000722Z: \[INFO\]  \> my-app@0.1.0 start /home/site/wwwroot

2022-12-10T10:54:55.482007922Z: \[INFO\]  \> react-scripts start

2022-12-10T10:54:55.482023422Z: \[INFO\]

2022-12-10T10:54:57.161168776Z: \[ERROR\]  node:internal/modules/cjs/loader:998

2022-12-10T10:54:57.161201276Z: \[ERROR\]    throw err;

2022-12-10T10:54:57.161206076Z: \[ERROR\]    ^

2022-12-10T10:54:57.161209576Z: \[ERROR\]

2022-12-10T10:54:57.161212977Z: \[ERROR\]  Error: Cannot find module '../scripts/start'

2022-12-10T10:54:57.161216377Z: \[ERROR\]  Require stack:

2022-12-10T10:54:57.161220077Z: \[ERROR\]  - /home/site/wwwroot/node_modules/.bin/react-scripts

2022-12-10T10:54:57.161223477Z: \[ERROR\]      at Module.\_resolveFilename (node:internal/modules/cjs/loader:995:15)

2022-12-10T10:54:57.161227477Z: \[ERROR\]      at Function.resolve (node:internal/modules/cjs/helpers:109:19)

2022-12-10T10:54:57.161235677Z: \[ERROR\]      at Object.\<anonymous\> (/home/site/wwwroot/node_modules/.bin/react-scripts:31:23)

2022-12-10T10:54:57.161240177Z: \[ERROR\]      at Module.\_compile (node:internal/modules/cjs/loader:1159:14)

2022-12-10T10:54:57.161243577Z: \[ERROR\]      at Module.\_extensions..js (node:internal/modules/cjs/loader:1213:10)

2022-12-10T10:54:57.161246977Z: \[ERROR\]      at Module.load (node:internal/modules/cjs/loader:1037:32)

2022-12-10T10:54:57.161250277Z: \[ERROR\]      at Module.\_load (node:internal/modules/cjs/loader:878:12)

2022-12-10T10:54:57.161253777Z: \[ERROR\]      at Function.executeUserEntryPoint \[as runMain\] (node:internal/modules/run_main:81:12)

2022-12-10T10:54:57.161257177Z: \[ERROR\]      at node:internal/main/run_main_module:23:47 {

2022-12-10T10:54:57.161260578Z: \[ERROR\]    code: 'MODULE_NOT_FOUND',

2022-12-10T10:54:57.161263878Z: \[ERROR\]    requireStack: \[ '/home/site/wwwroot/node_modules/.bin/react-scripts' \]

2022-12-10T10:54:57.161267278Z: \[ERROR\]  }

2022-12-10T10:54:57.171300295Z: \[ERROR\]

2022-12-10T10:54:57.171322096Z: \[ERROR\]  Node.js v18.12.0

2022-12-10T10:54:57.240925304Z: \[ERROR\]  npm info lifecycle my-app@0.1.0\~start: Failed to exec start script

2022-12-10T10:54:57.262303367Z: \[ERROR\]  npm ERR! code ELIFECYCLE

2022-12-10T10:54:57.270736750Z: \[ERROR\]  npm ERR! errno 1

2022-12-10T10:54:57.331226561Z: \[ERROR\]  npm ERR! my-app@0.1.0 start: `react-scripts start`

2022-12-10T10:54:57.331244961Z: \[ERROR\]  npm ERR! Exit status 1

2022-12-10T10:54:57.331249462Z: \[ERROR\]  npm ERR!

2022-12-10T10:54:57.331261062Z: \[ERROR\]  npm ERR! Failed at the my-app@0.1.0 start script.

2022-12-10T10:54:57.331264962Z: \[ERROR\]  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

2022-12-10T10:54:57.343324323Z: \[ERROR\]  npm timing npm Completed in 4353ms

2022-12-10T10:54:57.343341624Z: \[ERROR\]

2022-12-10T10:54:57.343346224Z: \[ERROR\]  npm ERR! A complete log of this run can be found in:

2022-12-10T10:54:57.343350024Z: \[ERROR\]  npm ERR!     /root/.npm/\_logs/2022-12-10T10_54_57_310Z-debug.log

**问题2:***只是为了尝试创建react应用程序,我将使用相同的github操作和凭据,它在步骤2登录后失败 *
日志

Starting script execution via docker image mcr.microsoft.com/azure-cli:2.42.0
ERROR: (ResourceNotFound) The Resource 'Microsoft.Web/serverFarms/azwebappci-feature' under resource group 'azwebapp' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Code: ResourceNotFound
Message: The Resource 'Microsoft.Web/serverFarms/azwebappci-feature' under resource group 'azwebapp' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Error: Error: az cli script failed.
cleaning up container...
MICROSOFT_AZURE_CLI_1670667478073_CONTAINER

Error: az cli script failed.

期望==〉

1.脚本应与所有存储库兼容以创建动态资源
1.为什么部署会失败
作为一种解决方案,我认为应用程序服务容器部署或静态网站上的主机构建文件夹。

k10s72fa

k10s72fa1#

根据错误消息,问题似乎是找不到清单文件:
在“/home/site/wwwroot/oryx-manifest.toml”中找不到生成清单文件
我将执行以下操作来隔离问题:
1.查找文件在本地计算机上的位置
1.请确保已将其签入到源代码管理
1.查找引用文件的位置并检查该位置是否可用

相关问题