# Multi-module Spring Boot 빌드 (ga-api 또는 ga-batch 선택)
# Build:  docker build --build-arg MODULE=ga-api -t ga-api .
ARG MODULE=ga-api

# Stage 1: build
FROM gradle:8.6-jdk17 AS builder
WORKDIR /work
COPY settings.gradle build.gradle gradle.properties ./
COPY ga-common/build.gradle  ga-common/
COPY ga-core/build.gradle    ga-core/
COPY ga-api/build.gradle     ga-api/
COPY ga-batch/build.gradle   ga-batch/
COPY ga-admin/build.gradle   ga-admin/
# 의존성 사전 다운로드 (캐시 최적화)
RUN gradle --no-daemon dependencies > /dev/null 2>&1 || true

COPY ga-common  ga-common
COPY ga-core    ga-core
COPY ga-api     ga-api
COPY ga-batch   ga-batch
COPY ga-admin   ga-admin

ARG MODULE
RUN gradle --no-daemon :${MODULE}:bootJar -x test

# Stage 2: runtime
FROM eclipse-temurin:17-jre-alpine
ARG MODULE
WORKDIR /app
COPY --from=builder /work/${MODULE}/build/libs/${MODULE}.jar /app/app.jar
ENV TZ=Asia/Seoul
EXPOSE 8080 8081
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
