Skip to content

Commit 16fb59c

Browse files
authored
Infra: AWS 추가 세팅
* Infra: 운영환경(application-prod.yml) 수정 - redis 설정 추가 - Oauth 설정 추가 - logging 설정 변경 - 스터디룸 설정 추가 * Infra: EmbeddedRedisConfig 관련 설정 추가 - 작업환경 정보 출력 - 기존 : 맥 환경이면 embedded-redis 비활성화 -> 변경 : 맥 환경이거나 현재 운영환경인 경우 embedded-redis 비활성화 * Infra: AWS 인스턴스 Tags 추가 - tags { Key = "Team" Value = "devcos-teamxx" Name = "인스턴스 name" } * Infra: EC2 추가 세팅 - Redis 설치 - NginX 설치
1 parent 6a131d5 commit 16fb59c

File tree

4 files changed

+185
-38
lines changed

4 files changed

+185
-38
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ db_dev.trace.db
4646
/infra/terraform/.terraform
4747
/infra/terraform/.terraform.lock.hcl
4848
/infra/terraform/terraform.tfstate
49-
/infra/terraform/terraform.tfstate.backup
49+
/infra/terraform/terraform.tfstate.backup
50+
/infra/terraform/secrets.tf

infra/terraform/main.tf

Lines changed: 90 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ resource "aws_vpc" "vpc_1" {
1919
enable_dns_hostnames = true
2020

2121
tags = {
22-
Name = "team5-vpc-1"
22+
Key = "TEAM"
23+
Value = "devcos-team05"
24+
Name = "team5-vpc-1"
2325
}
2426
}
2527

@@ -31,7 +33,9 @@ resource "aws_subnet" "subnet_1" {
3133
map_public_ip_on_launch = true # 퍼블릭 IP 자동 할당
3234

3335
tags = {
34-
Name = "team5-subnet-1-public"
36+
Key = "TEAM"
37+
Value = "devcos-team05"
38+
Name = "team5-subnet-1-public"
3539
}
3640
}
3741

@@ -42,7 +46,9 @@ resource "aws_subnet" "subnet_2" {
4246
availability_zone = "ap-northeast-2a"
4347

4448
tags = {
45-
Name = "team5-subnet-2-private"
49+
Key = "TEAM"
50+
Value = "devcos-team05"
51+
Name = "team5-subnet-2-private"
4652
}
4753
}
4854

@@ -53,7 +59,9 @@ resource "aws_subnet" "subnet_3" {
5359
availability_zone = "ap-northeast-2b"
5460

5561
tags = {
56-
Name = "team5-subnet-3-private"
62+
Key = "TEAM"
63+
Value = "devcos-team05"
64+
Name = "team5-subnet-3-private"
5765
}
5866
}
5967

@@ -62,7 +70,9 @@ resource "aws_internet_gateway" "igw_1" {
6270
vpc_id = aws_vpc.vpc_1.id
6371

6472
tags = {
65-
Name = "team5-igw-1"
73+
Key = "TEAM"
74+
Value = "devcos-team05"
75+
Name = "team5-igw-1"
6676
}
6777
}
6878

@@ -77,7 +87,9 @@ resource "aws_route_table" "rt_1" {
7787
}
7888

7989
tags = {
80-
Name = "team5-rt-1"
90+
Key = "TEAM"
91+
Value = "devcos-team05"
92+
Name = "team5-rt-1"
8193
}
8294
}
8395

@@ -104,8 +116,14 @@ resource "aws_route_table_association" "association_3" {
104116
}
105117

106118
resource "aws_security_group" "sg_1" {
107-
name = "team5-sg-1"
108-
vpc_id = aws_vpc.vpc_1.id
119+
name = "team5-sg-1"
120+
vpc_id = aws_vpc.vpc_1.id
121+
122+
tags = {
123+
Key = "TEAM"
124+
Value = "devcos-team05"
125+
Name = "team5-sg-1"
126+
}
109127

110128
ingress {
111129
from_port = 0
@@ -124,7 +142,11 @@ resource "aws_security_group" "sg_1" {
124142

125143
# EC2 역할 생성
126144
resource "aws_iam_role" "ec2_role_1" {
127-
name = "team5-ec2-role-1"
145+
tags = {
146+
Key = "TEAM"
147+
Value = "devcos-team05"
148+
Name = "team5-ec2-role-1"
149+
}
128150

129151
# 이 역할에 대한 신뢰 정책 설정. EC2 서비스가 이 역할을 가정할 수 있도록 설정
130152
assume_role_policy = <<EOF
@@ -152,26 +174,62 @@ resource "aws_iam_role_policy_attachment" "ec2_ssm" {
152174

153175
# IAM 인스턴스 프로파일 생성
154176
resource "aws_iam_instance_profile" "instance_profile_1" {
155-
name = "team5-instance-profile-1"
177+
tags = {
178+
Key = "TEAM"
179+
Value = "devcos-team05"
180+
Name = "team5-instance-profile-1"
181+
}
182+
156183
role = aws_iam_role.ec2_role_1.name
157184
}
158185

159186
# EC2 실행마다 적용할 작업
160187
locals {
161188
ec2_user_data_base = <<-END_OF_FILE
162189
#!/bin/bash
163-
yum install docker -y
164-
systemctl enable docker
165-
systemctl start docker
166-
167-
yum install git -y
168-
190+
# 가상 메모리 4GB 설정
169191
sudo dd if=/dev/zero of=/swapfile bs=128M count=32
170192
sudo chmod 600 /swapfile
171193
sudo mkswap /swapfile
172194
sudo swapon /swapfile
173195
sudo sh -c 'echo "/swapfile swap swap defaults 0 0" >> /etc/fstab'
174196
197+
# git 설치
198+
yum install git -y
199+
200+
#도커 설치 및 실행/활성화
201+
yum install docker -y
202+
systemctl enable docker
203+
systemctl start docker
204+
205+
# 도커 네트워크 생성
206+
docker network create common
207+
208+
# redis 설치
209+
docker run -d \
210+
--name redis_1 \
211+
--network common \
212+
-p 6379:6379 \
213+
-e TZ=Asia/Seoul \
214+
-v /dockerProjects/redis_1/volumes/data:/data \
215+
redis --requirepass ${var.password_1}
216+
217+
# NginX 설치
218+
docker run -d \
219+
--name npm_1 \
220+
--restart unless-stopped \
221+
--network common \
222+
-p 80:80 \
223+
-p 443:443 \
224+
-p 81:81 \
225+
-e TZ=Asia/Seoul \
226+
227+
-e INITIAL_ADMIN_PASSWORD=${var.password_1} \
228+
-v /dockerProjects/npm_1/volumes/data:/data \
229+
-v /dockerProjects/npm_1/volumes/etc/letsencrypt:/etc/letsencrypt \
230+
jc21/nginx-proxy-manager:latest
231+
232+
175233
END_OF_FILE
176234
}
177235

@@ -189,7 +247,9 @@ resource "aws_instance" "ec2_1" {
189247
iam_instance_profile = aws_iam_instance_profile.instance_profile_1.name
190248

191249
tags = {
192-
Name = "team5-ec2-1"
250+
Key = "TEAM"
251+
Value = "devcos-team05"
252+
Name = "team5-ec2-1"
193253
}
194254

195255
# 루트 불륨 설정
@@ -211,9 +271,9 @@ resource "aws_security_group" "rds_sg_1" {
211271
vpc_id = aws_vpc.vpc_1.id
212272

213273
ingress {
214-
from_port = 3306
215-
to_port = 3306
216-
protocol = "tcp"
274+
from_port = 3306
275+
to_port = 3306
276+
protocol = "tcp"
217277
cidr_blocks = ["0.0.0.0/0"]
218278
}
219279

@@ -225,7 +285,9 @@ resource "aws_security_group" "rds_sg_1" {
225285
}
226286

227287
tags = {
228-
Name = "team5-rds-sg-1"
288+
Key = "TEAM"
289+
Value = "devcos-team05"
290+
Name = "team5-rds-sg-1"
229291
}
230292
}
231293

@@ -235,7 +297,9 @@ resource "aws_db_subnet_group" "db_subnet_group" {
235297
subnet_ids = [aws_subnet.subnet_2.id, aws_subnet.subnet_3.id]
236298

237299
tags = {
238-
Name = "team5-db-subnet-group"
300+
Key = "TEAM"
301+
Value = "devcos-team05"
302+
Name = "team5-db-subnet-group"
239303
}
240304
}
241305

@@ -260,10 +324,12 @@ resource "aws_db_instance" "mysql" {
260324
# 자동 백업 보관 기간
261325
backup_retention_period = 1
262326

263-
# 삭제 시 최종 스냅샷 생성 여부 (개발용은 true, 운영은 false 권장)
327+
# 삭제 시 최종 스냅샷 생성 여부
264328
skip_final_snapshot = true
265329

266330
tags = {
267-
Name = "team5-rds-mysql"
331+
Key = "TEAM"
332+
Value = "devcos-team05"
333+
Name = "team5-mysql"
268334
}
269335
}

src/main/java/com/back/global/config/EmbeddedRedisConfig.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import jakarta.annotation.PostConstruct;
44
import jakarta.annotation.PreDestroy;
5+
import lombok.extern.log4j.Log4j2;
56
import org.springframework.context.annotation.Configuration;
67
import org.springframework.context.annotation.Profile;
78
import redis.embedded.RedisServer;
@@ -17,6 +18,7 @@
1718
*/
1819
@Configuration
1920
@Profile({"dev", "test"})
21+
@Log4j2
2022
public class EmbeddedRedisConfig {
2123

2224
private RedisServer redisServer;
@@ -26,10 +28,12 @@ public class EmbeddedRedisConfig {
2628
public void startRedis() {
2729
try {
2830
String osName = System.getProperty("os.name").toLowerCase();
31+
String activeProfile = System.getProperty("spring.profiles.active", "dev");
32+
log.info("현재환경: " + activeProfile);
2933

30-
// Mac 환경이면 embedded-redis 건너뛰고 docker-compose Redis 사용
31-
if (osName.contains("mac")) {
32-
System.out.println("Mac 환경 감지 → embedded-redis 비활성화, docker-compose Redis 사용");
34+
// 운영환경/Mac 환경이라면 embedded-redis 비활성화
35+
if (osName.contains("mac") || "prod".equalsIgnoreCase(activeProfile)) {
36+
log.info("운영환경/Mac 환경 감지 → embedded-redis 비활성화, 일반 Redis 사용");
3337
System.setProperty("spring.data.redis.port", "6379"); // docker-compose 기본 포트
3438
return;
3539
}
Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,98 @@
11
spring:
2-
jpa:
3-
database-platform: org.hibernate.dialect.MySQLDialect
4-
hibernate:
5-
ddl-auto: update # [none | validate | update | create | create-drop]
6-
7-
config:
8-
import: optional:file:.env[.properties]
9-
102
datasource:
113
url: jdbc:mysql://${MYSQL_HOST}:3306/${MYSQL_DATABASE}?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
124
driver-class-name: com.mysql.cj.jdbc.Driver
135
username: ${MYSQL_USERNAME}
146
password: ${MYSQL_PASSWORD}
157

8+
data:
9+
redis:
10+
host: redis_1
11+
port: 6379
12+
13+
config:
14+
import: optional:file:.env[.properties]
15+
16+
jpa:
17+
database-platform: org.hibernate.dialect.MySQLDialect
18+
hibernate:
19+
ddl-auto: update # [none | validate | update | create | create-drop]
20+
21+
security:
22+
oauth2:
23+
client:
24+
registration:
25+
kakao:
26+
client-id: ${KAKAO_CLIENT_ID}
27+
authorization-grant-type: authorization_code
28+
client-name: Kakao
29+
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
30+
scope: profile_nickname, profile_image, account_email
31+
naver:
32+
client-id: ${NAVER_CLIENT_ID}
33+
client-secret: ${NAVER_CLIENT_SECRET}
34+
client-name: Naver
35+
authorization-grant-type: authorization_code
36+
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
37+
scope: email, nickname, profile_image
38+
google:
39+
client-id: ${GOOGLE_CLIENT_ID}
40+
client-secret: ${GOOGLE_CLIENT_SECRET}
41+
client-name: Google
42+
authorization-grant-type: authorization_code
43+
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
44+
scope:
45+
- email
46+
- profile
47+
github:
48+
client-id: ${GITHUB_CLIENT_ID}
49+
client-secret: ${GITHUB_CLIENT_SECRET}
50+
client-name: GitHub
51+
authorization-grant-type: authorization_code
52+
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
53+
scope: user:email
54+
provider:
55+
kakao:
56+
authorization-uri: https://kauth.kakao.com/oauth/authorize
57+
token-uri: https://kauth.kakao.com/oauth/token
58+
user-info-uri: https://kapi.kakao.com/v2/user/me
59+
user-name-attribute: id
60+
naver:
61+
authorization-uri: https://nid.naver.com/oauth2.0/authorize
62+
token-uri: https://nid.naver.com/oauth2.0/token
63+
user-info-uri: https://openapi.naver.com/v1/nid/me
64+
user-name-attribute: response
65+
google:
66+
authorization-uri: https://accounts.google.com/o/oauth2/v2/auth
67+
token-uri: https://oauth2.googleapis.com/token
68+
user-info-uri: https://www.googleapis.com/oauth2/v3/userinfo
69+
user-name-attribute: sub
70+
github:
71+
authorization-uri: https://github.com/login/oauth/authorize
72+
token-uri: https://github.com/login/oauth/access_token
73+
user-info-uri: https://api.github.com/user
74+
user-name-attribute: id
75+
1676
springdoc:
1777
default-produces-media-type: application/json;charset=UTF-8
1878

79+
logging:
80+
level:
81+
org.hibernate.orm.jdbc.bind: OFF
82+
org.springframework.web.socket: INFO
83+
org.springframework.messaging: INFO
84+
1985
jwt:
20-
secret: ${JWT_SECRET:test-jwt-secret-key-12345678901234567890} # 운영 시에는 반드시 환경 변수로 설정할 것
86+
secret: ${JWT_SECRET} # 운영 시에는 반드시 환경 변수로 설정할 것
2187
access-token-expiration: ${JWT_ACCESS_TOKEN_EXPIRATION:1800} # 30분 (초 단위)
22-
refresh-token-expiration: ${JWT_REFRESH_TOKEN_EXPIRATION:604800} # 7일 (초 단위)
88+
refresh-token-expiration: ${JWT_REFRESH_TOKEN_EXPIRATION:604800} # 7일 (초 단위)
89+
90+
# 스터디룸 설정
91+
studyroom:
92+
heartbeat:
93+
timeout-minutes: 5 # Heartbeat 타임아웃 (분)
94+
default:
95+
max-participants: 10 # 기본 최대 참가자 수
96+
allow-camera: true
97+
allow-audio: true
98+
allow-screen-share: true

0 commit comments

Comments
 (0)