将 ASP.NET 核心部署到 AWS Elastic Beanstalk,必须包含带有'.runtimeconfig.json'后缀错误的文件



我正在尝试部署ASP。NET Core(dotnet版本5.0(到带有Bitbucket管道的AWS Elastic Beanstalk,但部署步骤导致错误:实例部署:您的源捆绑包只有一个。NET核心应用程序。您必须包含一个后缀为".runtimeconfig.json"的文件。部署失败

弹性Beanstalk设置:

  • 平台:。NET核心
  • 平台分支:。NET Core在64位Amazon Linux 2上运行
  • 平台版本:2.1.0(推荐(

(使用#some_text更改敏感数据(

弹性Beanstalk日志:

2020-12-04 02:04:16 UTC+0100 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.
2020-12-04 02:04:16 UTC+0100 ERROR Failed to deploy application.
2020-12-04 02:04:16 UTC+0100 ERROR Unsuccessful command execution on instance id(s) '#id'. Aborting the operation.
2020-12-04 02:04:16 UTC+0100 INFO  Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2020-12-04 02:04:16 UTC+0100 ERROR [Instance: #id] Command failed on instance. Return code: 1 Output: Engine execution has encountered an error..
2020-12-04 02:04:13 UTC+0100 ERROR Instance deployment: Your source bundle has a single .NET Core application. You must include a file with a '.runtimeconfig.json' suffix. The deployment failed.
2020-12-04 02:04:13 UTC+0100 INFO  Instance deployment found a runtime-dependent .NET Core application in your source bundle.
2020-12-04 02:04:13 UTC+0100 ERROR Instance deployment failed. For details, see 'eb-engine.log'.
2020-12-04 02:04:10 UTC+0100 INFO  Deploying new version to instance(s).

ebengine.log:

2020/12/04 01:04:13.566295 [INFO] Executing instruction: StageApplication
2020/12/04 01:04:13.569996 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2020/12/04 01:04:13.570035 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2020/12/04 01:04:13.688429 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2020/12/04 01:04:13.689890 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2020/12/04 01:04:13.689914 [INFO] The dir .platform/hooks/prebuild/ does not exist in the application. Skipping this step...
2020/12/04 01:04:13.689920 [INFO] Executing instruction: CheckProcfileForDotNetCoreApplication
2020/12/04 01:04:13.689925 [INFO] checking application and updating executable file permissions...
2020/12/04 01:04:13.690272 [INFO] found runtime-dependent application...
2020/12/04 01:04:13.690294 [INFO] checking Procfile...
2020/12/04 01:04:13.690317 [ERROR] An error occurred during execution of command [app-deploy] - [CheckProcfileForDotNetCoreApplication]. Stop running the command. Error: there is no .runtimeconfig.json file for your single application. Please provide a valid application

Bitbucket管道:(缩短-仅相关步骤(

image: mcr.microsoft.com/dotnet/sdk:5.0
pipelines:
test:
- step:
name: "Create release of Api project"
script:
- export API_PROJ=path/to/my/project.csproj
- export CONFIG=Release
- dotnet publish -c $CONFIG $API_PROJ -o api
artifacts:
- api/**
- step:
name: "Zip"
image: atlassian/default-image:2
script:
- zip api.zip api/*
artifacts:
- api.zip
- step:
name: "Deploy to Elastic Beanstalk"
script:
- pipe: atlassian/aws-elasticbeanstalk-deploy:0.6.7
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
DB_CONNECTION_STRING: $DB_CONNECTION_STRING
AWS_DEFAULT_REGION: "eu-west-2"
APPLICATION_NAME: "#the_app"
ENVIRONMENT_NAME: $BITBUCKET_BRANCH
ZIP_FILE: "api.zip"
S3_BUCKET: '#S3_BUCKET'

从日志中,AWS似乎找不到后缀为".runtimeconfig.json"的文件,但它在zip文件中:应用程序发布版本(目录打印屏幕(

到目前为止,我已经尝试从Bitbucket管道和我的笔记本电脑部署应用程序。我甚至尝试过部署自包含构建,但在同一个错误中解决了这个问题。我的一位同事成功地使用Visual Studio Elastic Beanstalk部署工具部署了它,但这并不能解决我们的问题,只是暂时的解决方案。我试过添加Procfile,但没有效果。

我还没有找到弹性豆茎的配置吗?任何想法和建议都将不胜感激。

这是因为EB在根目录上查找runtimeconfig.json。如果你提取你的zip,你会有这样的目录结构-

randomName.zip > random name created by EB
api
-runtimeconfig.json
-

虽然它看起来应该像

{randomName.zip} > random name created by EB
-runtimeconfig.json

因此,将构建规范工件从api/**更改为./**应该是可行的。以下是我在Github上的工作示例-https://gist.github.com/vickyrathee/06df1416d8bc5f2543c56e4d3b912e96

我没能让它以"管道"的方式工作,但我使用了dotnet eb工具。管道现在看起来是这样的:

image: mcr.microsoft.com/dotnet/sdk:5.0
pipelines:
test:
- step:
name: "Create a release of Api project"
script:
- export API_PROJ=path/to/my/project.csproj
- export CONFIG=Release
- dotnet publish -c $CONFIG $API_PROJ -o api
artifacts:
- api/**
- step:
name: "Deploy"
script:
- apt update
- apt install -y zip
- dotnet tool install -g Amazon.ElasticBeanstalk.Tools
- export PATH="$PATH:/root/.dotnet/tools"
- dotnet eb deploy-environment
--aws-access-key-id $AWS_ACCESS_KEY_ID
--aws-secret-key $AWS_SECRET_ACCESS_KEY
-pl path/to/my/
-f net5.0
--region eu-west-2
-app #the_app
-env $BITBUCKET_BRANCH
--solution-stack '64bit Amazon Linux 2 v2.1.0 running .NET Core'
--instance-profile #my_role
--instance-type t2.micro

如果这对来到这里的任何人都有帮助,那么显然AWS部署教程已经过时了。您所需要做的就是将site.zip文件(本质上是dotnet publish的压缩输出(上传到EB,然后它就会运行。我不需要带有部署清单的外部包装器。

我在Dotnet 6上,正在使用Github操作。我刚刚启动了自己的管道。对我来说,问题是我的脚本压缩了文件夹,而不仅仅是内容。例如:

邮编:

  • 部署(文件夹(
    • api.dll(文件(
    • settings.json(文件(
    • 等等

但EB只清理了一个包含文件的zip,而没有根文件夹。例如:

邮编:

  • api.dll(文件(
  • settings.json(文件(
  • 等等

原因是EB支持同时部署多个应用程序。但是,你需要添加每个应用程序运行方式的配置文件等。但当你只为一个应用程序进行简单部署时,你只需提供内容,它就会启动。

我的Github操作最终看起来是这样的:

name: API
on:
workflow_dispatch:
push:
branches:
- master
paths:
- 'src/Api/**'
env:
WEBAPP_PACKAGE_PATH: ./publish
CONFIGURATION: Release
DOTNET_CORE_VERSION: 6.0.x
WORKING_DIRECTORY: ./src/Api
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
- name: Restore
run: dotnet restore "${{ env.WORKING_DIRECTORY }}"
- name: Build
run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore
- name: Test
run: dotnet test "${{ env.WORKING_DIRECTORY }}" --no-build
- name: Publish
run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.WEBAPP_PACKAGE_PATH }}"
- name: Generate deployment package
run: cd ${{ env.WEBAPP_PACKAGE_PATH }}; zip -r ../deployment.zip .; cd ..
- name: Deploy to EB
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_KEY }}
application_name: SlideshowbobApi
environment_name: SlideshowbobApi-dev
version_label: 1.0.0.${{ github.run_number }}
region: eu-north-1
deployment_package: deployment.zip

这应该很容易更改您的构建过程/测试过程。

最新更新