fix(dockerfile): 修正Docker构建流程和文件路径
Some checks failed
Build and Deploy / build (push) Successful in 19s
Build and Deploy / docker (push) Successful in 38m56s
Build and Deploy / deploy (push) Failing after 3m40s

- 删除多余的目录拷贝,简化COPY指令
- 统一项目文件和配置文件的拷贝路径
- 调整工作目录,避免重复嵌套路径
- 优化dotnet restore和build步骤,确保路径正确
- 保持publish阶段项目路径一致,确保发布成功
This commit is contained in:
movingsam 2026-02-27 22:06:29 +08:00
parent 8d2eeea982
commit ca2c0d69a2

View File

@ -7,21 +7,24 @@ EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
# Copy Directory.Packages.props for centralized version management
# Copy project files
COPY ["Directory.Packages.props", "./"]
COPY ["src/Directory.Packages.props", "src/"]
COPY ["src/YarpGateway/YarpGateway.csproj", "src/YarpGateway/"]
COPY ["src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Core/Fengling.ServiceDiscovery.Core.csproj", "src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Core/"]
COPY ["src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Kubernetes/Fengling.ServiceDiscovery.Kubernetes.csproj", "src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Kubernetes/"]
COPY ["src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Static/Fengling.ServiceDiscovery.Static.csproj", "src/Fengling.ServiceDiscovery/Fengling.ServiceDiscovery.Static/"]
RUN dotnet restore "src/YarpGateway/YarpGateway.csproj"
COPY ["YarpGateway.csproj", "./"]
COPY ["NuGet.Config", "./"]
# Restore dependencies
RUN dotnet restore "YarpGateway.csproj"
# Copy all source code
COPY . .
WORKDIR "/src/src/YarpGateway"
RUN dotnet build "./YarpGateway.csproj" -c $BUILD_CONFIGURATION -o /app/build
WORKDIR "/src"
RUN dotnet build "YarpGateway.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./YarpGateway.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
RUN dotnet publish "YarpGateway.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app