0

I have added package source to my github actions but I still get error that my private packages cannot be found in nuget.org

My code for building a docker image and deploying to Azure Container Repository

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout to the branch
        uses: actions/checkout@v2

      - name: Set up Docker Buildx 
        uses: docker/setup-buildx-action@v1

      - name: Log in to container registry
        uses: docker/login-action@v1
        with:
          registry: rekruteqacr.azurecr.io
          username: ${{ secrets.STATISTICSWEBAPI_REGISTRY_USERNAME }}
          password: ${{ secrets.STATISTICSWEBAPI_REGISTRY_PASSWORD }}
          
      - run: |
          dotnet nuget add source "https://nuget.pkg.github.com/msmith/index.json" --name "githubpackages" --username "msmith@gmail.com" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text
          docker build . -t statqacr.azurecr.io/statisticswebapi:${{ github.sha }}
          docker push statqacr.azurecr.io/statisticswebapi:${{ github.sha }}

I get the following error

/src/Statistics.WebApi/Statistics.WebApi.csproj : error NU1101: Unable to find package Afrojptech.NetCore.Helpers. No packages exist with this id in source(s): nuget.org
/src/Statistics.WebApi/Rekruteq.Statistics.WebApi.csproj : error NU1101: Unable to find package Statistics.DataModels. No packages exist with this id in source(s): nuget.org
  Failed to restore /src/Statistics.WebApi/Statistics.WebApi.csproj (in 1.3 sec).
The command '/bin/sh -c dotnet restore "Statistics.WebApi/Statistics.WebApi.csproj"' returned a non-zero code: 1
Error: Process completed with exit code 1.

I tried using PAT same problem

My dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 7107

ENV ASPNETCORE_URLS=http://+:7107

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["Statistics.BLL/Statistics.BLL.csproj", "Statistics.WebApi/"]
COPY ["Statistics.Worker/Statistics.Worker.csproj", "Statistics.WebApi/"]
COPY ["Statistics.WebApi/Statistics.WebApi.csproj", "Statistics.WebApi/"]

RUN dotnet restore "Statistics.WebApi/Statistics.WebApi.csproj"
COPY . .
WORKDIR "/src/Statistics.WebApi"
RUN dotnet build ".Statistics.WebApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Statistics.WebApi.csproj" -c Release -o /app/publish /p:UseAppHost=false

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

2 Answers2

0

I modified the Dokerfile copying the nuget.config file into the build like so.

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 7107

ENV ASPNETCORE_URLS=http://+:7107

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["nuget.config", "Statistics.WebApi/"]
COPY ["Statistics.BLL/Statistics.BLL.csproj", "Statistics.WebApi/"]
COPY ["Statistics.Worker/Statistics.Worker.csproj", "Statistics.WebApi/"]
COPY ["Statistics.WebApi/Statistics.WebApi.csproj", "Statistics.WebApi/"]

RUN dotnet restore "Statistics.WebApi/Statistics.WebApi.csproj"
COPY . .
WORKDIR "/src/Statistics.WebApi"
RUN dotnet build ".Statistics.WebApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Statistics.WebApi.csproj" -c Release -o /app/publish /p:UseAppHost=false

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

That solved my problem

0

You can try adding source just before your dotnet restore command like this -

RUN dotnet nuget add source --username --password <github_PAT> --store-password-in-clear-text --name github "https://nuget.pkg.github.com/<organisation-name/your-name>/index.json"

for this, you have to create a PAT in github with required rights.