Files
Ho Ngoc Hai 76d75c753b Migrate
2026-05-23 18:37:02 +07:00

67 lines
3.1 KiB
Docker

# ═══════════════════════════════════════════════════════════════════════════════
# WebClientBase Dockerfile
# EN: Multi-stage build for Blazor WebAssembly Hosted
# VI: Multi-stage build cho Blazor WebAssembly Hosted
# ═══════════════════════════════════════════════════════════════════════════════
# ═══════════════════════════════════════════════════════════════════════════════
# Stage 1: Build
# ═══════════════════════════════════════════════════════════════════════════════
FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine AS build
WORKDIR /src
# EN: Copy solution and project files for layer caching
# VI: Copy solution và project files để cache layers
COPY WebClientBase.slnx ./
COPY src/WebClientBase.Shared/WebClientBase.Shared.csproj ./src/WebClientBase.Shared/
COPY src/WebClientBase.Client/WebClientBase.Client.csproj ./src/WebClientBase.Client/
COPY src/WebClientBase.Server/WebClientBase.Server.csproj ./src/WebClientBase.Server/
# EN: Restore dependencies
# VI: Restore dependencies
RUN dotnet restore
# EN: Copy source code
# VI: Copy source code
COPY . .
# EN: Build and publish
# VI: Build và publish
RUN dotnet publish src/WebClientBase.Server/WebClientBase.Server.csproj \
-c Release \
-o /app/publish \
--no-restore
# ═══════════════════════════════════════════════════════════════════════════════
# Stage 2: Runtime
# ═══════════════════════════════════════════════════════════════════════════════
FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS runtime
WORKDIR /app
# EN: Create non-root user for security
# VI: Tạo user không phải root để bảo mật
RUN adduser -D -u 1000 appuser && chown -R appuser /app
USER appuser
# EN: Copy published output
# VI: Copy output đã publish
COPY --from=build /app/publish .
# EN: Expose port
# VI: Expose port
EXPOSE 8080
# EN: Health check
# VI: 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
# EN: Set environment variables
# VI: Thiết lập biến môi trường
ENV ASPNETCORE_URLS=http://+:8080
ENV ASPNETCORE_ENVIRONMENT=Production
# EN: Run the application
# VI: Chạy ứng dụng
ENTRYPOINT ["dotnet", "WebClientBase.Server.dll"]