【问题标题】:How to Deploy from github to Azure App Service如何从 github 部署到 Azure 应用服务
【发布时间】:2020-07-30 11:30:40
【问题描述】:

我正在尝试将基本的 Angular 9 应用程序部署到 azure 应用服务。

到目前为止我做了什么。

  • 我已经创建了一个 Web 应用实例

  • 然后我按照启动网站的建议去了部署中心,并通过部署中心连接了我的 github 存储库

  • 它将此工作流 yml 文件添加到我的存储库中,我确实注释掉了 npm run test,因为它是 angular 的默认应用程序,无需浪费时间运行应用程序
# 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 - someapp

on:
  push:
    branches:
      - master

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@master

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

    - name: npm install, build, and test
      run: |
        npm install
        npm run build -prod --if-present
        # npm run test --if-present
    - name: 'Deploy to Azure Web App'
      uses: azure/webapps-deploy@v1
      with:
        app-name: 'someapp'
        slot-name: 'production'
        publish-profile: ${{ secrets.AzureAppService_PublishProfile}}
        package: .
  • 在运行管道后,它会在初始获取时给出一个 503 错误代码的应用程序错误。

我尝试通过 ssh 进入服务器查看文件结构,但要么我无法登录,要么如果我登录了它,几秒钟后我就会退出。

有谁知道我是否错过了部署到 azure 或文件结构所需的某些步骤? 我尝试搜索更多最新的教程或问题,但大多数似乎都过时了。

【问题讨论】:

    标签: angular azure github deployment http-status-code-503


    【解决方案1】:

    您可以通过两种方式做到这一点,一种是使用 Github Actions ,您可以在其中使用操作构建自己的管道。由于这似乎是一个有角度的应用程序,请关注我的blog

    第二种方法是使用 Azure Devops 项目,创建项目并添加自己的自定义代码。

    关于实际错误:我怀疑你的文件是否部署到appservice,你可以使用Kudu检查是否存在正确的文件。

    【讨论】:

      【解决方案2】:

      应用服务是静态网站的错误服务。我遇到了这些文档,它们可以帮助我快速设置网站。正如 Sajeetharan 建议的那样,您必须使用 devops 管道才能获得与部署应用服务中的部署中心相同的效果。

      1. 创建“存储帐户”并进入静态网站,并启用静态网站

      2. 在 Azure Devops 中创建项目单击管道并创建一个新项目。在配置 setp 中选择 Node.js with Angular。我将我的链接与 github 存储库。这将为您选择的任何部署分支添加一个 azure 管道 yml。

      您将需要生成一个工件,因此您需要向您的 yml 添加一个额外的任务。例如

      - task: PublishBuildArtifacts@1
        inputs:
          pathToPublish: dist/Nebulous
          artifactName: drop
      

      你的完整 yml 应该是这样的

      trigger:
      - master
      
      pool:
        vmImage: 'ubuntu-latest'
      
      steps:
      - task: NodeTool@0
        inputs:
          versionSpec: '10.x'
        displayName: 'Install Node.js'
      
      - script: |
          npm install -g @angular/cli
          npm install
          ng build --prod
        displayName: 'npm install and build'
      
      - task: PublishBuildArtifacts@1
        inputs:
          pathToPublish: dist/Nebulous
          artifactName: drop
      

      useful link about adding artifact

      在此之后,我们准备将工件推送到我们的存储帐户

      从 azure Devops 转到发布

      1. 在工件卡下单击添加,并将我们刚刚创建的管道添加到此。如果您想要持续部署,请单击角落的照明灯并启用它。

      2. 现在单击阶段 1 下显示“1 个工作,0 个任务”的链接,然后单击代理工作行上的加号以添加新任务。搜索 AzureBlob 文件副本。

      来源:选择您创建的管道并将其导航到您在之前步骤中创建的工件文件夹

      目标类型是 Azure Blob

      选择您之前创建的存储帐户名称

      容器名称 = $web

      现在您可以手动启动或推送到您的分支,它将部署到 azure。

      https://docs.microsoft.com/en-us/azure/javascript/tutorial-vscode-static-website-node-01?tabs=bash

      【讨论】:

        猜你喜欢
        • 2017-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-07
        • 1970-01-01
        • 1970-01-01
        • 2023-03-27
        • 2021-10-16
        相关资源
        最近更新 更多