# 网关服务Dockerfile - 测试环境版本
FROM openjdk:17-jdk-alpine

# 构建参数
ARG JAR_FILE=emotion-gateway-1.0.0.jar
ARG CONFIG_FILE=config/gateway-test.yml

# 设置工作目录
WORKDIR /app

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

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

# 创建必要的目录
RUN mkdir -p /app/config /data/logs/emotion-museum && \
    chown -R emotion:emotion /app /data

# 复制jar文件和配置文件
COPY ${JAR_FILE} app.jar
COPY ${CONFIG_FILE} config/application.yml

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

# 切换到非root用户
USER emotion

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

# 暴露端口
EXPOSE 9000

# 启动命令
ENTRYPOINT ["java", "-jar", \
    "-Xms${JVM_XMS:-512m}", "-Xmx${JVM_XMX:-1024m}", \
    "-Djava.security.egd=file:/dev/./urandom", \
    "-Dspring.profiles.active=${SPRING_PROFILES_ACTIVE:-test}", \
    "-Dspring.config.location=classpath:/application.yml,file:/app/config/application.yml", \
    "-Dlogging.file.path=/data/logs/emotion-museum", \
    "app.jar"]
