Skip to content

Commit ce61e16

Browse files
authored
Merge pull request #40 from haram-jo/feature/#39
[feat] AWS 배포 하기 위한 yml 관련 환경 설정 변경
2 parents 5303bad + 8dcb663 commit ce61e16

File tree

8 files changed

+89
-65
lines changed

8 files changed

+89
-65
lines changed

.github/workflows/deploy.yml

Whitespace-only changes.

docker-compose.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ services:
5050
- mysql
5151
- redis
5252
environment:
53-
SPRING_PROFILES_ACTIVE: docker
53+
SPRING_PROFILES_ACTIVE: prod
5454
env_file:
5555
- .env
5656
networks:
@@ -85,14 +85,18 @@ services:
8585
networks:
8686
- app-network
8787

88-
kafka:
88+
kafka-1:
8989
image: confluentinc/cp-kafka:7.4.0
9090
ports:
9191
- "9092:9092" #도커 내부 포트 9092를 내 컴퓨터 포트 9092에 매핑
9292
environment:
9393
KAFKA_BROKER_ID: 1
9494
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
95-
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092 # 도커 외부에서 도는 API 서버가 카프카를 찾아갈 수 있음
95+
# ✅ 리스너 이름을 서비스 이름인 kafka-1로 설정
96+
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:29092,CONTROLLER://0.0.0.0:9092
97+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-1:29092,CONTROLLER://localhost:9092
98+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT
99+
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
96100
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
97101
depends_on:
98102
- zookeeper

services/api/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ dependencies {
7070
// 테스트를 위한 설정 (선택 사항)
7171
testImplementation 'org.springframework.kafka:spring-kafka-test'
7272

73+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
74+
75+
7376
}
7477

7578
tasks.named('test') {

services/api/src/main/java/com/sprint/api/config/SecurityConfig.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ public PasswordEncoder passwordEncoder() {
4444
public CorsConfigurationSource corsConfigurationSource() {
4545
CorsConfiguration configuration = new CorsConfiguration();
4646

47-
// 프론트엔드 포트 허용
48-
configuration.setAllowedOrigins(List.of("http://localhost:5173"));
47+
// [핵심 수정] 환경 변수에서 프론트엔드 주소를 가져오고, 없으면 로컬 주소를 기본값으로 사용
48+
String frontendUrl = System.getenv("FRONTEND_URL");
49+
if (frontendUrl == null) frontendUrl = "http://localhost:5173";
50+
51+
// 로컬과 실제 배포 주소를 모두 허용 목록에 넣습니다.
52+
configuration.setAllowedOrigins(List.of(frontendUrl, "http://localhost:5173"));
53+
4954
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
5055
configuration.setAllowedHeaders(List.of("*"));
51-
// 쿠키 전송을 위해 필수 설정
52-
configuration.setAllowCredentials(true);
56+
configuration.setAllowCredentials(true); // 쿠키/인증정보 전송 허용
5357

5458
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
5559
source.registerCorsConfiguration("/**", configuration);
@@ -110,12 +114,3 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
110114
return http.build();
111115
}
112116
}
113-
114-
/* 테스트 코드
115-
.csrf(csrf -> csrf.disable()) // 테스트 위해 임시허용
116-
// 모든 경로에 대해 접근 허용
117-
.authorizeHttpRequests(auth -> auth
118-
.anyRequest().permitAll()
119-
);
120-
http.addFilterBefore(customLoginFilter(), UsernamePasswordAuthenticationFilter.class);
121-
*/
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
# ----- API는 local, MySQL는 Docker -----
2-
spring.datasource.url=jdbc:mysql://mysql:3306/appdb?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul
1+
# 1. Database (RDS \uC5F0\uACB0\uC6A9)
2+
# \uD658\uACBD \uBCC0\uC218\uAC00 \uC788\uC73C\uBA74 \uADF8 \uAC12\uC744 \uC4F0\uACE0, \uC5C6\uC73C\uBA74 \uAE30\uBCF8\uAC12(mysql:3306)\uC744 \uC0AC\uC6A9\uD558\uB3C4\uB85D \uC124\uC815\uD568
3+
spring.datasource.url=jdbc:mysql://${RDS_HOSTNAME:mysql}:${RDS_PORT:3306}/${RDS_DB_NAME:appdb}?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul
4+
spring.datasource.username=${RDS_USERNAME:app}
5+
spring.datasource.password=${RDS_PASSWORD:app}
36
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
4-
spring.datasource.username=app
5-
spring.datasource.password=app
67

7-
# JPA
8+
# 2. JPA (\uC6B4\uC601 \uD658\uACBD \uC8FC\uC758!)
9+
# \uBC30\uD3EC \uC2DC\uC5D0\uB294 'update'\uBCF4\uB2E4 'none'\uC774\uB098 'validate'\uAC00 \uC548\uC804\uD558\uC9C0\uB9CC, \uCD08\uAE30 \uAD6C\uCD95 \uC2DC\uC5D0\uB294 update\uB97C \uC720\uC9C0\uD574\uB3C4 \uB428
810
spring.jpa.hibernate.ddl-auto=update
9-
spring.jpa.show-sql=true
11+
spring.jpa.show-sql=false
1012
spring.jpa.properties.hibernate.format_sql=true
1113

12-
# schema.sql/data.sql ???? ????? ??? ? ???(??? always?)
13-
spring.sql.init.mode=never
14+
# 3. Redis (ElastiCache \uC5F0\uACB0\uC6A9)
15+
spring.data.redis.host=${REDIS_HOST:my-redis}
16+
spring.data.redis.port=${REDIS_PORT:6379}
17+
18+
# 4. Kafka (MSK \uB610\uB294 Cloud Kafka \uC5F0\uACB0\uC6A9)
19+
spring.kafka.bootstrap-servers=${KAFKA_BROKERS:kafka-1:29092}
20+
21+
# 5. Actuator (\uBCF4\uC548\uC744 \uC704\uD574 health\uB9CC \uB178\uCD9C)
22+
management.endpoints.web.exposure.include=health
23+
management.endpoint.health.show-details=always
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
spring.application.name=api
2-
spring.profiles.active=local
2+
spring.profiles.active=prod
33

44
# JWT \uC124\uC815
55
jwt.secret=${JWT_SECRET}
66

77
# TMDB API \uD1A0\uD070 (\uACF5\uD1B5)
8-
custom.tmdb.access-token=${TMDB_ACCESS_TOKEN}
8+
custom.tmdb.access-token=${TMDB_ACCESS_TOKEN}
9+
10+
# Actuator endpoint \uBAA8\uB450 \uB178\uCD9C
11+
management.endpoints.web.exposure.include=*

services/batch/src/main/resources/application-docker.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
server.port=8081
22

3-
spring.datasource.url=jdbc:mysql://mysql:3306/appdb?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul
4-
spring.datasource.username=app
5-
spring.datasource.password=app
3+
spring.datasource.url=jdbc:mysql://${RDS_HOSTNAME:mysql}:${RDS_PORT:3306}/${RDS_DB_NAME:appdb}?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul
4+
spring.datasource.username=${RDS_USERNAME:app}
5+
spring.datasource.password=${RDS_PASSWORD:app}
66

77
spring.jpa.hibernate.ddl-auto=update
88
spring.jpa.show-sql=false

services/gateway/nginx/nginx.conf

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,48 @@
11
# Nginx 전체 설정 파일
22
worker_processes auto;
33

4-
events {
5-
worker_connections 1024;
6-
}
7-
8-
http {
9-
include /etc/nginx/mime.types;
10-
default_type application/octet-stream;
11-
12-
sendfile on;
13-
keepalive_timeout 65;
14-
15-
# 1. 기존 include는 주석 처리하거나 그대로 둡니다.
16-
# include /etc/nginx/conf.d/*.conf;
17-
18-
# 2. 서버 설정
19-
server {
20-
listen 80;
21-
22-
# 일반 API 요청 (로컬 API 서버 연결)
23-
location /api/ {
24-
proxy_pass http://host.docker.internal:8080;
25-
proxy_set_header Host $host;
26-
proxy_set_header X-Real-IP $remote_addr;
27-
}
28-
29-
# SSE 전용 설정 (실시간 알림용)
30-
location /api/sse {
31-
proxy_pass http://host.docker.internal:8080;
32-
proxy_set_header Connection "";
33-
proxy_http_version 1.1;
34-
proxy_buffering off; # 새로고침 안해도 알람 전송해주는 설정
35-
proxy_cache off;
36-
proxy_read_timeout 3600s;
37-
}
38-
}
39-
}
4+
events {
5+
worker_connections 1024;
6+
}
7+
8+
http {
9+
include /etc/nginx/mime.types;
10+
default_type application/octet-stream;
11+
12+
sendfile on;
13+
keepalive_timeout 65;
14+
15+
server {
16+
listen 80;
17+
18+
# [필수] AWS 내부 DNS 서버 주소 (Service Discovery를 찾기 위해 꼭 필요함)
19+
resolver 10.0.0.2 valid=30s;
20+
21+
# [필수] 변수 정의: API 서버의 내부 도메인 주소
22+
set $api_url http://api.mopl.local:8080;
23+
24+
# 1. 일반 API 요청
25+
location /api/ {
26+
proxy_pass $api_url;
27+
proxy_set_header Host $host;
28+
proxy_set_header X-Real-IP $remote_addr;
29+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
30+
}
31+
32+
# 2. SSE 전용 설정 (실시간 알림용)
33+
location /api/sse {
34+
proxy_pass $api_url;
35+
proxy_set_header Connection "";
36+
proxy_http_version 1.1;
37+
proxy_buffering off;
38+
proxy_cache off;
39+
proxy_read_timeout 3600s;
40+
}
41+
42+
# [추가] ALB 건강 체크용 (배포 시 필수)
43+
location /health {
44+
access_log off;
45+
return 200 'OK';
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)