Github 操作将 zip 部署到应用程序服务,但 wwwroot 为空

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

我有一个 Nest.js api,我正在尝试通过 github 操作将其部署到我的 Azure Web 服务。我以前曾工作过。但现在还没有部署

我的动作文件看起来像这样

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

on:
  push:
    branches:
      - dev
    # paths-ignore:
    #   - 'README.md'
    #   - '.husky'
    #   - '.github/**'
    #   - '**/*.csv'
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/[email protected]

      - name: Set up Node.js version
        uses: actions/[email protected]
        with:
          node-version: '20.4.0'

      # - name: npm install, build, and test
      #   run: |
      #     npm install -g @nestjs/cli
      #     npm install
      #     npm run build

      - name: Zip artifact for deployment
        run: |
          zip -r release.zip . \
          -x "*.git/*" \
          -x ".vscode/*" \
          -x "src/*" \
          -x "test/*" \
          -x "README.md" \
          -x ".env" \
          -x ".env.example" \
          -x ".env.local" \
          -x ".gitignore" \
          -x ".prettierrc" \
          -x "tsconfig.build.json" \
          -x "tsconfig.json" \
          -x ".github/*"

      - name: Upload artifact for deployment job
        uses: actions/[email protected]
        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/[email protected]
        with:
          name: node-app

      # - name: Unzip artifact for deployment
      #   run: unzip release.zip

      - name: Login to Azure
        uses: Azure/[email protected]
        with:
          client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_... }}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_... }}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_... }}

      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: Azure/[email protected]
        with:
          app-name: 'dev-api'
          slot-name: 'production'
          package: 'release.zip'
          # type: 'zip'
          # clean: true
          # restart: true

      - name: Logout
        run: |
          az logout

我的部署文件如下所示

[config]
SCM_DO_BUILD_DURING_DEPLOYMENT=true

我的 web.config 看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<!--
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:
    https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->
<configuration>
    <system.webServer>
        <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
        <webSocket enabled="false" />
        <handlers>
            <!-- Indicates that the dist/main.js file is a node.js site to be handled by the iisnode module -->
            <add name="iisnode" path="dist/main.js" verb="*" modules="iisnode" />
        </handlers>
        <rewrite>
            <rules>
                <!-- Do not interfere with requests for node-inspector debugging -->
                <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^dist/main.js\/debug[\/]?" />
                </rule>

                <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
                <rule name="StaticContent">
                    <action type="Rewrite" url="public{REQUEST_URI}" />
                </rule>

                <!-- All other URLs are mapped to the node.js site entry point -->
                <rule name="DynamicContent">
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
                    </conditions>
                    <action type="Rewrite" url="dist/main.js" />
                </rule>
            </rules>
        </rewrite>

        <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
        <security>
            <requestFiltering>
                <hiddenSegments>
                    <remove segment="bin" />
                </hiddenSegments>
            </requestFiltering>
        </security>

        <!-- Make sure error responses are left untouched -->
        <httpErrors existingResponse="PassThrough" />
        <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled
     See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
        <!--<iisnode watchedFiles="web.config;*.js"/>-->
    </system.webServer>
</configuration>

我还在环境变量中将

WEBSITE_RUN_FROM_PACKAGE
设置为 true 或 1。但它只是不会部署我的 Github 操作,说它有效。

我通过以下消息成功部署:

Package deployment using OneDeploy initiated.
{
  id: '7e616a05-6826-47c8-9bf7-bb7f3b1b6ad7',
  status: 4,
  status_text: '',
  author_email: 'N/A',
  author: 'N/A',
  deployer: 'OneDeploy',
  message: 'OneDeploy',
  progress: '',
  received_time: '2024-04-17T12:04:00.9090509Z',
  start_time: '2024-04-17T12:04:02.2551014Z',
  end_time: '2024-04-17T12:04:03.2578212Z',
  last_success_end_time: '2024-04-17T12:04:03.2578212Z',
  complete: true,
  active: true,
  is_temp: false,
  is_readonly: true,
  url: 'https://dev-api.scm.azurewebsites.net/api/deployments/7e616a05-6826-47c8-9bf7-bb7f3b1b6ad7',
  log_url: 'https://dev-api.scm.azurewebsites.net/api/deployments/7e616a05-6826-47c8-9bf7-bb7f3b1b6ad7/log',
  site_name: 'dev-api',
  build_summary: { errors: [], warnings: [] }
}
Deploy logs can be viewed at https://dev-api.scm.azurewebsites.net/api/deployments/7e616a05-6826-47c8-9bf7-bb7f3b1b6ad7/log
Successfully deployed web package to App Service.
App Service Application URL: https://dev-api.azurewebsites.net
node.js azure github azure-web-app-service github-actions
1个回答
0
投票

正如我所见,您排除了多个要压缩的文件。交叉检查,您没有排除所有文件。

这对我有用。

我正在使用发布配置文件

我的目录:

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 - nesjswebapp

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/[email protected]

      - name: Set up Node.js version
        uses: actions/[email protected]
        with:
          node-version: '20.x'

      #- 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 -r release.zip . \
          -x "src/*" \
          -x "test/*" \
          -x ".gitignore" \
          -x ".prettierrc" \
          -x "tsconfig.build.json" \
          -x "tsconfig.json" \
          -x ".github/*"

      - name: Upload artifact for deployment job
        uses: actions/[email protected]
        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/[email protected]
        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/[email protected]
        with:
          app-name: 'nesjswebapp'
          slot-name: 'Production'
          package: release.zip
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_12717BD1B6BD4CCB9EE716xxxxxxx }}

OUTPUT

如您所见,除了排除的文件之外,所有文件都已上传。您可以在 scm url 末尾添加

newui
来检查 Linux Web 应用程序的文件。

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