# 成长服务Dockerfile
FROM openjdk:17-jdk-alpine

# 设置工作目录
WORKDIR /app

# 安装必要的工具
RUN apk add --no-cache curl tzdata && \
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone

# 复制Maven构建文件
COPY pom.xml ./
COPY emotion-common ./emotion-common
COPY emotion-growth ./emotion-growth

# 安装Maven
RUN apk add --no-cache maven

# 构建应用
RUN mvn clean package -DskipTests -pl emotion-growth -am

# 创建运行用户
RUN addgroup -g 1000 emotion && \
    adduser -D -s /bin/sh -u 1000 -G emotion emotion

# 复制jar文件
RUN cp emotion-growth/target/emotion-growth-*.jar app.jar

# 设置文件权限
RUN chown -R emotion:emotion /app

# 切换到非root用户
USER emotion

# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:19004/actuator/health || exit 1

# 暴露端口
EXPOSE 19004

# 启动命令
ENTRYPOINT ["java", "-jar", \
    "-Xms512m", "-Xmx1024m", \
    "-Djava.security.egd=file:/dev/./urandom", \
    "-Dspring.profiles.active=local", \
    "app.jar"]
