# ==============================================================================
# 上海炫恒网络系统有限公司 官网 —— 生产镜像
# 基础镜像：nginx (alpine)，最终镜像约 30 MB
# 构建： docker compose build
# ==============================================================================
FROM nginx:1.27-alpine

LABEL org.opencontainers.image.title="xuanheng-website" \
      org.opencontainers.image.description="上海炫恒网络系统有限公司 官方网站（静态站点）" \
      org.opencontainers.image.vendor="上海炫恒网络系统有限公司" \
      org.opencontainers.image.licenses="Proprietary"

# ---- 1) 站点文件 ----------------------------------------------------------
# 站点根目录就是 site/，页面之间全部使用同级相对路径
COPY site/ /usr/share/nginx/html/

# ---- 2) Nginx 站点配置 ----------------------------------------------------
RUN rm -f /etc/nginx/conf.d/default.conf
COPY nginx/default.conf /etc/nginx/conf.d/default.conf

# ---- 3) 构建期自检 --------------------------------------------------------
# 五个页面和入口资源必须存在，否则构建直接失败，避免把半成品镜像推上线
RUN set -eux; \
    for f in index.html brands.html honors.html cases.html about.html \
             assets/css/main.css assets/js/main.js favicon.ico; do \
      test -f "/usr/share/nginx/html/$f" || { echo "缺少站点文件: $f"; exit 1; }; \
    done; \
    nginx -t

# ---- 4) 运行 --------------------------------------------------------------
EXPOSE 80

# 健康检查：访问 /healthz，返回 200 即视为健康
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD wget -q -O /dev/null http://127.0.0.1/healthz || exit 1

STOPSIGNAL SIGQUIT

CMD ["nginx", "-g", "daemon off;"]
