build: optimize Docker build by skipping redundant SPA build
Set SkipSpaBuild environment variable in Dockerfile to prevent MSBuild from rebuilding the frontend during publish, as it is already built in a separate stage. Also disable NuGet audit warnings to reduce build noise.
This commit is contained in:
@@ -11,11 +11,14 @@ FROM mcr.microsoft.com/dotnet/sdk:9.0 AS backend-build
|
|||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY nuget.config ./
|
COPY nuget.config ./
|
||||||
COPY backend.csproj ./
|
COPY backend.csproj ./
|
||||||
|
ENV DOTNET_NUGET_AUDIT=false
|
||||||
RUN dotnet nuget list source
|
RUN dotnet nuget list source
|
||||||
RUN dotnet restore
|
RUN dotnet restore
|
||||||
COPY . .
|
COPY . .
|
||||||
# Copy the frontend build output from the previous stage
|
# Copy the frontend build output from the previous stage
|
||||||
COPY --from=frontend-build /app/dist ./ClientApp/dist
|
COPY --from=frontend-build /app/dist ./ClientApp/dist
|
||||||
|
# Skip the SPA build in MSBuild since it's already built in Stage 1
|
||||||
|
ENV SkipSpaBuild=true
|
||||||
RUN dotnet publish -c Release -o /app/publish
|
RUN dotnet publish -c Release -o /app/publish
|
||||||
|
|
||||||
# Stage 3: Runtime
|
# Stage 3: Runtime
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
<Exec WorkingDirectory="$(SpaRoot)" Command="npm ci" />
|
<Exec WorkingDirectory="$(SpaRoot)" Command="npm ci" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
|
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish" Condition=" '$(SkipSpaBuild)' != 'true' ">
|
||||||
<!-- Build the frontend -->
|
<!-- Build the frontend -->
|
||||||
<Exec WorkingDirectory="$(SpaRoot)" Command="npm ci" Condition=" !Exists('$(SpaRoot)node_modules') " />
|
<Exec WorkingDirectory="$(SpaRoot)" Command="npm ci" Condition=" !Exists('$(SpaRoot)node_modules') " />
|
||||||
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />
|
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />
|
||||||
|
|||||||
Reference in New Issue
Block a user