Files
CasService/docker/Dockerfile
T

33 lines
2.1 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CAS 5.3.16 运行镜像(单阶段,war 预构建)
# CI 已先 mvn package 并在容器内把产物 cp 成固定名 target/app.jar(= cas.war,可执行 WAR)
# 构建上下文 = 仓库根:docker build -f docker/Dockerfile .
# 健康检查(projman 应用配置 healthPath=/status + HTTPS 自签名开):curl -fk https://localhost:8443/status
# 时区 Asia/Shanghai;JAVA_OPTS 由 projman 部署 env 注入(默认 -Xms512m -Xmx1024m)
FROM eclipse-temurin:8-jre
# CAS 5.3 默认要求 HTTPS(安全 Cookie),生成自签名密钥库(密码固定 changeit,过渡期用)
RUN mkdir -p /etc/cas/config \
&& keytool -genkeypair -alias cas -keyalg RSA -keysize 2048 -validity 3650 \
-storetype JKS -keystore /etc/cas/cas.keystore \
-storepass changeit -keypass changeit -dname "CN=cas.example.org" \
&& apt-get update && apt-get install -y --no-install-recommends curl tzdata \
&& ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY target/app.jar /app/cas.war
COPY docker/cas.properties /etc/cas/config/cas.properties
COPY etc/cas/config/log4j2.xml /etc/cas/config/log4j2.xml
# 镜像内 cas.properties 仅保留环境无关配置(HTTPS/端口/日志/管理页白名单);
# 业务配置(cas.server.name / cas.authn.jdbc / Redis / custom.login.* 等)来自 projman
# 配置管理挂载的 /app/config/application.yml(Boot 1.5 自动加载 file:./config/ 且优先于 classpath),镜像保持环境无关。
EXPOSE 8443
# 兜底:把容器 hostname 写入 /etc/hosts。Docker 默认 hostname=容器短ID,某些 network_mode 下
# /etc/hosts 不含该行且内网 DNS 无法解析 → InetAddress.getLocalHost 抛 UnknownHostException,
# 导致 CAS TicketIdSanitizationUtils 类初始化失败(ExceptionInInitializerError),票据日志带病运行。
RUN printf '#!/bin/sh\nHN=$(hostname)\ngrep -qw "$HN" /etc/hosts || echo "127.0.0.1 $HN" >> /etc/hosts\nexec java ${JAVA_OPTS:--Xms512m -Xmx1024m} -Dfile.encoding=UTF-8 -jar /app/cas.war\n' > /app/entrypoint.sh \
&& chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]