47 lines
1.3 KiB
Docker
47 lines
1.3 KiB
Docker
|
|
# Production Dockerfile for WorkClub.Api
|
||
|
|
# Multi-stage build optimized for minimal image size
|
||
|
|
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||
|
|
|
||
|
|
WORKDIR /src
|
||
|
|
|
||
|
|
# Layer caching: Copy solution and project files first
|
||
|
|
COPY WorkClub.slnx .
|
||
|
|
COPY global.json .
|
||
|
|
COPY WorkClub.Api/*.csproj ./WorkClub.Api/
|
||
|
|
COPY WorkClub.Application/*.csproj ./WorkClub.Application/
|
||
|
|
COPY WorkClub.Domain/*.csproj ./WorkClub.Domain/
|
||
|
|
COPY WorkClub.Infrastructure/*.csproj ./WorkClub.Infrastructure/
|
||
|
|
COPY WorkClub.Tests.Integration/*.csproj ./WorkClub.Tests.Integration/
|
||
|
|
COPY WorkClub.Tests.Unit/*.csproj ./WorkClub.Tests.Unit/
|
||
|
|
|
||
|
|
# Restore dependencies (cached layer)
|
||
|
|
RUN dotnet restore WorkClub.slnx
|
||
|
|
|
||
|
|
# Copy source code and build
|
||
|
|
COPY . .
|
||
|
|
RUN dotnet build -c Release --no-restore
|
||
|
|
|
||
|
|
# Publish release build
|
||
|
|
RUN dotnet publish -c Release -o /app/publish --no-build
|
||
|
|
|
||
|
|
# Runtime stage - minimal Alpine image
|
||
|
|
FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine
|
||
|
|
|
||
|
|
WORKDIR /app
|
||
|
|
|
||
|
|
# Copy published application from build stage
|
||
|
|
COPY --from=build /app/publish .
|
||
|
|
|
||
|
|
# Health check
|
||
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health/live || exit 1
|
||
|
|
|
||
|
|
# Run as non-root user (built-in to Microsoft images)
|
||
|
|
USER app
|
||
|
|
|
||
|
|
# Expose default ASP.NET Core port
|
||
|
|
EXPOSE 8080
|
||
|
|
|
||
|
|
# Start the application
|
||
|
|
ENTRYPOINT ["dotnet", "WorkClub.Api.dll"]
|