artifacts-credprovider and VSS_NUGET_EXTERNAL_FEED_ENDPOINTS with Docker

删除回忆录丶 提交于 2020-05-28 04:40:46

问题


Maybe you could help me with authentication with private NuGet feed, I already spend a day for different solutions and notice this repo, but I'm still struggling to make it done.

I'm using below Dockerfile with different variations, but I'm getting Unauthorized each time

FROM microsoft/dotnet:2.2-sdk AS build
ARG VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
WORKDIR /api

#ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS={"endpointCredentials":[{"endpoint":"https://name.pkgs.visualstudio.com/_packaging/Feed/nuget/v3/index.json","username":"PAT","password":"PAT"}]}


# Auth with private feed
RUN wget https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh \
   && chmod +x installcredprovider.sh \
   && ./installcredprovider.sh


# Copy csproj and restore as distinct layers
COPY ["App.csproj", "./"]
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS runtime
WORKDIR /api
COPY --from=build /api/out ./
EXPOSE 4444
ENTRYPOINT ["dotnet", "App.dll"]

I tried with ARGs and ENVs to set the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS, but each time I'm getting this error:

error NU1101: Unable to find package Package.Name. No packages exist with this id in source(s): nuget.org

Currently we don't have dedicated NuGet.Config in the project, maybe it's the case of this issue? That I need to create it and add this private repo to it?

Thank you.


回答1:


Nuget.config is not required, but you need to specify source during restoring package, because, there is just default source (https://api.nuget.org/v3/index.json)

Dockerfile (I modified environment variable):

FROM microsoft/dotnet:2.2-sdk AS build
#ARG VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
WORKDIR /api

ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS '{"endpointCredentials":[{"endpoint":"https://pkgs.dev.azure.com/org/_packaging/feedname/nuget/v3/index.json","username":"name","password":"your personal access token"}]}'


# Auth with private feed
RUN wget https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh \
   && chmod +x installcredprovider.sh \
   && ./installcredprovider.sh


# Copy csproj and restore as distinct layers
COPY ["App.csproj", "./"]
RUN dotnet restore -s "https://pkgs.dev.azure.com/org/_packaging/feedname/nuget/v3/index.json" -s "https://api.nuget.org/v3/index.json"

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS runtime
WORKDIR /api
COPY --from=build /api/out ./
EXPOSE 4444
ENTRYPOINT ["dotnet", "App.dll"]



回答2:


Currently we don't have dedicated NuGet.Config in the project, maybe it's the case of this issue? That I need to create it and add this private repo to it?

Yes, you should create a nuget.config file in the same folder as your Dockerfile that is configured to use the private repo.

Then copy the nuget.config file in the dockerfile, like:

...
COPY . .
COPY NuGet.Config ./
...

And specify your private feed and Credentials in the nuget.config:

<?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="BredasVSTS" value="https://xxxx.pkgs.visualstudio.com/_packaging/BredasVSTS/nuget/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <BredasVSTS>
      <add key="Username" value="emailhere" />      
      <add key="ClearTextPassword" value="PAT here" />
    </BredasVSTS>
  </packageSourceCredentials>
</configuration>

Check the document Azure DevOps Private Nuget Feed with Docker Build(Step 4) and Docker use private NuGet Feed for some more details.

Hope this helps.



来源:https://stackoverflow.com/questions/57362453/artifacts-credprovider-and-vss-nuget-external-feed-endpoints-with-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!