Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
.git
.gitignore
*.md
build/
src/test/
src/
.gradle/
.idea/
.DS_Store
*/.DS_Store

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

현재 설정된 */.DS_Store 패턴은 1단계 하위 디렉토리의 .DS_Store 파일만 제외합니다. 프로젝트 하위의 모든 디렉토리에서 재귀적으로 .DS_Store 파일을 제외하려면 **/.DS_Store 패턴을 사용하는 것이 올바릅니다.

**/.DS_Store

.env

build/*
!build/libs/
!build/libs/eat-ssu.jar
5 changes: 4 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ jobs:
run: chmod +x gradlew

- name: Gradle로 빌드
run: ./gradlew clean build -x test
run: ./gradlew build -x test --no-daemon

- name: 빌드 산출물 확인
run: ls -lh build/libs/*.jar

- name: Docker Hub 로그인
uses: docker/login-action@v2
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
./gradlew test # 테스트만 실행
./gradlew test --tests "ssu.eatssu.domain.review.service.ReviewServiceTest" # 단일 테스트 클래스 실행
./gradlew bootRun --args='--spring.profiles.active=local' # 로컬 서버 실행 (port 9000)
docker build -f Dockerfile -t eatssu-local . # Docker 이미지 빌드
docker build -f Dockerfile -t eatssu-local . # Docker 이미지 빌드 (반드시 ./gradlew build -x test 선행 필요)
```

로컬 실행 시 MySQL이 `localhost:3306/eatssu`에 필요하며, `application-local.yml`에서 DB 정보를 설정한다. `.env` 파일로 환경변수를 오버라이드할 수 있다 (`spring.config.import: optional:file:.env[.properties]`).
Expand Down
21 changes: 2 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
# 1단계: 빌드 단계 (Gradle Wrapper를 사용하여 애플리케이션 빌드)
FROM --platform=linux/amd64 gradle:7.5.1-jdk17 AS builder
WORKDIR /home/gradle/project

# 소스 코드 전체를 복사 (gradlew, build.gradle, settings.gradle, src/ 등)
COPY --chown=gradle:gradle . .

# Gradle Wrapper 실행 권한 부여 (실행 권한이 없을 경우를 대비)
RUN chmod +x gradlew

# Gradle을 사용하여 프로젝트 빌드 (JAR 파일은 build/libs 폴더에 생성됨)
RUN ./gradlew clean build --no-daemon

# 2단계: 실행 단계 (빌드 결과물 실행을 위한 환경)
FROM --platform=linux/amd64 eclipse-temurin:17-jdk-alpine
FROM --platform=linux/amd64 eclipse-temurin:17-jre-alpine
WORKDIR /app

# 빌드 단계에서 생성된 JAR 파일 복사 (파일명이 프로젝트에 따라 달라질 수 있으므로 와일드카드 사용)
COPY --from=builder /home/gradle/project/build/libs/*.jar app.jar
COPY build/libs/eat-ssu.jar app.jar

# 컨테이너에서 사용할 포트 (필요 시 변경)
EXPOSE 9000

# 애플리케이션 실행
ENTRYPOINT ["java", "-jar", "app.jar"]
Comment on lines +1 to 8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

현재 Dockerfile은 root 권한으로 애플리케이션을 실행하도록 설정되어 있습니다. 컨테이너 내에서 root 권한으로 프로세스를 실행하는 것은 보안상 위험할 수 있으므로, 별도의 비특권(non-root) 사용자를 생성하여 실행하는 것을 권장합니다. eclipse-temurin:17-jre-alpine 이미지에서는 spring 사용자와 그룹을 생성하고, 해당 사용자로 애플리케이션을 실행하도록 설정을 변경할 수 있습니다.

FROM --platform=linux/amd64 eclipse-temurin:17-jre-alpine
WORKDIR /app

RUN addgroup -S spring && adduser -S spring -G spring
COPY --chown=spring:spring build/libs/eat-ssu.jar app.jar
USER spring:spring

EXPOSE 9000

ENTRYPOINT ["java", "-jar", "app.jar"]

4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ bootJar {
archiveVersion = "0.0.1"
}

jar {
enabled = false
}

configurations {
compileOnly {
extendsFrom annotationProcessor
Expand Down
Loading