使用 GitHub 操作将 ASP.NET Core 应用程序部署到 AWS Beanstalk

时间:2021-03-11 00:30:09

标签: amazon-web-services asp.net-core github yaml amazon-elastic-beanstalk

我正在尝试使用 GitHub Actions 和 AWS Beanstalk (mac) 为我的 ASP.NET Core 应用程序构建 CD 管道。我已经按如下方式配置了 YML 文件:

name: Deploy AWS

on:
  workflow_dispatch:

jobs:
  build:

    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v2
   
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.301
    
    - name: Install dependencies
      run: dotnet restore
    
    - name: Build
      run: dotnet build --configuration Release --no-restore
    
    - name: Test
      run: dotnet test --no-restore --verbosity normal

    - name: Publish
      run: dotnet publish -c Release -o '${{ github.workspace }}/out'
  
    - name: Zip Package
      run: |
        cd ${{ github.workspace }}/out 
        zip -r ${{ github.workspace }}/out.zip *
    - name: Deploy to EB
      uses: einaregilsson/beanstalk-deploy@v13
      with:
        aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        application_name: demovideo
        environment_name: demovideo-dev
        region: us-east-2
        version_label: ${{ github.run_id }}
        version_description: ${{ github.sha }}
        deployment_package: ${{ github.workspace }}/out.zip

但是我在 github 上收到一个关于版本失败的错误。这是当前日志:

23:53:45 ERROR: Error occurred during build: Command hooks failed
23:53:46 ERROR: [Instance: i-094e9d57f5e05c25c ConfigSet: Infra-WriteRuntimeConfig, Infra-EmbeddedPreBuild, Hook-PreAppDeploy, Infra-EmbeddedPostBuild, Hook-EnactAppDeploy, Hook-PostAppDeploy] Command failed on instance. Return code: 1 Output: null.
23:53:46 INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
23:53:46 ERROR: Unsuccessful command execution on instance id(s) 'i-094e9d57f5e05c25c'. Aborting the operation.
23:53:46 ERROR: Failed to deploy application.
23:53:46 ERROR: During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version.
23:53:56 ERROR: Deployment failed! Current State: Version: v20210310030618, Health: Red, Health Status: Degraded
Error: Deployment failed: Error: Deployment failed! Current State: Version: v20210310030618, Health: Red, Health Status: Degraded

1 个答案:

答案 0 :(得分:0)

通常你需要添加Procfile来指定你正在使用的应用程序

例如:

web: dotnet exec ./Application.dll --urls http://0.0.0.0:5000/

对于发布命令,请尝试以下命令:

dotnet publish -c Release -o '${{ github.workspace }}/out' -r linux-x64 --self-contained false