Files
Ghadir/backend/Dockerfile
alireza ee98cef379 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.
2026-06-03 20:48:09 +03:30

31 lines
844 B
Docker

# Stage 1: Build the frontend
FROM node:20-alpine AS frontend-build
WORKDIR /app
COPY ClientApp/package*.json ./
RUN npm ci
COPY ClientApp/ .
RUN npm run build
# Stage 2: Build the backend
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS backend-build
WORKDIR /src
COPY nuget.config ./
COPY backend.csproj ./
ENV DOTNET_NUGET_AUDIT=false
RUN dotnet nuget list source
RUN dotnet restore
COPY . .
# Copy the frontend build output from the previous stage
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
# Stage 3: Runtime
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
EXPOSE 8080
ENV ASPNETCORE_URLS=http://+:8080
COPY --from=backend-build /app/publish .
ENTRYPOINT ["dotnet", "backend.dll"]