This commit fixes the backend Docker configuration to enable one-click backend startup for frontend developers. Changes: - Updated Dockerfile with correct paths for modular monolith architecture * Added all module projects (Identity, ProjectManagement, IssueManagement) * Optimized layer caching by copying .csproj files first * Used alpine runtime image for smaller size (~500MB reduction) * Added non-root user (appuser) for security * Simplified to single HTTP port (8080) for development - Enhanced .dockerignore to optimize build context * Excluded unnecessary files (docs, git, docker files) * Added environment and secret file exclusions - Added /health endpoint to Program.cs * Required for Docker HEALTHCHECK functionality * Enables docker-compose to verify backend is ready Testing: - Docker build succeeds in ~14 seconds (after first build) - Backend container starts and passes health check - Swagger UI accessible at http://localhost:5000/scalar/v1 - Health endpoint returns "Healthy" at http://localhost:5000/health This implements Phase 1 of DOCKER-DEVELOPMENT-ENVIRONMENT.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
96 lines
5.1 KiB
Docker
96 lines
5.1 KiB
Docker
# ColaFlow API Dockerfile
|
|
# Multi-stage build for .NET 9 application
|
|
# Optimized for modular monolith architecture with Docker layer caching
|
|
|
|
# ================================================================================================
|
|
# Stage 1: Build
|
|
# ================================================================================================
|
|
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
|
WORKDIR /src
|
|
|
|
# Copy solution file first
|
|
COPY ["ColaFlow.sln", "./"]
|
|
|
|
# Copy all project files for dependency restoration (leverages Docker cache)
|
|
# This layer will only rebuild if any .csproj file changes
|
|
|
|
# Core projects (old structure - still in use)
|
|
COPY ["src/ColaFlow.Domain/ColaFlow.Domain.csproj", "src/ColaFlow.Domain/"]
|
|
COPY ["src/ColaFlow.Application/ColaFlow.Application.csproj", "src/ColaFlow.Application/"]
|
|
COPY ["src/ColaFlow.Infrastructure/ColaFlow.Infrastructure.csproj", "src/ColaFlow.Infrastructure/"]
|
|
COPY ["src/ColaFlow.API/ColaFlow.API.csproj", "src/ColaFlow.API/"]
|
|
|
|
# Shared projects
|
|
COPY ["src/Shared/ColaFlow.Shared.Kernel/ColaFlow.Shared.Kernel.csproj", "src/Shared/ColaFlow.Shared.Kernel/"]
|
|
|
|
# Identity Module
|
|
COPY ["src/Modules/Identity/ColaFlow.Modules.Identity.Domain/ColaFlow.Modules.Identity.Domain.csproj", "src/Modules/Identity/ColaFlow.Modules.Identity.Domain/"]
|
|
COPY ["src/Modules/Identity/ColaFlow.Modules.Identity.Application/ColaFlow.Modules.Identity.Application.csproj", "src/Modules/Identity/ColaFlow.Modules.Identity.Application/"]
|
|
COPY ["src/Modules/Identity/ColaFlow.Modules.Identity.Infrastructure/ColaFlow.Modules.Identity.Infrastructure.csproj", "src/Modules/Identity/ColaFlow.Modules.Identity.Infrastructure/"]
|
|
|
|
# ProjectManagement Module
|
|
COPY ["src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Domain/ColaFlow.Modules.ProjectManagement.Domain.csproj", "src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Domain/"]
|
|
COPY ["src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Application/ColaFlow.Modules.ProjectManagement.Application.csproj", "src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Application/"]
|
|
COPY ["src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Infrastructure/ColaFlow.Modules.ProjectManagement.Infrastructure.csproj", "src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Infrastructure/"]
|
|
COPY ["src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Contracts/ColaFlow.Modules.ProjectManagement.Contracts.csproj", "src/Modules/ProjectManagement/ColaFlow.Modules.ProjectManagement.Contracts/"]
|
|
|
|
# IssueManagement Module
|
|
COPY ["src/Modules/IssueManagement/ColaFlow.Modules.IssueManagement.Domain/ColaFlow.Modules.IssueManagement.Domain.csproj", "src/Modules/IssueManagement/ColaFlow.Modules.IssueManagement.Domain/"]
|
|
COPY ["src/Modules/IssueManagement/ColaFlow.Modules.IssueManagement.Application/ColaFlow.Modules.IssueManagement.Application.csproj", "src/Modules/IssueManagement/ColaFlow.Modules.IssueManagement.Application/"]
|
|
COPY ["src/Modules/IssueManagement/ColaFlow.Modules.IssueManagement.Infrastructure/ColaFlow.Modules.IssueManagement.Infrastructure.csproj", "src/Modules/IssueManagement/ColaFlow.Modules.IssueManagement.Infrastructure/"]
|
|
COPY ["src/Modules/IssueManagement/ColaFlow.Modules.IssueManagement.Contracts/ColaFlow.Modules.IssueManagement.Contracts.csproj", "src/Modules/IssueManagement/ColaFlow.Modules.IssueManagement.Contracts/"]
|
|
|
|
# Restore NuGet packages
|
|
# This layer is cached unless .csproj files change
|
|
RUN dotnet restore "src/ColaFlow.API/ColaFlow.API.csproj"
|
|
|
|
# Copy the rest of the source code
|
|
# This layer rebuilds whenever source code changes
|
|
COPY . .
|
|
|
|
# Build the application
|
|
WORKDIR "/src/src/ColaFlow.API"
|
|
RUN dotnet build "ColaFlow.API.csproj" -c Release -o /app/build --no-restore
|
|
|
|
# ================================================================================================
|
|
# Stage 2: Publish
|
|
# ================================================================================================
|
|
FROM build AS publish
|
|
RUN dotnet publish "ColaFlow.API.csproj" -c Release -o /app/publish --no-restore
|
|
|
|
# ================================================================================================
|
|
# Stage 3: Runtime (Alpine for smaller image size)
|
|
# ================================================================================================
|
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine AS runtime
|
|
WORKDIR /app
|
|
|
|
# Install curl for health checks (alpine uses apk)
|
|
RUN apk add --no-cache curl
|
|
|
|
# Create a non-root user for security
|
|
RUN addgroup -g 1000 appgroup && \
|
|
adduser -D -u 1000 -G appgroup appuser
|
|
|
|
# Copy published application from publish stage
|
|
COPY --from=publish /app/publish .
|
|
|
|
# Set ownership of application files
|
|
RUN chown -R appuser:appgroup /app
|
|
|
|
# Configure ASP.NET Core
|
|
ENV ASPNETCORE_URLS=http://+:8080
|
|
ENV ASPNETCORE_ENVIRONMENT=Development
|
|
|
|
# Expose HTTP port (HTTPS will be handled by reverse proxy in production)
|
|
EXPOSE 8080
|
|
|
|
# Health check endpoint
|
|
HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=40s \
|
|
CMD curl -f http://localhost:8080/health || exit 1
|
|
|
|
# Run as non-root user for security
|
|
USER appuser
|
|
|
|
# Entry point
|
|
ENTRYPOINT ["dotnet", "ColaFlow.API.dll"]
|