-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
79 lines (64 loc) · 2.81 KB
/
Dockerfile
File metadata and controls
79 lines (64 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# =============================================================================
# Multi-stage Dockerfile for MemoryKit API
# Optimized for production with minimal image size and security hardening
# =============================================================================
# =============================================================================
# Stage 1: Build
# =============================================================================
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
WORKDIR /src
# Copy solution and project files
COPY MemoryKit.sln ./
COPY src/MemoryKit.Domain/MemoryKit.Domain.csproj ./src/MemoryKit.Domain/
COPY src/MemoryKit.Application/MemoryKit.Application.csproj ./src/MemoryKit.Application/
COPY src/MemoryKit.Infrastructure/MemoryKit.Infrastructure.csproj ./src/MemoryKit.Infrastructure/
COPY src/MemoryKit.API/MemoryKit.API.csproj ./src/MemoryKit.API/
COPY tests/MemoryKit.Domain.Tests/MemoryKit.Domain.Tests.csproj ./tests/MemoryKit.Domain.Tests/
COPY tests/MemoryKit.Application.Tests/MemoryKit.Application.Tests.csproj ./tests/MemoryKit.Application.Tests/
COPY tests/MemoryKit.Infrastructure.Tests/MemoryKit.Infrastructure.Tests.csproj ./tests/MemoryKit.Infrastructure.Tests/
COPY tests/MemoryKit.API.Tests/MemoryKit.API.Tests.csproj ./tests/MemoryKit.API.Tests/
COPY tests/MemoryKit.IntegrationTests/MemoryKit.IntegrationTests.csproj ./tests/MemoryKit.IntegrationTests/
# Restore dependencies (cached layer)
RUN dotnet restore src/MemoryKit.API/MemoryKit.API.csproj
# Copy source code
COPY src/ ./src/
# Build and publish
RUN dotnet publish src/MemoryKit.API/MemoryKit.API.csproj \
--configuration Release \
--output /app/publish \
--no-restore \
--no-self-contained \
-p:PublishSingleFile=false \
-p:DebugType=None \
-p:DebugSymbols=false
# =============================================================================
# Stage 2: Runtime
# =============================================================================
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine AS runtime
# Install required packages for production
RUN apk add --no-cache \
ca-certificates \
tzdata \
icu-libs \
wget \
wget
# Create non-root user
RUN addgroup -g 1000 memorykit && \
adduser -D -u 1000 -G memorykit memorykit
# Set working directory
WORKDIR /app
# Copy published app from build stage
COPY --from=build --chown=memorykit:memorykit /app/publish .
# Switch to non-root user
USER memorykit
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
# Expose port
EXPOSE 8080
# Set environment variables
ENV ASPNETCORE_ENVIRONMENT=Production \
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
TZ=UTC
# Set entrypoint
ENTRYPOINT ["dotnet", "MemoryKit.API.dll"]