Merge pull request 'Refactored API dockerfile' (#48) from garages3 into main
Reviewed-on: #48
This commit was merged in pull request #48.
This commit is contained in:
+25
-17
@@ -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
|
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
EXPOSE 80
|
EXPOSE 8080
|
||||||
EXPOSE 443
|
EXPOSE 8081
|
||||||
|
|
||||||
|
# Build stage
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||||
ARG TARGETARCH
|
ARG BUILD_CONFIGURATION=Release
|
||||||
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 \
|
WORKDIR /src
|
||||||
NUGET_XMLDOC_MODE=skip
|
|
||||||
WORKDIR /app_source
|
|
||||||
|
|
||||||
# 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 . .
|
COPY . .
|
||||||
|
|
||||||
# 2. Prevent exit code 155 (global.json version mismatch)
|
# Build the API project
|
||||||
RUN rm -f global.json
|
WORKDIR "/src/PostFundManagement.Api"
|
||||||
|
RUN dotnet build "PostFundManagement.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
# 3. Restore all projects using the solution context
|
# Publish stage
|
||||||
RUN dotnet restore "PostFundManagement.slnx"
|
|
||||||
|
|
||||||
# 4. Publish directly from the root using the solution context
|
|
||||||
FROM build AS publish
|
FROM build AS publish
|
||||||
WORKDIR /app_source
|
ARG BUILD_CONFIGURATION=Release
|
||||||
RUN dotnet publish "PostFundManagement.Api/PostFundManagement.Api.csproj" -c Release --no-restore -o /app/publish 1>&2
|
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
|
FROM base AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=publish /app/publish .
|
COPY --from=publish /app/publish .
|
||||||
ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
|
|
||||||
ENTRYPOINT ["dotnet", "PostFundManagement.Api.dll"]
|
ENTRYPOINT ["dotnet", "PostFundManagement.Api.dll"]
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ services:
|
|||||||
pfm-console:
|
pfm-console:
|
||||||
image: pfm-console
|
image: pfm-console
|
||||||
build:
|
build:
|
||||||
context: .
|
context: PostFundManagement.ConsoleUI
|
||||||
dockerfile: PostFundManagement.ConsoleUI/Dockerfile
|
dockerfile: PostFundManagement.ConsoleUI/Dockerfile
|
||||||
container_name: pfm-console
|
container_name: pfm-console
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
Reference in New Issue
Block a user