-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.prod
More file actions
61 lines (45 loc) · 1.63 KB
/
Copy pathDockerfile.prod
File metadata and controls
61 lines (45 loc) · 1.63 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
# Production Dockerfile for TaskGenix Backend
# Multi-stage build for optimized production image
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
# Copy project files in order of dependency (for better layer caching)
COPY ["TaskGenix.Core/TaskGenix.Core.csproj", "TaskGenix.Core/"]
COPY ["TaskGenix.DAL/TaskGenix.DAL.csproj", "TaskGenix.DAL/"]
COPY ["TaskGenix.BLL/TaskGenix.BLL.csproj", "TaskGenix.BLL/"]
COPY ["TaskGenix.Server/TaskGenix.Server.csproj", "TaskGenix.Server/"]
# Restore dependencies for all projects
RUN dotnet restore "TaskGenix.Server/TaskGenix.Server.csproj"
# Copy source code
COPY . .
# Build all projects in the solution
WORKDIR "/src"
RUN dotnet build "TaskGenix.Server/TaskGenix.Server.csproj" -c Release --no-restore
# Publish stage
FROM build AS publish
WORKDIR "/src/TaskGenix.Server"
RUN dotnet publish "TaskGenix.Server.csproj" -c Release -o /app/publish \
--no-restore \
/p:UseAppHost=false
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
# Create non-root user for security
RUN groupadd -r taskgenix && useradd -r -g taskgenix taskgenix
# Set working directory
WORKDIR /app
# Copy published app
COPY --from=publish /app/publish .
# Change ownership to non-root user
RUN chown -R taskgenix:taskgenix /app
# Switch to non-root user
USER taskgenix
# Expose ports
EXPOSE 5009
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:5009/health || exit 1
# Set environment variables
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS=http://+:5009
# Entry point
ENTRYPOINT ["dotnet", "TaskGenix.Server.dll"]