izzyp
izzyp

Reputation: 173

AWS Codebuild "Unknown runtime version named '3.1' of dotnet. This build image has the following versions: 2.2"

Im using codepipeline line to build and deploy - pulling from github and deploying to fargate containers - upon bulding the dotnet application in codebuild I come across this error. Pretty stumped. Does anyone have any ideas why it thinks my app is dotnet 2.2?

This is a brand new pipeline


[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

My dockerfile points to 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"]

My buildspec points to 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

and my dotnet core app is definitely 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>

Upvotes: 7

Views: 4439

Answers (2)

Marcin
Marcin

Reputation: 238507

Based on the comments.

The issue was caused by using old runtime image version Amazon Linux 2 x86_64 standard:1.0 which does not support dotnet 3.1. As listed in the AWS docs only the following versions support dotnet 3.1:

  • Amazon Linux 2 x86_64 standard:3.0

  • Amazon Linux 2 AArch64 standard:2.0

  • Ubuntu standard:4.0

  • Ubuntu standard:5.0

Thus, the solution was to upgrade the image version to Amazon Linux 2 x86_64 standard:3.0.

Upvotes: 7

izzyp
izzyp

Reputation: 173

Moving to Amazon Linux 2 x86_64 standard:3.0 from Amazon Linux 2 x86_64 standard:1.0 fixed this!

Upvotes: 0

Related Questions