You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.9 KiB
52 lines
1.9 KiB
# ===== build 阶段 ===== |
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build |
|
WORKDIR /src |
|
|
|
# 仅拷贝 csproj 提升缓存命中 |
|
COPY ["VideoService/Video.API/Video.API.csproj", "VideoService/Video.API/"] |
|
COPY ["Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj", "Common.SharedService/Common.Shared.Application/"] |
|
COPY ["WeiCloud.Core/WeiCloud.Core.csproj", "WeiCloud.Core/"] |
|
COPY ["WeiCloud.Utils/WeiCloud.Utils.csproj", "WeiCloud.Utils/"] |
|
COPY ["VideoService/Video.Application/Video.Application.csproj", "VideoService/Video.Application/"] |
|
COPY ["VideoService/Video.DomainService/Video.DomainService.csproj", "VideoService/Video.DomainService/"] |
|
COPY ["Common.SharedService/Common.Shared.DomainService/Common.Shared.DomainService.csproj", "Common.SharedService/Common.Shared.DomainService/"] |
|
|
|
RUN dotnet restore "VideoService/Video.API/Video.API.csproj" |
|
|
|
# 再拷贝全部源码并发布 |
|
COPY . . |
|
RUN dotnet publish "VideoService/Video.API/Video.API.csproj" \ |
|
-c Release -o /app \ |
|
/p:PublishReadyToRun=true \ |
|
/p:UseAppHost=false |
|
|
|
# ===== runtime 阶段 ===== |
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final |
|
WORKDIR /app |
|
|
|
# 健康检查用 curl |
|
RUN apt-get update && apt-get install -y --no-install-recommends curl \ |
|
&& rm -rf /var/lib/apt/lists/* |
|
|
|
# 创建非 root 账户(存在则跳过) |
|
RUN set -eux; \ |
|
if ! getent group app >/dev/null; then groupadd -g 64198 app; fi; \ |
|
if ! id -u appuser >/dev/null 2>&1; then useradd -r -u 64198 -g app appuser; fi |
|
|
|
# 拷贝发布产物并赋权 |
|
COPY --from=build /app ./ |
|
RUN chown -R appuser:app /app |
|
|
|
# 对外只走 8080,TLS 在 Nginx 统一终止 |
|
ENV ASPNETCORE_URLS=http://+:8080 \ |
|
ASPNETCORE_ENVIRONMENT=Production |
|
EXPOSE 8080 |
|
|
|
# 健康检查:需要你的服务实现 /healthz |
|
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \ |
|
CMD curl -fsS http://localhost:8080/healthz || exit 1 |
|
|
|
# 以非 root 运行 |
|
USER appuser |
|
|
|
ENTRYPOINT ["dotnet", "Video.API.dll"]
|
|
|