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.
53 lines
2.0 KiB
53 lines
2.0 KiB
|
3 months ago
|
# ===== build 阶段 =====
|
||
|
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||
|
|
WORKDIR /src
|
||
|
|
|
||
|
|
# 只拷贝 .csproj 做还原,最大化缓存命中
|
||
|
|
COPY ["AlarmService/AlarmService.API/AlarmService.API.csproj", "AlarmService/AlarmService.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 ["AlarmService/Alarm.Application/Alarm.Application.csproj", "AlarmService/Alarm.Application/"]
|
||
|
|
COPY ["AlarmService/Alarm.DomainService/Alarm.DomainService.csproj", "AlarmService/Alarm.DomainService/"]
|
||
|
|
COPY ["Common.SharedService/Common.Shared.DomainService/Common.Shared.DomainService.csproj", "Common.SharedService/Common.Shared.DomainService/"]
|
||
|
|
|
||
|
|
RUN dotnet restore "AlarmService/AlarmService.API/AlarmService.API.csproj"
|
||
|
|
|
||
|
|
# 再拷贝全部源码并发布(一次 publish 即可)
|
||
|
|
COPY . .
|
||
|
|
RUN dotnet publish "AlarmService/AlarmService.API/AlarmService.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
|
||
|
|
|
||
|
|
# 健康检查工具
|
||
|
|
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", "AlarmService.API.dll"]
|