Refactored API dockerfile #48

Merged
khwezi merged 1 commits from garages3 into main 2026-09-13 17:50:29 +02:00
2 changed files with 26 additions and 18 deletions
+25 -17
View File
@@ -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"]
+1 -1
View File
@@ -56,7 +56,7 @@ services:
pfm-console:
image: pfm-console
build:
context: .
context: PostFundManagement.ConsoleUI
dockerfile: PostFundManagement.ConsoleUI/Dockerfile
container_name: pfm-console
ports: