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
15 changes: 12 additions & 3 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ name: CI/CD Docker to EC2
# 언제 이 워크플로우를 실행할지 정하는 부분임.
on:
push:
# "release/2.5.2" 브랜치에 코드가 push 될 때마다 실행될 거임.
branches: [ "release/2.5.2" ]
# "hotfix/deployment" 브랜치에 코드가 push 될 때마다 실행될 거임.
branches: [ "hotfix/deployment" ]

# 워크플로우가 해야 할 작업(job)들을 정의함.
jobs:
Expand Down Expand Up @@ -71,7 +71,16 @@ jobs:
# 8 단계: .env 파일을 생성해서 환경변수 준비
- name: Create .env file from secret
run: |
echo "${{ secrets.APP_ENV }}" > .env
echo "DEPLOY_DB_URL=${{ secrets.DEPLOY_DB_URL }}" >> .env
echo "DEPLOY_DB_USERNAME=${{ secrets.DEPLOY_DB_USERNAME }}" >> .env
echo "DEPLOY_DB_PASSWORD=${{ secrets.DEPLOY_DB_PASSWORD }}" >> .env
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env
echo "SENDGRID_API_KEY=${{ secrets.SENDGRID_API_KEY }}" >> .env
echo "SENDGRID_FROM_EMAIL=${{ secrets.SENDGRID_FROM_EMAIL }}" >> .env
echo "SENDGRID_TEMPLATE_ID=${{ secrets.SENDGRID_TEMPLATE_ID }}" >> .env
echo "DEPLOY_REDIS_HOST=${{ secrets.DEPLOY_REDIS_HOST }}" >> .env
echo "DEPLOY_REDIS_PORT=${{ secrets.DEPLOY_REDIS_PORT }}" >> .env
echo "DEPLOY_REDIS_PASSWORD=${{ secrets.DEPLOY_REDIS_PASSWORD }}" >> .env

# 8.5 단계: .env, docker-compose.yml 파일 EC2로 복사
- name: Copy files to EC2
Expand Down
7 changes: 5 additions & 2 deletions database/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ services:
container_name: redis-container
# 접근 포트 설정(컨테이너 외부:컨테이너 내부)
ports:
- "6379:6379"
- "15483:6379"
# 내부 컨테이너 접속용
expose:
- "6379"
# 스토리지 마운트(볼륨) 설정
volumes:
- /home/ubuntu/db/redis/data:/data
Expand All @@ -21,7 +24,7 @@ services:
- "mode=standalone"
# 컨테이너 종료시 재시작 여부 설정
restart: always
command: redis-server /usr/local/conf/redis.conf
command: ["redis-server", "/usr/local/conf/redis.conf"]

networks:
default:
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ services:
# application-prod.yml 파일을 활성화 시킴
environment:
SPRING_PROFILES_ACTIVE: prod
SPRING_REDIS_HOST: redis-container
SPRING_REDIS_PORT: 6379
SPRING_REDIS_HOST: ${DEPLOY_REDIS_HOST}
SPRING_REDIS_PORT: ${DEPLOY_REDIS_PORT}
SPRING_REDIS_PASSWORD: ${DEPLOY_REDIS_PASSWORD}
# docker 컨테이너가 중단되었을때 다시 자동으로 자동 재시작 하지 않음
restart: "no"
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class RedisConfig {
@Value("${spring.data.redis.port}")
private int redisPort;

@Value("${spring.data.redis.password}")
private String redisPassword;

@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
Expand All @@ -39,6 +42,7 @@ public RedisConnectionFactory defaultRedisConnectionFactory() {
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName(redisHost);
config.setPort(redisPort);
config.setPassword(redisPassword);
return new LettuceConnectionFactory(config);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ spring:
redis:
host: ${DEPLOY_REDIS_HOST}
port: ${DEPLOY_REDIS_PORT}
password: ${DEPLOY_REDIS_PASSWORD}
timeout: 3000
ssl:
enabled: true
enabled: false