# ═══════════════════════════════════════════════════════════════════════════════
# WebClientTpos Dockerfile
# EN: Multi-stage build for Blazor WebAssembly Hosted (root context)
# VI: Multi-stage build cho Blazor WebAssembly Hosted (root context)
# ═══════════════════════════════════════════════════════════════════════════════

# ═══════════════════════════════════════════════════════════════════════════════
# Stage 1: Build
# ═══════════════════════════════════════════════════════════════════════════════
FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine AS build
WORKDIR /src

# EN: Copy project files for layer caching (app + shared package)
# VI: Copy project files để cache layers (app + shared package)
COPY apps/web-client-tpos-net/WebClientTpos.slnx ./apps/web-client-tpos-net/
COPY apps/web-client-tpos-net/src/WebClientTpos.Shared/WebClientTpos.Shared.csproj ./apps/web-client-tpos-net/src/WebClientTpos.Shared/
COPY apps/web-client-tpos-net/src/WebClientTpos.Client/WebClientTpos.Client.csproj ./apps/web-client-tpos-net/src/WebClientTpos.Client/
COPY apps/web-client-tpos-net/src/WebClientTpos.Server/WebClientTpos.Server.csproj ./apps/web-client-tpos-net/src/WebClientTpos.Server/
COPY packages/blazor-ui/GoodGo.BlazorUi.csproj ./packages/blazor-ui/

# EN: Restore dependencies
# VI: Restore dependencies
WORKDIR /src/apps/web-client-tpos-net
RUN dotnet restore

# EN: Copy full source code
# VI: Copy toàn bộ source code
WORKDIR /src
COPY apps/web-client-tpos-net/ ./apps/web-client-tpos-net/
COPY packages/blazor-ui/ ./packages/blazor-ui/

# EN: Build and publish
# VI: Build và publish
RUN dotnet publish apps/web-client-tpos-net/src/WebClientTpos.Server/WebClientTpos.Server.csproj \
    -c Release \
    -o /app/publish

# ═══════════════════════════════════════════════════════════════════════════════
# Stage 2: Runtime
# ═══════════════════════════════════════════════════════════════════════════════
FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS runtime
WORKDIR /app

# EN: Install ICU libs for globalization support (Alpine doesn't include them)
# VI: Cài đặt ICU libs cho hỗ trợ globalization (Alpine không bao gồm sẵn)
RUN apk add --no-cache icu-libs
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

# 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", "WebClientTpos.Server.dll"]
# Build trigger 1775832654
# Build trigger v2 1775833389
# Build v3 1775834045
# Build v4 1775835811
# Build v5 1775838916
