# Build stage FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src # Copy solution and project files first for better layer caching COPY TrueCV.sln ./ COPY src/TrueCV.Domain/TrueCV.Domain.csproj src/TrueCV.Domain/ COPY src/TrueCV.Application/TrueCV.Application.csproj src/TrueCV.Application/ COPY src/TrueCV.Infrastructure/TrueCV.Infrastructure.csproj src/TrueCV.Infrastructure/ COPY src/TrueCV.Web/TrueCV.Web.csproj src/TrueCV.Web/ # Restore dependencies RUN dotnet restore # Copy all source code COPY src/ src/ # Build and publish WORKDIR /src/src/TrueCV.Web RUN dotnet publish -c Release -o /app/publish --no-restore # Runtime stage FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime WORKDIR /app # Install curl for health checks RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* # Create non-root user for security RUN groupadd -r truecv && useradd -r -g truecv truecv # Copy published app COPY --from=build /app/publish . # Set ownership RUN chown -R truecv:truecv /app # Switch to non-root user USER truecv # Expose port EXPOSE 8080 # Set environment variables ENV ASPNETCORE_URLS=http://+:8080 ENV ASPNETCORE_ENVIRONMENT=Production ENV DOTNET_RUNNING_IN_CONTAINER=true # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:8080/health || exit 1 # Start the app ENTRYPOINT ["dotnet", "TrueCV.Web.dll"]