3

Note that I am trying to build this locally with docker desktop and not in Azure CI/CD pipeline.

I have started this process using https://github.com/microsoft/artifacts-credprovider which also didn't work and later found out new dotnet restore can do it's job. So, below method was tried after referring to https://github.com/microsoft/artifacts-credprovider/issues/220

Below are the steps I tried.

I have a PAT already generated.

Below is my docker file.

WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["MyProj.csproj", "."]

COPY . .
WORKDIR "/src/."

ARG PAT
ARG FEED_URL

ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
RUN dotnet nuget add source "${FEED_URL}" -u "noneed" -p "${PAT}" --store-password-in-clear-    text --valid-authentication-types basic

RUN dotnet restore "./MyProj.csproj"

RUN dotnet build "MyProj.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "MyProj.csproj" -c Release -o /app/publish /p:UseAppHost=false

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

Then I run docker build as below

docker build . --build-arg FEED_URL=https://pkgs.dev.azure.com/[mycompanydata]/nuget/v3/index.json --build-arg PAT=secret

In the output I can see dotnet nuget add source gets properly build by replacing the parameters. But after some time the error shows

error NU1301: Unable to load the service index for source [my artifact feed url]

Then I tried with a nuget.config file as well as mentioned in https://blog.devops.dev/consuming-private-nuget-feeds-from-a-dockerfile-in-a-secure-and-devops-friendly-manner-b5c90ea90bba?gi=70f359a1d550 Here the only changes was to add the nuget.config file such as;

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
        <add key="opentrips" value="azure-artifact-feed-url"/>
      </packageSources>
    <packageSourceCredentials>
        <openTrips>
        <add key="Username" value="noneed" />
        <add key="ClearTextPassword" value="my-pat" />
        </openTrips>
      </packageSourceCredentials>
</configuration>

Then changed the restore step as;

RUN dotnet restore "./OpenTrips.Services.UserProfile.csproj" --configfile nuget.config --ignore-failed-sources

Then ran the docker build . And this time the same issue but instead of error code NU1301 it shows NU1801. Then tried Nuget connection attempt failed "Unable to load the service index for source" where it says to remove the nuget.config in %appData% same NU1801 error.

Then in some other sources they mentioned to make sure TLS 1.2 is enabled in Edge and it is. Then added dns to Docker Desktop config file like; "dns": [ "8.8.8.8","1.1.1.1" ],

Apart from above I have tried few other things which has worked to some people randomly. Basically without nuget.config I get NU1301 and with nuget.config NU1801. I am completely lost.

user2058413
  • 691
  • 3
  • 10
  • 28
  • Are you 100% sure you don't need to supply a username? I banged my head against a wall with this same problem for a few hours recently (I was trying to restore packages from a private GitLab NuGet feed in a dockerfile script). Even though a personal access token was being used, I still had to provide the correct username. – Steven Frew Mar 08 '23 at 16:40
  • hmm will try with a username also. Didn't provided it because all tutorials says you don't need one. May be that's how Azure works... anyway better try that also. – user2058413 Mar 10 '23 at 04:01

0 Answers0