Add Docker support
Docker configuration: - Dockerfile: Multi-stage build with non-root user, health checks - Dockerfile.migrations: Runs EF Core migrations on startup - docker-compose.yml: Full stack with SQL Server, Azurite, app - .dockerignore: Optimized build context - .env.example: Template for API keys Application changes: - Added /health endpoint with EF Core database check - Conditional HTTPS redirect (disabled in containers) - DOTNET_RUNNING_IN_CONTAINER environment detection Usage: cp .env.example .env # Add your API keys docker-compose up -d # Start all services Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
54
Dockerfile
Normal file
54
Dockerfile
Normal file
@@ -0,0 +1,54 @@
|
||||
# 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"]
|
||||
Reference in New Issue
Block a user