Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ dump.rdb
**/resources/application-qa.yml
**/resources/dongnae_firebase_key.json

Dockerfile
docker-compose.yaml
deploy_*.sh
app-*.yaml
log/
Expand Down
17 changes: 17 additions & 0 deletions app-main/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 1. Zulu OpenJDK 17 기반 이미지 사용
FROM azul/zulu-openjdk-alpine:17

# 2. 작업 디렉토리 생성
WORKDIR /app

# 3. jar 파일 복사 (빌드 결과물에 맞게 경로 조정)
COPY app-main/build/libs/*.jar app.jar

# 4. 리소스 및 환경 파일 복사
COPY /app-main/src/main/resources/application-local.yml /app/src/main/resources/application.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

여기서 local.yml이 복사되는게 맞나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵! 맞습니다

COPY /app-main/src/main/resources/dongnae_firebase_key.json /app/src/main/resources/dongnae_firebase_key.json
Comment on lines +11 to +12
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

COPY 명령어의 소스 경로가 절대 경로(/app-main/...)로 지정되어 있습니다. docker-compose.yml에서 빌드 컨텍스트를 . (프로젝트 루트)로 설정했기 때문에, 경로는 컨텍스트에 상대적이어야 합니다. 현재 설정은 빌드 시 파일을 찾지 못해 오류를 발생시킬 수 있습니다. 맨 앞의 /를 제거하여 상대 경로로 수정해야 합니다.

COPY app-main/src/main/resources/application-local.yml /app/src/main/resources/application.yml
COPY app-main/src/main/resources/dongnae_firebase_key.json /app/src/main/resources/dongnae_firebase_key.json


# 5. 애플리케이션 실행
ENTRYPOINT ["java", "-jar", "app.jar"]


47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
services:
mysql:
image: mysql:8.0
container_name: db_caucse_mysql
environment:
MYSQL_ROOT_PASSWORD: 1234
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

MYSQL_ROOT_PASSWORD가 파일에 하드코딩되어 있습니다. 이는 심각한 보안 문제입니다. 민감한 정보는 버전 관리에 포함되어서는 안 되며, .env 파일을 통해 주입하는 것이 좋습니다.

프로젝트 루트에 .env 파일을 만들고, MYSQL_ROOT_PASSWORD=your_secret_password와 같이 변수를 정의한 뒤, docker-compose.yml에서는 ${MYSQL_ROOT_PASSWORD}와 같이 참조하도록 수정하는 것을 권장합니다. .env 파일은 반드시 .gitignore에 추가해야 합니다.

      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}

MYSQL_DATABASE: db_caucse
Copy link
Contributor

Choose a reason for hiding this comment

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

이부분은 패스워드가 담겨있는데 민감정보류는 제외하고 작성해주셔야할 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

서버에 배포하기 위한 값이 아닌 로컬에서 테스트를 위해 사용하는 것이기 때문에 크게 문제가 되진 않을 것 같습니다. 추가로 패스워드의 경우도 직접 설정을 바꿔서 사용도 가능합니다.
패스워드 없이 접근이 가능하게도 설정이 가능하지만 일부 데이터베이스에서는 패스워드 없이 설정할 경우 몇몇 기능이나 접근이 막힐 수 있습니다. 그래도 문제가 된다고 판단되시면 수정하도록 하겠습니다!
다른 분들도 의견 부탁드립니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

로컬 테스트용이면 괜찮을 것 같습니다.

TZ: Asia/Seoul
ports:
- "3308:3306"
volumes:
- ./mysql_data:/var/lib/mysql
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost -u root -p1234"]
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

healthcheck에서도 MySQL 비밀번호가 하드코딩되어 있습니다. 이 또한 .env 파일의 변수를 참조하도록 변경해야 합니다. mysqladmin 명령어에 직접 비밀번호를 전달하는 대신, MYSQL_PWD 환경 변수를 사용하는 것이 더 안전합니다.

      test: ["CMD-SHELL", "MYSQL_PWD=${MYSQL_ROOT_PASSWORD} mysqladmin ping -h localhost -u root"]

interval: 10s
timeout: 5s
retries: 5

redis:
image: redis:latest
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Redis 이미지에 latest 태그를 사용하고 있습니다. latest 태그는 예기치 않은 버전 변경을 유발하여 빌드의 재현성을 해칠 수 있습니다. 안정적인 운영과 테스트 환경을 위해 redis:7.2와 같이 특정 버전을 명시하는 것이 좋습니다.

    image: redis:7.2

container_name: db_caucse_redis
ports:
- "6379:6379"
volumes:
- ./redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5

app:
build:
context: .
dockerfile: app-main/Dockerfile
container_name: db_caucse_app
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "8080:8080"
environment:
SPRING_DATA_REDIS_HOST: redis
SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/db_caucse?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
SPRING_PROFILES_ACTIVE: local
25 changes: 25 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,28 @@
## Contact

**Email** : <a href="mailto:caucsedongne@gmail.com">caucsedongne@gmail.com</a>

## Docker Compose를 이용한 테스트 환경 구축 및 사용법

### 1. app-main 빌드

> 변경된 코드나 의존성이 있을 경우 이미지를 다시 빌드해야 합니다.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

"app-main 빌드" 섹션에서 코드 변경 시 이미지를 다시 빌드해야 한다고 설명하고 있지만, 구체적인 명령어가 없어 사용자에게 혼동을 줄 수 있습니다. 이미지 재빌드를 포함하여 컨테이너를 실행하는 docker compose up --build 명령어를 명시해주면 사용자가 더 쉽게 이해하고 사용할 수 있을 것입니다.

Suggested change
> 변경된 코드나 의존성이 있을 경우 이미지를 다시 빌드해야 합니다.
> 변경된 코드나 의존성이 있을 경우 `docker compose up --build` 명령어로 이미지를 다시 빌드해야 합니다.


### 2. 컨테이너 및 볼륨 정리 (선택 사항)

> docker compose down -v

- **설명:**
모든 컨테이너와 네트워크, **그리고 연결된 볼륨까지 모두 삭제**할 때 사용합니다.
- DB를 초기화하거나, 깨끗한 환경에서 테스트를 진행하고 싶을 때 유용합니다.
- 일부 데이터(예: DB 볼륨)를 보존하려면 `-v` 옵션 없이 `docker compose down`만 실행하세요.

### 3. 컨테이너 실행

> docker compose up

- **설명:**
`docker-compose.yml`에 정의된 모든 서비스가 실행됩니다.
- 백그라운드(Detached) 모드로 실행하려면:

> docker compose up -d
Loading