# πŸš€ SOSO Server ν˜„λŒ€ν™”λœ Spring Boot 기반 μ†Œμ…œ λ―Έλ””μ–΄ ν”Œλž«νΌ μ„œλ²„ ## πŸ“‹ λͺ©μ°¨ - [κ°œμš”](#κ°œμš”) - [μ•„ν‚€ν…μ²˜](#μ•„ν‚€ν…μ²˜) - [λΉ λ₯Έ μ‹œμž‘](#λΉ λ₯Έ-μ‹œμž‘) - [배포](#배포) - [인프라 관리](#인프라-관리) - [개발 κ°€μ΄λ“œ](#개발-κ°€μ΄λ“œ) - [API λ¬Έμ„œ](#api-λ¬Έμ„œ) ## 🎯 κ°œμš” SOSO ServerλŠ” ν˜„λŒ€μ μΈ λ§ˆμ΄ν¬λ‘œμ„œλΉ„μŠ€ μ•„ν‚€ν…μ²˜λ₯Ό 기반으둜 ν•œ μ†Œμ…œ λ―Έλ””μ–΄ ν”Œλž«νΌμž…λ‹ˆλ‹€. ### μ£Όμš” κΈ°λŠ₯ - πŸ” **μ‚¬μš©μž 인증**: JWT 기반 인증 및 OAuth (Kakao) - πŸ“± **μ†Œμ…œ κΈ°λŠ₯**: κ²Œμ‹œκΈ€, λŒ“κΈ€, μ’‹μ•„μš” μ‹œμŠ€ν…œ - πŸš€ **μ‹€μ‹œκ°„ μ•Œλ¦Ό**: WebSocket 기반 μ‹€μ‹œκ°„ μ•Œλ¦Ό - πŸ“Š **λͺ¨λ‹ˆν„°λ§**: Spring Boot Actuator ν—¬μŠ€μ²΄ν¬ - 🐳 **μ»¨ν…Œμ΄λ„ˆν™”**: Docker & Docker Compose - πŸ”„ **CI/CD**: Jenkins 기반 μžλ™ 배포 ## πŸ—οΈ μ‹œμŠ€ν…œ μ•„ν‚€ν…μ²˜ ```mermaid graph TB A[Client/Browser] --> B[Caddy Reverse Proxy :80/443] B --> |/api/*| C[SOSO API :8080] B --> |/jenkins/*| D[Jenkins CI/CD :8080] B --> |/actuator/health| C C --> E[MySQL Database :3306] C --> F[Redis Cache :6379] G[GitHub Webhook] --> D D --> |Docker Build/Deploy| H[Docker Engine] H --> C subgraph "Docker Network (soso_net)" C D E F B end subgraph "External Services" I[Kakao OAuth] J[AWS S3] K[Kafka] end C --> I C --> J C --> K ``` ### μ„œλΉ„μŠ€ ꡬ성 및 λ„€νŠΈμ›Œν‚Ή | μ„œλΉ„μŠ€ | μ»¨ν…Œμ΄λ„ˆ | 포트 | 도메인 경둜 | μ—­ν•  | | ------------ | ------------ | ----------- | -------------------------- | ------------------------ | | **Proxy** | `soso-proxy` | 80, 443 | soso.dreampaste.com | Caddy λ¦¬λ²„μŠ€ ν”„λ‘μ‹œ | | **API** | `soso-api` | 8080 (λ‚΄λΆ€) | /api/*, /actuator/* | Spring Boot μ• ν”Œλ¦¬μΌ€μ΄μ…˜ | | **CI/CD** | `jenkins` | 8080 (μ™ΈλΆ€) | /jenkins/* | Jenkins μžλ™ν™” | | **Database** | `soso-mysql` | 3306 (λ‚΄λΆ€) | - | MySQL 8.4 λ°μ΄ν„°λ² μ΄μŠ€ | | **Cache** | `soso-redis` | 6379 (λ‚΄λΆ€) | - | Redis μΊμ‹œ | ### 도메인 λΌμš°νŒ… ꡬ성 #### 메인 도메인: `soso.dreampaste.com` - **API μ„œλΉ„μŠ€**: `/api/*` β†’ `soso-api:8080` - **ν—¬μŠ€μ²΄ν¬**: `/actuator/*` β†’ `soso-api:8080` - **Jenkins**: `/jenkins/*` β†’ `jenkins:8080` - **SSL**: μžλ™ Let's Encrypt μΈμ¦μ„œ ## ⚑ λΉ λ₯Έ μ‹œμž‘ ### 1. 사전 μš”κ΅¬μ‚¬ν•­ - Docker & Docker Compose - Git - Java 17+ (개발용) ### 2. ν™˜κ²½ μ„€μ • ```bash # 1. λ ˆν¬μ§€ν† λ¦¬ 클둠 git clone https://github.com/B2A5/SOSO-Server.git cd SOSO-Server # 2. ν™˜κ²½λ³€μˆ˜ μ„€μ • cp .env.example .env # .env νŒŒμΌμ„ νŽΈμ§‘ν•˜μ—¬ μ‹€μ œ 값듀을 μž…λ ₯ν•˜μ„Έμš” # 3. 인프라 μ‹œμž‘ (개발용) docker compose -f compose-dev.yml up -d # 4. μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 둜컬 μ‹€ν–‰ ./gradlew bootRun ``` ### 3. 접속 확인 - **API λ¬Έμ„œ**: http://localhost:8080/swagger-ui/ - **MySQL**: localhost:3307 - **Redis**: localhost:6379 ## πŸš€ 배포 ### ν”„λ‘œλ•μ…˜ 배포 #### μžλ™ 배포 (Git Push) ```bash # 메인 λΈŒλžœμΉ˜μ— ν‘Έμ‹œν•˜λ©΄ μžλ™ 배포 git push origin main ``` #### μˆ˜λ™ 배포 ```bash # 배포 슀크립트 μ‹€ν–‰ ./infrastructure/scripts/deploy.sh production ``` ### 배포 ν”„λ‘œμ„ΈμŠ€ 1. **ν…ŒμŠ€νŠΈ μ‹€ν–‰**: Unit ν…ŒμŠ€νŠΈ 및 톡합 ν…ŒμŠ€νŠΈ 2. **λΉŒλ“œ**: Spring Boot JAR 파일 생성 3. **Docker 이미지**: μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 이미지 λΉŒλ“œ 4. **무쀑단 배포**: ν—¬μŠ€μ²΄ν¬ 기반 둀링 μ—…λ°μ΄νŠΈ 5. **검증**: μ„œλΉ„μŠ€ μƒνƒœ 및 μ—”λ“œν¬μΈνŠΈ 확인 ## πŸ› οΈ 인프라 관리 ### ν˜„λŒ€ν™”λœ Git 기반 인프라 λͺ¨λ“  인프라 ꡬ성은 Git으둜 κ΄€λ¦¬λ˜λ©°, `git push`만으둜 μ„œλ²„ 인프라λ₯Ό μ—…λ°μ΄νŠΈν•  수 μžˆμŠ΅λ‹ˆλ‹€: - **compose.yml**: ν†΅ν•©λœ Docker Compose μ„€μ • - **infrastructure/Caddyfile**: Git으둜 κ΄€λ¦¬λ˜λŠ” λ¦¬λ²„μŠ€ ν”„λ‘μ‹œ μ„€μ • - **Jenkinsfile**: Docker Compose 기반 CI/CD νŒŒμ΄ν”„λΌμΈ - **infrastructure/scripts/**: μžλ™ν™”λœ 관리 슀크립트 ### 관리 λͺ…λ Ήμ–΄ ```bash # μ‹œμŠ€ν…œ μƒνƒœ 확인 ./infrastructure/scripts/manage.sh status # μ„œλΉ„μŠ€ 둜그 확인 ./infrastructure/scripts/manage.sh logs api 100 # λ°±μ—… 생성 ./infrastructure/scripts/manage.sh backup # μ„œλΉ„μŠ€ μž¬μ‹œμž‘ ./infrastructure/scripts/manage.sh restart api # μ‹œμŠ€ν…œ 정리 ./infrastructure/scripts/manage.sh cleanup # μ‹€μ‹œκ°„ λͺ¨λ‹ˆν„°λ§ (5λΆ„κ°„) ./infrastructure/scripts/manage.sh monitor 300 ``` ### ν—¬μŠ€μ²΄ν¬ 및 λͺ¨λ‹ˆν„°λ§ ```bash # API ν—¬μŠ€μ²΄ν¬ curl https://soso.dreampaste.com/actuator/health # Jenkins 접속 확인 curl https://soso.dreampaste.com/jenkins/ # Swagger API λ¬Έμ„œ curl https://soso.dreampaste.com/swagger-ui/ ``` ### μžλ™ 배포 νŒŒμ΄ν”„λΌμΈ 1. **Git Push** β†’ GitHub μ €μž₯μ†Œμ— μ½”λ“œ ν‘Έμ‹œ 2. **Webhook Trigger** β†’ Jenkinsκ°€ μžλ™μœΌλ‘œ λΉŒλ“œ μ‹œμž‘ 3. **Test & Build** β†’ ν…ŒμŠ€νŠΈ μ‹€ν–‰ ν›„ Docker 이미지 λΉŒλ“œ 4. **Zero-Downtime Deploy** β†’ ν—¬μŠ€μ²΄ν¬ 기반 무쀑단 배포 5. **Verification** β†’ 배포 μ™„λ£Œ ν›„ μ„œλΉ„μŠ€ μƒνƒœ 검증 ## πŸ‘¨β€πŸ’» 개발 κ°€μ΄λ“œ ### 둜컬 개발 ν™˜κ²½ ```bash # 개발용 인프라 μ‹œμž‘ (DB, Redis만) docker compose -f compose-dev.yml up -d # μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 개발 λͺ¨λ“œ μ‹€ν–‰ ./gradlew bootRun --args='--spring.profiles.active=dev' # ν…ŒμŠ€νŠΈ μ‹€ν–‰ ./gradlew test # μ½”λ“œ ν¬λ§·νŒ… ./gradlew spotlessApply ``` ### 브랜치 μ „λž΅ - `main`: ν”„λ‘œλ•μ…˜ 배포 브랜치 - `dev`: 개발 톡합 브랜치 - `feature/*`: κΈ°λŠ₯ 개발 브랜치 ### 컀밋 μ»¨λ²€μ…˜ ``` feat: μƒˆλ‘œμš΄ κΈ°λŠ₯ μΆ”κ°€ fix: 버그 μˆ˜μ • docs: λ¬Έμ„œ μˆ˜μ • style: μ½”λ“œ ν¬λ§·νŒ… refactor: μ½”λ“œ λ¦¬νŒ©ν† λ§ test: ν…ŒμŠ€νŠΈ μΆ”κ°€/μˆ˜μ • chore: λΉŒλ“œ κ΄€λ ¨ μˆ˜μ • ``` ## πŸ“š API λ¬Έμ„œ ### 접속 URL - **Swagger UI**: https://soso.dreampaste.com/swagger-ui/ - **OpenAPI Spec**: https://soso.dreampaste.com/v3/api-docs ### μ£Όμš” μ—”λ“œν¬μΈνŠΈ #### πŸ” 인증/νšŒμ›κ°€μž… API | κΈ°λŠ₯ | Method | Endpoint | μ„€λͺ… | | -------------- | ------ | ---------------------------- | --------------------------------------- | | 카카였 둜그인 | POST | `/auth/kakao/login` | 카카였 OAuth 둜그인 | | 토큰 μž¬λ°œκΈ‰ | POST | `/auth/refresh` | Refresh Token으둜 Access Token μž¬λ°œκΈ‰ | #### πŸ‘€ νšŒμ›κ°€μž… 단계별 API | 단계 | Method | Endpoint | μ„€λͺ… | | -------------- | ------ | ---------------------------- | --------------------------------------- | | 1단계 | POST | `/signup/user-type` | μ‚¬μš©μž μœ ν˜• μ„€μ • (μ˜ˆλΉ„μ°½μ—…μž/일반거주민) | | 2단계 | POST | `/signup/region` | μ§€μ—­ μ„€μ • | | 3단계 | POST | `/signup/age-range` | μ—°λ ΉλŒ€ μ„€μ • | | 4단계 | POST | `/signup/gender` | 성별 μ„€μ • | | 5단계* | POST | `/signup/interests` | 관심업쒅 μ„€μ • (μ˜ˆλΉ„μ°½μ—…μž μ „μš©) | | 6단계* | POST | `/signup/budget` | μ˜ˆμ‚° μ„€μ • (μ˜ˆλΉ„μ°½μ—…μž μ „μš©) | | 7단계* | POST | `/signup/experience` | μ°½μ—… κ²½ν—˜ μ„€μ • (μ˜ˆλΉ„μ°½μ—…μž μ „μš©) | | 8단계 | POST | `/signup/nickname` | λ‹‰λ„€μž„ μžλ™ 생성 | | 9단계 | POST | `/signup/complete` | νšŒμ›κ°€μž… μ™„λ£Œ 및 JWT 토큰 λ°œκΈ‰ | #### πŸ“ μžμœ κ²Œμ‹œνŒ API | κΈ°λŠ₯ | Method | Endpoint | μ„€λͺ… | | -------------- | ------ | -------------------------------------- | --------------------------------------- | | κ²Œμ‹œκΈ€ λͺ©λ‘ | GET | `/community/freeboard` | μ»€μ„œ 기반 κ²Œμ‹œκΈ€ λͺ©λ‘ 쑰회 | | κ²Œμ‹œκΈ€ 생성 | POST | `/community/freeboard` | μƒˆ κ²Œμ‹œκΈ€ μž‘μ„± (이미지 μ—…λ‘œλ“œ 지원) | | κ²Œμ‹œκΈ€ 쑰회 | GET | `/community/freeboard/{id}` | κ²Œμ‹œκΈ€ 상세 쑰회 | | κ²Œμ‹œκΈ€ μˆ˜μ • | PATCH | `/community/freeboard/{id}` | κ²Œμ‹œκΈ€ μˆ˜μ • | | κ²Œμ‹œκΈ€ μ‚­μ œ | DELETE | `/community/freeboard/{id}` | κ²Œμ‹œκΈ€ μ†Œν”„νŠΈ μ‚­μ œ | | μ’‹μ•„μš” ν† κΈ€ | POST | `/community/freeboard/{id}/like` | κ²Œμ‹œκΈ€ μ’‹μ•„μš” μΆ”κ°€/μ·¨μ†Œ | | μ’‹μ•„μš” μƒνƒœ | GET | `/community/freeboard/{id}/like` | μ’‹μ•„μš” μƒνƒœ 확인 | #### πŸ’¬ λŒ“κΈ€ API | κΈ°λŠ₯ | Method | Endpoint | μ„€λͺ… | | -------------- | ------ | --------------------------------------------- | --------------------------------- | | λŒ“κΈ€ λͺ©λ‘ | GET | `/community/freeboard/{id}/comments` | μ»€μ„œ 기반 λŒ“κΈ€ λͺ©λ‘ 쑰회 | | λŒ“κΈ€ μž‘μ„± | POST | `/community/freeboard/{id}/comments` | λŒ“κΈ€/λŒ€λŒ“κΈ€ μž‘μ„± | | λŒ“κΈ€ μˆ˜μ • | PATCH | `/community/freeboard/{id}/comments/{cId}` | λŒ“κΈ€ μˆ˜μ • | | λŒ“κΈ€ μ‚­μ œ | DELETE | `/community/freeboard/{id}/comments/{cId}` | λŒ“κΈ€ μ†Œν”„νŠΈ μ‚­μ œ | | λŒ“κΈ€ μ’‹μ•„μš” | POST | `/community/freeboard/{id}/comments/{cId}/like` | λŒ“κΈ€ μ’‹μ•„μš” ν† κΈ€ | *μ˜ˆλΉ„μ°½μ—…μž μ „μš© 단계 ### 인증 API μš”μ²­ μ‹œ 헀더에 JWT 토큰 포함: ```bash Authorization: Bearer ``` ## πŸ”§ μ„€μ • ### ν™˜κ²½λ³€μˆ˜ ꡬ성 ν”„λ‘œλ•μ…˜ ν™˜κ²½μ—μ„œλŠ” `.env` νŒŒμΌμ„ 톡해 ν™˜κ²½λ³€μˆ˜λ₯Ό κ΄€λ¦¬ν•©λ‹ˆλ‹€: ```bash # Application Configuration SPRING_PROFILES_ACTIVE=prod API_IMAGE=localtest/soso-server:latest # Database Configuration (MySQL) MYSQL_ROOT_PASSWORD=your-secure-root-password DB_NAME=soso DB_USER=soso_user DB_PASS=your-secure-db-password # JWT Configuration JWT_SECRET=your-super-secure-jwt-secret-key-at-least-256-bits JWT_AT_VALIDITY=1800000 # Access Token 30λΆ„ JWT_RT_VALIDITY=1209600000 # Refresh Token 14일 # Frontend Configuration FRONTEND_ORIGIN=https://soso.dreampaste.com # OAuth Configuration (Kakao) KAKAO_CLIENT_ID=your-kakao-client-id KAKAO_REDIRECT_URIS=https://soso.dreampaste.com/auth # AWS Configuration (S3) AWS_REGION=ap-northeast-2 AWS_S3_BUCKET=your-s3-bucket-name S3_BASE_URL=https://your-s3-bucket-name.s3.ap-northeast-2.amazonaws.com # External Services KAFKA_BOOTSTRAP=your-kafka-bootstrap-servers ``` ### Spring ν”„λ‘œνŒŒμΌ | ν”„λ‘œνŒŒμΌ | μš©λ„ | λ°μ΄ν„°λ² μ΄μŠ€ μ—°κ²° | νŠΉμ§• | | -------- | ----------------------- | ------------------------ | ----------------------- | | `dev` | 둜컬 개발 ν™˜κ²½ | localhost:3307 | μ½˜μ†” 둜그, H2 μ½˜μ†” | | `test` | ν…ŒμŠ€νŠΈ ν™˜κ²½ | λ©”λͺ¨λ¦¬ H2 DB | ν…ŒμŠ€νŠΈ μ „μš© μ„€μ • | | `prod` | ν”„λ‘œλ•μ…˜ ν™˜κ²½ | Docker λ‚΄λΆ€ db:3306 | μ΅œμ ν™”, λ³΄μ•ˆ κ°•ν™” | ### μ»¨ν…Œμ΄λ„ˆ ν™˜κ²½λ³€μˆ˜ μ˜€λ²„λΌμ΄λ“œ Docker Composeμ—μ„œ λ‹€μŒ ν™˜κ²½λ³€μˆ˜λ“€μ΄ μžλ™μœΌλ‘œ μ˜€λ²„λΌμ΄λ“œλ©λ‹ˆλ‹€: ```yaml # Production Container Overrides DB_HOST: db # localhost β†’ db DB_PORT: 3306 # 3307 β†’ 3306 REDIS_HOST: redis # localhost β†’ redis REDIS_PORT: 6379 JPA_DDL: validate # create β†’ validate (운영 μ•ˆμ „μ„±) ``` ## 🚨 문제 ν•΄κ²° ### 일반적인 문제 #### 1. 포트 좩돌 ```bash # μ‚¬μš© 쀑인 포트 확인 lsof -i :8080 # μ»¨ν…Œμ΄λ„ˆ 정리 docker compose down ``` #### 2. λ°μ΄ν„°λ² μ΄μŠ€ μ—°κ²° μ‹€νŒ¨ ```bash # DB μ»¨ν…Œμ΄λ„ˆ μƒνƒœ 확인 docker compose ps db # DB 둜그 확인 docker compose logs db ``` #### 3. λ©”λͺ¨λ¦¬ λΆ€μ‘± ```bash # μ‹œμŠ€ν…œ λ¦¬μ†ŒμŠ€ 확인 docker stats # μ‹œμŠ€ν…œ 정리 ./infrastructure/scripts/manage.sh cleanup ``` ### 둜그 확인 ```bash # 전체 둜그 ./infrastructure/scripts/manage.sh logs # νŠΉμ • μ„œλΉ„μŠ€ 둜그 ./infrastructure/scripts/manage.sh logs api 100 ``` ## 🀝 κΈ°μ—¬ 1. Fork ν”„λ‘œμ νŠΈ 2. Feature 브랜치 생성 (`git checkout -b feature/amazing-feature`) 3. 변경사항 컀밋 (`git commit -m 'feat: add amazing feature'`) 4. 브랜치 ν‘Έμ‹œ (`git push origin feature/amazing-feature`) 5. Pull Request 생성 ## πŸ“„ λΌμ΄μ„ μŠ€ 이 ν”„λ‘œμ νŠΈλŠ” MIT λΌμ΄μ„ μŠ€ ν•˜μ— λ°°ν¬λ©λ‹ˆλ‹€. ---