# Spring Boot 백엔드 배포용 Dockerfile
FROM eclipse-temurin:21-jdk-alpine AS build
WORKDIR /app

COPY gradlew ./
COPY gradle ./gradle
RUN chmod +x gradlew

COPY build.gradle settings.gradle ./
RUN ./gradlew dependencies --no-daemon || true

COPY src ./src
RUN ./gradlew bootJar --no-daemon

# Runtime image
FROM eclipse-temurin:21-jre-alpine AS runner
WORKDIR /app

# postgresql16-client: 회사 프로비저닝 시 pg_dump 로 스키마 복사.
# 서버 PG 16.x 와 버전 맞춤 (alpine 기본 postgresql-client 는 18 이라 불일치).
RUN apk add --no-cache curl postgresql16-client

COPY --from=build /app/build/libs/*.jar app.jar

RUN mkdir -p logs uploads data && \
    chown -R nobody:nobody /app && \
    chmod -R 755 /app

EXPOSE 8081
USER nobody
CMD ["java", "-jar", "app.jar"]
