# ============================================================================= # Multi-stage Dockerfile for Embase Conference Abstract Packaging Scheduler # Targets: .NET 8 Worker Service running on Linux # Optimized for: Small image size, security, and production deployment # ============================================================================= # ============================================================================= # Stage 1: Build # Uses the full SDK image to restore packages and build the application # ============================================================================= FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src # Copy project files for dependency restoration COPY ["src/EmbaseConferenceScheduler.Worker/EmbaseConferenceScheduler.Worker.csproj", "src/EmbaseConferenceScheduler.Worker/"] COPY ["src/EmbaseConferenceScheduler.Application/EmbaseConferenceScheduler.Application.csproj", "src/EmbaseConferenceScheduler.Application/"] COPY ["src/EmbaseConferenceScheduler.Domain/EmbaseConferenceScheduler.Domain.csproj", "src/EmbaseConferenceScheduler.Domain/"] COPY ["src/EmbaseConferenceScheduler.Infrastructure/EmbaseConferenceScheduler.Infrastructure.csproj", "src/EmbaseConferenceScheduler.Infrastructure/"] # Restore dependencies # This layer is cached unless project files change - improves build performance RUN dotnet restore "src/EmbaseConferenceScheduler.Worker/EmbaseConferenceScheduler.Worker.csproj" # Copy all source code COPY . . # Build the application WORKDIR "/src/src/EmbaseConferenceScheduler.Worker" RUN dotnet build "EmbaseConferenceScheduler.Worker.csproj" -c Release -o /app/build # ============================================================================= # Stage 2: Publish # Creates a production-ready published output with optimizations # ============================================================================= FROM build AS publish RUN dotnet publish "EmbaseConferenceScheduler.Worker.csproj" -c Release -o /app/publish /p:UseAppHost=false # ============================================================================= # Stage 3: Runtime # Uses the minimal runtime image - significantly smaller than SDK # Only contains what's needed to run the application # ============================================================================= FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final # Set working directory WORKDIR /app # Create non-root user for security # Running as non-root is a security best practice RUN groupadd -r appuser && useradd -r -g appuser appuser # Copy published application from publish stage COPY --from=publish /app/publish . # Create directories for runtime operations (with proper permissions) RUN mkdir -p /app/temp /logs && chown -R appuser:appuser /app/temp /logs # Set ownership to non-root user RUN chown -R appuser:appuser /app # Switch to non-root user USER appuser # Set environment variables # These can be overridden at runtime via docker run -e or docker-compose ENV DOTNET_ENVIRONMENT=Production ENV TZ="Asia/Kolkata" # Entry point - starts the worker service ENTRYPOINT ["dotnet", "EmbaseConferenceScheduler.Worker.dll"]