我已经添加了包源到我的github操作,但我仍然得到错误,我的私有包不能在nuget.org
构建docker映像并部署到Azure容器存储库的代码
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 }}
我得到以下错误
/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.
我尝试使用PAT同样的问题
我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"]
我修改了复制nuget的Dokerfile。
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"]
我的问题解决了
您可以尝试在dotnet恢复命令之前添加源代码,像这样-
RUN dotnet nuget add source——username——password
为此,您必须在github中创建具有所需权限的PAT。