使用 Docker 的 artifacts-credprovider 和 VSS_NUGET_EXTERNAL_FEED_ENDPOINTS

Rom*_*nok 3 nuget azure-devops

也许您可以帮助我使用私有 NuGet feed 进行身份验证,我已经花了一天时间研究不同的解决方案并注意到这个存储库,但我仍然在努力完成它。

我使用下面具有不同变体的 Dockerfile,但每次都未经授权

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"]
Run Code Online (Sandbox Code Playgroud)

我尝试使用 ARG 和 ENV 设置 VSS_NUGET_EXTERNAL_FEED_ENDPOINTS,但每次都会收到此错误:

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

目前我们的项目中没有专用的NuGet.Config,也许是这个问题的情况?我需要创建它并将此私人存储库添加到其中吗?

谢谢。

sta*_*SFT 5

Nuget.config不是必需的,但您需要在恢复包时指定源,因为只有默认源(https://api.nuget.org/v3/index.json

Dockerfile(我修改了环境变量):

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"]
Run Code Online (Sandbox Code Playgroud)