Quantcast
Channel: Cannot connect to azure nuget feed when creating a container - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Cannot connect to azure nuget feed when creating a container

$
0
0

I have been trying to get docker to pull from a private nuget feed which is hosted within Azure Devops, but I consistently get a 401 unauthorized error. I have looked a numerous other answers and resources, but all of which have not helped. My dockerfile script is the following

# escape=`FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-envWORKDIR /srcEXPOSE 80EXPOSE 443ARG FEED_URLARG FEED_ACCESSTOKEN# Install powershell via dotnetRUN dotnet tool install --global PowerShell --version 7.0.0SHELL ["pwsh", "-command"]## CURRENT ERROR - "-AddNetfx" - NOT CONSIDERED AN ARGUMENT, ALTHOUGH IT IS (CAN BE SEEN IN THE SCRIPT ENTRY) ### Install credprovider which is required for accessing private artifact repositoryRUN Invoke-WebRequest https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1 -OutFile installcredprovider.ps1; `    .\installcredprovider.ps1 -AddNetfx; `    del installcredprovider.ps1################################################################################################################## Copy csproj and sln filesCOPY ["Abstractions/*.csproj", "./Abstractions/"]COPY ["AdminServicesPortal/*.csproj", "./AdminServicesPortal/"]COPY ["DataInterface/*.csproj", "./DataInterface/"]COPY ["Resources/*.csproj", "./Resources/"]# Need to copy over docker NuGet packagesCOPY "AdminServicesPortal/nuget.config" "AdminServicesPortal/"# Enable session token cacheENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED trueENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS `"{`"endpointCredentials`": [{`"endpoint`":`"https://pkgs.dev.azure.com/ORG/PROJECT/_packaging/FEED/nuget/v3/index.json`", `"username`":`"USER`", `"password`":`"PAT`"}]}"RUN echo $Env:VSS_NUGET_EXTERNAL_FEED_ENDPOINTS# Restore dependencies before copying everything else overRUN dotnet restore "AdminServicesPortal/Portal.csproj"# Copy the rest of the files required for a build# Note that this is separate, because we should stop building# the container if we do not have all required dependenciesCOPY Abstractions/. ./Abstractions/COPY AdminServicesPortal/. ./AdminServicesPortal/COPY DataInterface/. ./DataInterface/COPY Resources/. ./Resources/WORKDIR "/src/AdminServicesPortal"RUN dotnet build "Portal.csproj" -c Release -o /app/build# Publish applicationFROM build-env AS publishRUN dotnet publish "Portal.csproj" -c Release -o /app/publish# Runtime environment for containerFROM build-env AS finalWORKDIR /appCOPY --from=build /app/publish .ENTRYPOINT ["dotnet", "MPX.AdminServices.Portal.dll"]

The error I get from Visual Studio is the following

2>  Failed to restore C:\src\Resources\Resources.csproj (in 2.99 sec).2>C:\Program Files\dotnet\sdk\3.1.404\NuGet.targets(128,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/{ORG}/{PROJECT}/_packaging/{FEED}/nuget/v3/index.json. [C:\src\AdminServicesPortal\Portal.csproj]2>C:\Program Files\dotnet\sdk\3.1.404\NuGet.targets(128,5): error :   Response status code does not indicate success: 401 (Unauthorized). [C:\src\AdminServicesPortal\Portal.csproj]

From what I can tell in the link below; my dockerfile script should work

https://github.com/dotnet/dotnet-docker/blob/master/documentation/scenarios/nuget-credentials.md#using-the-azure-artifact-credential-provider

To ensure it wasn't an issue with the PAT of the user not having access, I gave them access to everything across the whole entire organisation. Any help would be greatly appreciated!

Note #1: My current suspicion is that there are some additional parameters I might need to pass, since the private nuget feed is for a project rather than the entire organisation?

Note #2: I ran the following PowerShell command (https://docs.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops#package-and-publish-the-module) which worked fine, so I am even more confused to why my dockerfile script does not work.

nuget sources Add -Name "PowershellModules" -Source "https://pkgs.dev.azure.com/<org_name>/_packaging/<feed_name>/nuget/v3/index.json" -username "<user_name>" -password "<personal_access_token(PAT)>"

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images