-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
87 lines (63 loc) · 2.72 KB
/
Dockerfile
File metadata and controls
87 lines (63 loc) · 2.72 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
80
81
82
83
84
85
86
# =============================================================================
# Thrive Stream Controller - Multi-stage Docker Build
# Builds both React UI and .NET API, serves UI as static files from API
# =============================================================================
# -----------------------------------------------------------------------------
# Stage 1: Build React UI
# -----------------------------------------------------------------------------
FROM node:20-alpine AS ui-build
WORKDIR /app/ui
# Copy package files first for better caching
COPY UI/package*.json ./
# Install dependencies
RUN npm ci
# Copy UI source
COPY UI/ ./
# Build production bundle
RUN npm run build
# -----------------------------------------------------------------------------
# Stage 2: Build .NET API
# -----------------------------------------------------------------------------
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS api-build
WORKDIR /app
# Copy solution and project files first for better caching
COPY API/ThriveStreamController.sln ./
COPY API/ThriveStreamController.API/ThriveStreamController.API.csproj ./ThriveStreamController.API/
COPY API/ThriveStreamController.Core/ThriveStreamController.Core.csproj ./ThriveStreamController.Core/
COPY API/ThriveStreamController.Data/ThriveStreamController.Data.csproj ./ThriveStreamController.Data/
COPY API/ThriveStreamController.Tests/ThriveStreamController.Tests.csproj ./ThriveStreamController.Tests/
# Restore dependencies
RUN dotnet restore
# Copy all API source
COPY API/ ./
# Build and publish
RUN dotnet publish ThriveStreamController.API/ThriveStreamController.API.csproj \
-c Release \
-o /app/publish \
--no-restore
# -----------------------------------------------------------------------------
# Stage 3: Final Runtime Image
# -----------------------------------------------------------------------------
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
# Create non-root user for security
RUN adduser --disabled-password --gecos "" appuser
# Copy published API
COPY --from=api-build /app/publish ./
# Copy built UI to wwwroot
COPY --from=ui-build /app/ui/dist ./wwwroot
# Create data directory for SQLite database and logs
RUN mkdir -p /app/data /app/logs && chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Environment variables
ENV ASPNETCORE_URLS=http://+:8080
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ConnectionStrings__DefaultConnection="Data Source=/app/data/thrivestream.db"
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/api/obs/status || exit 1
# Start the application
ENTRYPOINT ["dotnet", "ThriveStreamController.API.dll"]