From f29ac65d7cc60ca732217c04e25fae3ad3567686 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sun, 13 Sep 2026 17:50:08 +0200 Subject: [PATCH] Refactored API dockerfile --- Dockerfile | 42 +++++++++++++++++++++++++----------------- docker-compose.yml | 2 +- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9481f2e..7003430 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,39 @@ +#FROM mcr.microsoft.com/dotnet/sdk:10.0 AS base +# Base image for running the app FROM mcr.microsoft.com/dotnet/sdk:10.0 AS base WORKDIR /app -EXPOSE 80 -EXPOSE 443 +EXPOSE 8080 +EXPOSE 8081 +# Build stage FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build -ARG TARGETARCH -ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 \ - NUGET_XMLDOC_MODE=skip -WORKDIR /app_source +ARG BUILD_CONFIGURATION=Release +WORKDIR /src -# 1. Copy everything over +# Copy project files for dependency restoration +# Copying all layer csproj files optimizes Docker layer caching +COPY ["PostFundManagement.Api/PostFundManagement.Api.csproj", "PostFundManagement.Api/"] +COPY ["PostFundManagement.Application/PostFundManagement.Application.csproj", "PostFundManagement.Application/"] +COPY ["PostFundManagement.Domain/PostFundManagement.Domain.csproj", "PostFundManagement.Domain/"] +COPY ["PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj", "PostFundManagement.Infrastructure/"] + +# Restore dependencies +RUN dotnet restore "PostFundManagement.Api/PostFundManagement.Api.csproj" + +# Copy the remaining source code COPY . . -# 2. Prevent exit code 155 (global.json version mismatch) -RUN rm -f global.json +# Build the API project +WORKDIR "/src/PostFundManagement.Api" +RUN dotnet build "PostFundManagement.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build -# 3. Restore all projects using the solution context -RUN dotnet restore "PostFundManagement.slnx" - -# 4. Publish directly from the root using the solution context +# Publish stage FROM build AS publish -WORKDIR /app_source -RUN dotnet publish "PostFundManagement.Api/PostFundManagement.Api.csproj" -c Release --no-restore -o /app/publish 1>&2 +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "PostFundManagement.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false -# 5. Final runtime assembly +# Final runtime stage FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true ENTRYPOINT ["dotnet", "PostFundManagement.Api.dll"] diff --git a/docker-compose.yml b/docker-compose.yml index 2557112..a5cf471 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -56,7 +56,7 @@ services: pfm-console: image: pfm-console build: - context: . + context: PostFundManagement.ConsoleUI dockerfile: PostFundManagement.ConsoleUI/Dockerfile container_name: pfm-console ports: -- 2.47.3