How can I restore nuget packages hosted in GitHub packages within a Dockerfile?
When I create a NuGet.config file, I need to set a token there (only a readonly token) to access GitHub Packages, even on public repositories :-( . This password will be deleted by GitHub immediately. Is there another way?
Dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS buildWORKDIR /srcCOPY ["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/buildFROM build AS publishRUN dotnet publish "Deploy_O_Mat.API.csproj" -c Release -o /app/publishFROM base AS finalWORKDIR /appCOPY --from=publish /app/publish .ENTRYPOINT ["dotnet", "Deploy_O_Mat.API.dll"]
Action (build - restore works without NuGet.config file):
name: .NET Coreon: 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
Action (Docker image build and deply without NuGet.config - doesn't work):
name: Publish Dockeron: [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}}