-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.backend
More file actions
119 lines (98 loc) · 3.27 KB
/
Dockerfile.backend
File metadata and controls
119 lines (98 loc) · 3.27 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# ================================
# 🔷 DOCKERFILE - BACKEND C# (.NET 8)
# Multi-stage build otimizado
# ================================
# ================================
# Stage 1: Base Runtime
# ================================
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
# Instalar dependências do sistema
RUN apt-get update && apt-get install -y \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# ================================
# Stage 2: Build
# ================================
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
# Copiar arquivos de projeto primeiro (cache de layers)
COPY ["src/API/FacialRecognition.API.csproj", "API/"]
COPY ["src/WebUI/FacialRecognition.WebUI.csproj", "WebUI/"]
COPY ["src/Application/FacialRecognition.Application.csproj", "Application/"]
COPY ["src/Domain/FacialRecognition.Domain.csproj", "Domain/"]
COPY ["src/Infrastructure/FacialRecognition.Infrastructure.csproj", "Infrastructure/"]
# Restore dependencies
RUN dotnet restore "API/FacialRecognition.API.csproj"
RUN dotnet restore "WebUI/FacialRecognition.WebUI.csproj"
# Copiar todo o código fonte
COPY src/ .
# Build da aplicação
WORKDIR "/src/API"
RUN dotnet build "FacialRecognition.API.csproj" -c $BUILD_CONFIGURATION -o /app/build
# ================================
# Stage 3: Publish
# ================================
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "FacialRecognition.API.csproj" \
-c $BUILD_CONFIGURATION \
-o /app/publish \
/p:UseAppHost=false \
--no-restore
# ================================
# Stage 4: Development (com hot reload)
# ================================
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS development
WORKDIR /app
# Instalar dotnet-ef para migrations
RUN dotnet tool install --global dotnet-ef --version 8.0.*
ENV PATH="${PATH}:/root/.dotnet/tools"
# Instalar ferramentas úteis
RUN apt-get update && apt-get install -y \
curl \
vim \
&& rm -rf /var/lib/apt/lists/*
# Criar diretórios
RUN mkdir -p /app/uploads /app/logs /app/models
# Expor portas
EXPOSE 5000
EXPOSE 5001
# Comando padrão (será sobrescrito no docker-compose)
CMD ["dotnet", "watch", "run", "--project", "src/API"]
# ================================
# Stage 5: Runtime Final (Produção)
# ================================
FROM base AS runtime
WORKDIR /app
# Copiar artefatos publicados
COPY --from=publish /app/publish .
# Criar diretórios necessários
RUN mkdir -p /app/uploads /app/logs /app/models && \
chmod -R 755 /app/uploads /app/logs /app/models
# Usuário não-root para segurança
RUN useradd -m -u 1000 appuser && \
chown -R appuser:appuser /app
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:5000/health || exit 1
# Entry point
ENTRYPOINT ["dotnet", "FacialRecognition.API.dll"]
# ================================
# BUILD INSTRUCTIONS
# ================================
#
# Development:
# docker build --target development -t facial-backend:dev .
#
# Production:
# docker build --target runtime -t facial-backend:latest .
#
# Multi-platform:
# docker buildx build --platform linux/amd64,linux/arm64 -t facial-backend:latest .
#