AWS Codebuild“名为 '3.1' 的 dotnet 运行时版本未知。此构建映像具有以下版本:2.2”

izz*_*zyp 7 c# amazon-web-services docker .net-core aws-codebuild

我使用 codepipeline 线来构建和部署 - 从 github 拉取并部署到 Fargate 容器 - 在 codebuild 中构建 dotnet 应用程序时,我遇到了这个错误。相当难住。有谁知道为什么它认为我的应用程序是 dotnet 2.2?

这是一条全新的管道


[Container] 2021/05/20 05:54:31 Waiting for agent ping
[Container] 2021/05/20 05:54:33 Waiting for DOWNLOAD_SOURCE
[Container] 2021/05/20 05:54:34 Phase is DOWNLOAD_SOURCE
[Container] 2021/05/20 05:54:34 CODEBUILD_SRC_DIR=/codebuild/output/src177986340/src
[Container] 2021/05/20 05:54:34 YAML location is /codebuild/output/src177986340/src/config/buildspec.yml
[Container] 2021/05/20 05:54:34 No commands found for phase name: install
[Container] 2021/05/20 05:54:34 Processing environment variables
[Container] 2021/05/20 05:54:35 Selecting 'dotnet' runtime version '3.1' based on manual selections...
[Container] 2021/05/20 05:54:35 Phase complete: DOWNLOAD_SOURCE State: FAILED
[Container] 2021/05/20 05:54:35 Phase context status code: YAML_FILE_ERROR Message: Unknown runtime version named '3.1' of dotnet. This build image has the following versions: 2.2
Run Code Online (Sandbox Code Playgroud)

我的 dockerfile 指向 3.1

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet",  "user-bff.dll"]
Run Code Online (Sandbox Code Playgroud)

我的构建规范指向 3.1

version: 0.2

phases:
  install:
    runtime-versions:
      dotnet: 3.1
  pre_build:
    commands:
      - cd code/
      - echo Logging in to Amazon ECR
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
      - IMAGE_URI="${REPOSITORY_URI}:latest"
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...
      - docker build --tag "$IMAGE_URI"
      - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:latest

  post_build:
    commands:
      - echo Build completed on `date`
      - echo Push the latest Docker Image...
      - docker push "$IMAGE_URI"
      - printf '[{"name":"App","imageUri":"%s"}]' "$IMAGE_URI" > images.json
artifacts:
  files: images.json
Run Code Online (Sandbox Code Playgroud)

我的 dotnet core 应用程序肯定是 3.1

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <RootNamespace>user_bff</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AWSSDK.SimpleSystemsManagement" Version="3.3.106" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="MySql.Data" Version="8.0.17" />
    <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.17" />
    <PackageReference Include="Amazon.Extensions.Configuration.SystemsManager" Version="1.2.0" />
  </ItemGroup>
  
</Project>
Run Code Online (Sandbox Code Playgroud)

Mar*_*cin 7

根据评论。

Amazon Linux 2 x86_64 standard:1.0该问题是由于使用不支持 dotnet 3.1 的旧运行时映像版本引起的。正如AWS 文档中列出的,只有以下版本支持 dotnet 3.1:

  • 亚马逊 Linux 2 x86_64 标准:3.0

  • Amazon Linux 2 AArch64 标准:2.0

  • Ubuntu标准:4.0

  • Ubuntu标准:5.0

因此,解决方案是将镜像版本升级到Amazon Linux 2 x86_64 standard:3.0.