1

I have private Nuget feed from Azure Artifact that I want to use inside docker, but I am getting the following error:

/usr/share/dotnet/sdk/5.0.402/NuGet.targets(131,5): error : Unable to load the service index for source http://test/DefaultCollection/test/_packaging/company/nuget/v3/index.json. [/src/App1/App1.csproj] /usr/share/dotnet/sdk/5.0.402/NuGet.targets(131,5): error : NTLM authentication is not possible with default credentials on this platform. [/src/App1/App1.csproj] The command '/bin/sh -c dotnet restore "App1/App1.csproj" --configfile nuget.config' returned a non-zero code: 1 ##[error]The command '/bin/sh -c dotnet restore "App1/App1h.csproj" --configfile nuget.config' returned a non-zero code: 1 ##[error]/usr/bin/docker failed with return code: 1

I tried few thing, but I am getting same issues. Do you have any suggestion how to fix this?

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

#############
## Stage 1 ##
#############
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build


#Personal Access Token to Authenticate To Artifactory
ARG FEED_URL
ARG PAT  

RUN apt-get update && apt-get install -y --no-install-recommends gss-ntlmssp

#ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
#ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
#ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS {\"endpointCredentials\": [{\"endpoint\":\"${FEED_URL}\", \"username\":\"App1\", \"password\":\"${PAT}\"}]}
#
#
#RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
#

WORKDIR /src

## Copy the applications .csproj
COPY ["App1/App1.csproj", "App1/"]
COPY ["App2/App2.csproj", "App2/"] 
COPY nuget.config ./

## Restore packages
#RUN dotnet restore "App1.csproj" -s "${FEED_URL}" -s "https://api.nuget.org/v3/index.json"
#RUN sed -i "s|</configuration>|<packageSourceCredentials><Company><add key=\"Username\" value=\"Company\" /><add key=\"ClearTextPassword\" value=\"${PAT}\" /></Company></packageSourceCredentials></configuration>|" nuget.config

#RUN dotnet restore . -s "${FEED_URL}" -s "https://api.nuget.org/v3/index.json" "App1.csproj"

RUN dotnet restore "App1.csproj"  --configfile nuget.config

#RUN dotnet restore \
    #-s https://api.nuget.org/v3/index.json \
    #-s ${FEED_URL} \ 
    #"App1.csproj" 

## Copy everything else
COPY . .
WORKDIR "/src/App1"
## Build the app
RUN dotnet build "App1.csproj" -c Release -o /app/build

## Run dotnet test setting the output on the /coverage folder
## ...

## Create the code coverage file in sonarqube format using the cobertura file generated from the dotnet test command
## ...

## Publish the app
FROM build AS publish
RUN dotnet publish "App1.csproj" -c Release -o /app/publish


#############
## Stage 2 ##
#############
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "App1.dll"]

My task for building docker container:

   - task: Docker@0
     displayName: 'Build an image: App1'
     inputs:
       containerregistrytype: 'Azure Container Registry'
       azureSubscription: 'azure connection'
       azureContainerRegistry: '{"loginServer":"test.azurecr.io", "id" : "/subscriptions/be40d993-b17f-4873-a724-11111111111/resourceGroups/aks-test/providers/Microsoft.ContainerRegistry/registries/test"}'
       action: 'Build an image'
       dockerFile: 'App1/App1/Dockerfile'
       buildArguments: |
         PAT=$(PAT)
         FEED_URL=$(FEED_URL) 
       defaultContext: false
       imageName: '$(Build.Repository.Name):$(Build.BuildId)'

I am using private agents on Azure DevOps Server.

cashmere
  • 885
  • 3
  • 12
  • 37

0 Answers0