Files
work-club-manager/backend/Dockerfile
WorkClub Automation 6124557f11 infra(docker): add Dockerfiles for backend and frontend
Implements Tasks 23 & 24: Backend and Frontend Dockerfiles

Backend Dockerfiles:
- Dockerfile.dev: Development with dotnet watch hot reload
  - Base: sdk:10.0, installs dotnet-ef tool
  - Layer caching: csproj files copied before source
  - Entry: dotnet watch run with --no-restore
- Dockerfile: Production multi-stage build
  - Build stage: sdk:10.0, restore + build + publish
  - Runtime stage: aspnet:10.0-alpine (~110MB)
  - Health check: /health/live endpoint
  - Non-root: USER app (built-in)

Frontend Dockerfiles:
- Dockerfile.dev: Development with Bun hot reload
  - Base: node:22-alpine, installs Bun globally
  - Layer caching: package.json + bun.lock before source
  - Command: bun run dev
- Dockerfile: Production standalone 3-stage build
  - Deps stage: Install with --frozen-lockfile
  - Build stage: bun run build → standalone output
  - Runner stage: node:22-alpine with non-root nextjs user
  - Copies: .next/standalone, .next/static, public
  - Health check: Node.js HTTP GET to port 3000
  - Entry: node server.js (~240MB)

All Dockerfiles use layer caching optimization and security best practices.

Note: Docker build verification skipped (Docker daemon not running).
2026-03-03 20:59:20 +01:00

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"]