1

如何恢复 Dockerfile 中托管在 GitHub 包中的 nuget 包?

当我创建 NuGet.config 文件时,我需要在那里设置一个令牌(只有一个只读令牌)来访问 GitHub 包,即使在公共存储库上也是如此 :-( 。这个密码将被 GitHub 立即删除。还有其他方法吗?

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src

COPY ["Deploy_O_Mat.API/Deploy_O_Mat.API.csproj", "Deploy_O_Mat.API/"]
COPY ["NuGet.config", "Deploy_O_Mat.API/"]

RUN dotnet restore "Deploy_O_Mat.API/Deploy_O_Mat.API.csproj" 
COPY . .
WORKDIR "/src/Deploy_O_Mat.API"

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

FROM build AS publish
RUN dotnet publish "Deploy_O_Mat.API.csproj" -c Release -o /app/publish

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

操作(构建 - 无需 NuGet.config 文件即可恢复):

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.100
        source-url: https://nuget.pkg.github.com/Marcel-B/index.json
      env:
        NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
    - name: Install dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Test
      run: dotnet test --no-restore --verbosity normal

操作(没有 NuGet.config 的 Docker 映像构建和部署 - 不起作用):

name: Publish Docker
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Publish to Registry
      uses: elgohr/Publish-Docker-Github-Action@master
      with:
        name: millegalb/deploy-o-mat
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}
        source-url: https://nuget.pkg.github.com/Marcel-B/index.json
      env:
        NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
4

0 回答 0