gpt4 book ai didi

azure - 使用 Github Actions 将多个项目部署到 Azure

转载 作者:行者123 更新时间:2023-12-03 06:12:16 26 4
gpt4 key购买 nike

我遇到了与 this one 相同的问题。我已经修改了自动生成的 yml 文件,以便在构建步骤中包含此文件:

之前:

- name: Build with dotnet
run: dotnet build --configuration Release

- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp

之后:

  - name: Build with dotnet
run: dotnet build {project folder}/project_name.csproj --configuration Release

- name: dotnet publish
run: dotnet publish {project folder}/project_name.csproj -c Release -o ${{env.DOTNET_ROOT}}/myapp

部署成功,构建和部署操作均已完成且没有任何错误。但是,我的 Web 应用程序未加载,显示 403 错误,并且当我检查 wwwroot 文件夹时,它是空的,并且没有部署任何文件。

以下是部署的相关代码:

deploy:
runs-on: windows-latest
needs: build
environment:
name: 'dev'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: .net-app

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'myappname'
slot-name: 'dev'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_****** }}
package: .

我错过了什么?

最佳答案

dotnetpublish 不会将您的应用发布到 Azure 应用服务。它只会准备一个用于部署的包。

要将应用部署到 Azure 应用服务,您需要使用此任务 azure/webapps-deploy

查看 an example workflow :

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Build and deploy ASP.Net Core app to an Azure Web App

env:
AZURE_WEBAPP_NAME: MY_WEBAPP_NAME # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '5' # set this to the .NET Core version to use

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Set up dependency caching for faster builds
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-

- name: Build with dotnet
run: dotnet build --configuration Release

- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp

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: .net-app

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

如果你想部署多个项目,你可以使用矩阵来完成,如下所示

jobs:
build-and-deploy:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- app: 'web-app-name-1'
artifact: 'artifact-path-1'
profileName: 'profile-1'
- app: 'web-app-name-2'
artifact: 'artifact-path-2'
profileName: 'profile-2'
- app: 'web-app-name-3'
artifact: 'artifact-path-3'
profileName: 'profile-3'

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: ${{ matrix.artifact }}

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@azure/webapps-deploy@v2
with:
app-name: ${{ matrix.app }}
publish-profile: ${{ secrets[matrix.profileName] }}
package: ${{ matrix.artifact }}

关于azure - 使用 Github Actions 将多个项目部署到 Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76625311/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com