Unable to load the service index for source error for a CodeArtifact NuGet feed using Dockerfile

0

Hi! We’re using AWS CodeArtifact for storing our packages and when we try to build a Docker image from our Dockerfile it fails because it's unable to load the source during the restore process.

We have a web API in .Net that we want to deploy using AWS Fargate. This project runs smoothly from Visual Studio 2022 using Docker but we can’t build the image from PowerShell after adding our packages from CodeArtifact.

Our approach to include the credentials in the build is to pass the NuGet.Config stored on the host using Buildkit.

This’s our Dockerfile:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:49151

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src 
COPY . .

WORKDIR /src
COPY ["Src/Presentation/Project.API/Project.API.csproj", "Src/Presentation/Project.API/"]
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
	--mount=type=secret,id=nugetconfig \
	dotnet restore "Src/Presentation/Project.API/Project.API.csproj" \
	--configfile /run/secrets/nugetconfig

COPY . .
WORKDIR "/src/Src/Presentation/Project.API"
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
	dotnet build "Project.API.csproj" -c Release -o /app/build \
	--no-restore

FROM build AS publish
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
	dotnet publish "Project.API.csproj" -c Release -o /app/publish \
	--no-restore

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Project.API.dll"]

Our script in PowerShell:

docker buildx build --secret id=nugetconfig,src=$HOME\AppData\Roaming\NuGet\NuGet.Config -f "Src\Presentation\Project.API\Dockerfile" -t my-dotnet-image .

Output:

#14 [build 6/9] RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages 	--mount=type=secret,id=nugetconfig 	dotnet restore "Src/Presentation/Project.API/Project.API.csproj" 	
--configfile /run/secrets/nugetconfig
#14 1.175   Determining projects to restore...
#14 2.504 /src/Src/Presentation/Project.API/Project.API.csproj : error NU1301: Unable to load the service index for source 
https://domain-123456789012.d.codeartifact.us-east-2.amazonaws.com/nuget/repository/v3/index.json.

What are we missing here? Once we have the Dockerfile working we want to use CDK for deploying the Docker image alongside our infrastructure.

We’re using aws codeartifact login command to authenticate with the service.

Thanks!

profile picture
posta 2 anni fa6486 visualizzazioni
3 Risposte
0

Did you ever get an answer to this? I'm having the same issue. Thanks

con risposta 2 anni fa
0

Having this same issue -- did anyone find a solution?

con risposta 2 anni fa
0

Try to update a source credentials for sourceName

nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key="nuget" value="https://api.nuget.org/v3/index.json" />
    <add key="sourceName" value="https://mydomain-01005003.d.codeartifact.eu-west-1.amazonaws.com/nuget/nugets/v3/index.json" />
  </packageSources>  
</configuration>

dotnet nuget update source sourceName

Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:6.0
WORKDIR /app
COPY ./app .
COPY ./.aws /root/.aws
RUN apt-get update; apt-get install -y  python3-pip curl unzip

RUN curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip \
  && unzip awscliv2.zip \
  && ./aws/install \
  && rm -rf aws awscliv2.zip
  
RUN \    
    CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain mydomain --domain-owner 01005003 --region eu-west-1 --query authorizationToken --output text --profile default` 	 && \
    dotnet nuget update source sourceName -s "https://mydomain-01005003.d.codeartifact.eu-west-1.amazonaws.com/nuget/nugets/v3/index.json"  -u "aws" -p "${CODEARTIFACT_AUTH_TOKEN}" --store-password-in-clear-text --configfile "nuget.config"  

RUN \ 
	  dotnet publish  

con risposta un anno fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande