# Build stage FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src # Copy csproj and restore dependencies (better caching) COPY ["QRRapidoApp.csproj", "./"] RUN dotnet restore "QRRapidoApp.csproj" # Copy source code COPY . . # Build optimized for production RUN dotnet build "QRRapidoApp.csproj" -c Release -o /app/build --no-restore # Publish stage FROM build AS publish RUN dotnet publish "QRRapidoApp.csproj" -c Release -o /app/publish --no-restore --no-build \ /p:PublishReadyToRun=true \ /p:PublishSingleFile=false \ /p:PublishTrimmed=false # Runtime stage FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final WORKDIR /app # Install dependencies for QR code generation RUN apt-get update && apt-get install -y \ libgdiplus \ libc6-dev \ curl \ && rm -rf /var/lib/apt/lists/* # Copy application COPY --from=publish /app/publish . # Configure production environment ENV ASPNETCORE_ENVIRONMENT=Production ENV ASPNETCORE_URLS=http://+:80 ENV DOTNET_EnableDiagnostics=0 # Create non-root user for security RUN addgroup --system --gid 1001 qrrapido RUN adduser --system --uid 1001 qrrapido # Set ownership RUN chown -R qrrapido:qrrapido /app USER qrrapido # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD curl -f http://localhost/health || exit 1 EXPOSE 80 ENTRYPOINT ["dotnet", "QRRapidoApp.dll"]