From 8a5d55fc2af40f1b9e91c7535a11b790787746ea Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Sat, 6 Jun 2026 00:16:21 +0200 Subject: [PATCH] Refactored docker files to overcome the individually targeted project files --- src/LiteCharmsSecurity.Admin.Api/Dockerfile | 23 ++++++++++++------- src/LiteCharmsSecurity.Admin/Dockerfile | 22 +++++++++++------- .../Dockerfile | 19 +++++++++++---- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/LiteCharmsSecurity.Admin.Api/Dockerfile b/src/LiteCharmsSecurity.Admin.Api/Dockerfile index 1a78e80..1727109 100644 --- a/src/LiteCharmsSecurity.Admin.Api/Dockerfile +++ b/src/LiteCharmsSecurity.Admin.Api/Dockerfile @@ -6,16 +6,23 @@ EXPOSE 443 FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0 AS build ARG TARGETARCH WORKDIR /src -COPY ["src/LiteCharmsSecurity.Admin.Api/LiteCharmsSecurity.Admin.Api.csproj", "src/LiteCharmsSecurity.Admin.Api/"] -COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.Shared/LiteCharmsSecurity.Admin.EntityFramework.Shared.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.Shared/"] -COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.SqlServer/LiteCharmsSecurity.Admin.EntityFramework.SqlServer.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.SqlServer/"] -COPY ["src/LiteCharmsSecurity.Shared/LiteCharmsSecurity.Shared.csproj", "src/LiteCharmsSecurity.Shared/"] -COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.PostgreSQL/LiteCharmsSecurity.Admin.EntityFramework.PostgreSQL.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.PostgreSQL/"] -RUN dotnet restore "src/LiteCharmsSecurity.Admin.Api/LiteCharmsSecurity.Admin.Api.csproj" +# 1. Copy the master solution file and structural project footprints. +# Wildcard matching reads everything cleanly into the build cache layer. +COPY LiteCharmsSecurity.sln ./ +COPY src/*/*.csproj ./ +COPY src/ ./src/ +# Clean up duplicate files dropped into the root context by the wildcard copy +RUN rm -f *.csproj +# 2. Restore the entire solution using the global solution profile +RUN dotnet restore "LiteCharmsSecurity.sln" + +# 3. Bring in the rest of your implementation logic code files COPY . . -WORKDIR "src/LiteCharmsSecurity.Admin.Api" + +# 4. Target your specific Admin API project path for Compilation & Publishing +WORKDIR "/src/src/LiteCharmsSecurity.Admin.Api" RUN dotnet build "LiteCharmsSecurity.Admin.Api.csproj" -c Release -o /app/build FROM build AS publish @@ -25,4 +32,4 @@ FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true -ENTRYPOINT ["dotnet", "LiteCharmsSecurity.Admin.Api.dll"] +ENTRYPOINT ["dotnet", "LiteCharmsSecurity.Admin.Api.dll"] \ No newline at end of file diff --git a/src/LiteCharmsSecurity.Admin/Dockerfile b/src/LiteCharmsSecurity.Admin/Dockerfile index cbfc2cc..dbb35f5 100644 --- a/src/LiteCharmsSecurity.Admin/Dockerfile +++ b/src/LiteCharmsSecurity.Admin/Dockerfile @@ -11,22 +11,28 @@ ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 \ NUGET_XMLDOC_MODE=skip WORKDIR /src +# Bring over Node & NPM runtimes for administrative UI asset packaging steps COPY --from=node /usr/local/bin/node /usr/local/bin/node COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \ && npm install -g npm@latest \ && node --version && npm --version -COPY ["src/LiteCharmsSecurity.Admin/LiteCharmsSecurity.Admin.csproj", "src/LiteCharmsSecurity.Admin/"] -COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.PostgreSQL/LiteCharmsSecurity.Admin.EntityFramework.PostgreSQL.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.PostgreSQL/"] -COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.Shared/LiteCharmsSecurity.Admin.EntityFramework.Shared.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.Shared/"] -COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.SqlServer/LiteCharmsSecurity.Admin.EntityFramework.SqlServer.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.SqlServer/"] -COPY ["src/LiteCharmsSecurity.Shared/LiteCharmsSecurity.Shared.csproj", "src/LiteCharmsSecurity.Shared/"] +# 1. Copy the master solution file and project structures for build cache retention +COPY LiteCharmsSecurity.sln ./ +COPY src/*/*.csproj ./ +COPY src/ ./src/ +# Clean up duplicate files dropped into the root context by the wildcard copy +RUN rm -f *.csproj -RUN dotnet restore "src/LiteCharmsSecurity.Admin/LiteCharmsSecurity.Admin.csproj" +# 2. Restore the entire solution cleanly via public NuGet paths +RUN dotnet restore "LiteCharmsSecurity.sln" +# 3. Pull in the remaining implementation files COPY . . -WORKDIR "src/LiteCharmsSecurity.Admin" + +# 4. Navigate into your specific Admin UI directory context for assembly compilation +WORKDIR "/src/src/LiteCharmsSecurity.Admin" RUN dotnet build "LiteCharmsSecurity.Admin.csproj" -c Release -o /app/build FROM build AS publish @@ -36,4 +42,4 @@ FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true -ENTRYPOINT ["dotnet", "LiteCharmsSecurity.Admin.dll"] +ENTRYPOINT ["dotnet", "LiteCharmsSecurity.Admin.dll"] \ No newline at end of file diff --git a/src/LiteCharmsSecurity.STS.Identity/Dockerfile b/src/LiteCharmsSecurity.STS.Identity/Dockerfile index 8c9f1bd..95d4e6a 100644 --- a/src/LiteCharmsSecurity.STS.Identity/Dockerfile +++ b/src/LiteCharmsSecurity.STS.Identity/Dockerfile @@ -6,14 +6,23 @@ EXPOSE 443 FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS build ARG TARGETARCH WORKDIR /src -COPY ["src/LiteCharmsSecurity.STS.Identity/LiteCharmsSecurity.STS.Identity.csproj", "src/LiteCharmsSecurity.STS.Identity/"] -COPY ["src/LiteCharmsSecurity.Admin.EntityFramework.Shared/LiteCharmsSecurity.Admin.EntityFramework.Shared.csproj", "src/LiteCharmsSecurity.Admin.EntityFramework.Shared/"] -COPY ["src/LiteCharmsSecurity.Shared/LiteCharmsSecurity.Shared.csproj", "src/LiteCharmsSecurity.Shared/"] -RUN dotnet restore "src/LiteCharmsSecurity.STS.Identity/LiteCharmsSecurity.STS.Identity.csproj" +# 1. Copy the master solution file and the entire project directory structures +# but ONLY copy the .csproj files. This keeps the Docker layer cache completely optimization-friendly. +COPY LiteCharmsSecurity.sln ./ +COPY src/*/*.csproj ./ +COPY src/ ./src/ +# Clean up duplicate files dropped into the root context by the wildcard copy +RUN rm -f *.csproj +# 2. Restore the entire solution cleanly using the global workspace cache +RUN dotnet restore "LiteCharmsSecurity.sln" + +# 3. Bring in the rest of your implementation code files now that the packages are fully cached COPY . . -WORKDIR "src/LiteCharmsSecurity.STS.Identity" + +# 4. Target your specific project execution path for Compilation & Publishing +WORKDIR "/src/src/LiteCharmsSecurity.STS.Identity" RUN dotnet build "LiteCharmsSecurity.STS.Identity.csproj" -c Release -o /app/build FROM build AS publish