Skip to content

Commit

Permalink
chore: dev 환경 변수 파일 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jemin committed Apr 26, 2024
1 parent 8171743 commit f626a8f
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 72 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: build/test

on: # when the workflows should be triggered ?
pull_request: # Starting Build when pull request is created.
on:
pull_request:
branches: [ "main", "dev"]

permissions:
contents: read
checks: write
issues: write

jobs: # defining jobs, executed in this workflows
jobs:
build:
runs-on: ubuntu-latest
services:
Expand All @@ -19,7 +19,7 @@ jobs: # defining jobs, executed in this workflows
- 6379:6379
steps:
- name: Checkout repository
uses: actions/checkout@v3 # clone repository
uses: actions/checkout@v3
with:
token: ${{ secrets.ACTION_TOKEN }}
submodules: true
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3 # clone repository
uses: actions/checkout@v3
with:
token: ${{ secrets.ACTION_TOKEN }}
submodules: true

- name: Update submodules
run: git submodule update --remote

# Caching Gradle
- name: Cache Gradle
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -56,12 +55,12 @@ jobs:
run: |
aws s3 cp \
--region ap-northeast-2 \
./$GITHUB_SHA.zip s3://dnd-9th-1-s3
./$GITHUB_SHA.zip s3://milestone-deploy-dev
- name: Request to CodeDeploy
run: |
aws deploy create-deployment \
--application-name dnd-9th-1-codedeploy \
--application-name milestone-deploy-dev \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name milestone-prod-deployment-group \
--s3-location bucket=dnd-9th-1-s3,bundleType=zip,key=$GITHUB_SHA.zip
--deployment-group-name milestone-deploy-group-dev \
--s3-location bucket=milestone-deploy-dev,bundleType=zip,key=$GITHUB_SHA.zip
6 changes: 3 additions & 3 deletions appspec.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ hooks:
- location: scripts/dev/health_check.sh
timeout: 180
runas: ubuntu
- location: scripts/dev/switch.sh
timeout: 180
runas: ubuntu
# - location: scripts/dev/switch.sh
# timeout: 180
# runas: ubuntu
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
// jpa
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'


// security
implementation 'org.springframework.boot:spring-boot-starter-security'

Expand All @@ -32,7 +33,7 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'

// database
implementation 'org.mariadb.jdbc:mariadb-java-client:3.1.4'
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.h2database:h2'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

Expand All @@ -46,9 +47,6 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'

implementation 'net.javacrumbs.shedlock:shedlock-spring:5.1.0'
implementation 'net.javacrumbs.shedlock:shedlock-provider-redis-spring:5.1.0'

implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
Expand Down
18 changes: 9 additions & 9 deletions scripts/dev/health_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

# Crawl current connected port of WAS
CURRENT_PORT=$(cat /home/ubuntu/dev_url.inc | grep -Po '[0-9]+' | tail -1)
TARGET_PORT=0
TARGET_PORT=8080

# Toggle port Number
if [ ${CURRENT_PORT} -eq 8083 ]; then
TARGET_PORT=8084
elif [ ${CURRENT_PORT} -eq 8084 ]; then
TARGET_PORT=8083
else
echo "> No WAS is connected to nginx"
exit 1
fi
#if [ ${CURRENT_PORT} -eq 8083 ]; then
# TARGET_PORT=8084
#elif [ ${CURRENT_PORT} -eq 8084 ]; then
# TARGET_PORT=8083
#else
# echo "> No WAS is connected to nginx"
# exit 1
#fi

echo "> Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}' ..."

Expand Down
24 changes: 12 additions & 12 deletions scripts/dev/run_new_was.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ echo "> Start run_new_was.sh"
# Parse port number from 'dev_url.inc'
CURRENT_PORT=$(cat /home/ubuntu/dev_url.inc | grep -Po '[0-9]+' | tail -1)
CURRENT_PROFILE=dev
TARGET_PORT=0
TARGET_PORT=8080

echo "> Current port of running WAS is ${CURRENT_PORT}."
#echo "> Current port of running WAS is ${CURRENT_PORT}."

# Find target port to switch
if [ ${CURRENT_PORT} -eq 8083 ]; then
TARGET_PORT=8084
elif [ ${CURRENT_PORT} -eq 8084 ]; then
TARGET_PORT=8083
else
echo "> No WAS is connected to nginx"
fi
## Find target port to switch
#if [ ${CURRENT_PORT} -eq 8083 ]; then
# TARGET_PORT=8084
#elif [ ${CURRENT_PORT} -eq 8084 ]; then
# TARGET_PORT=8083
#else
# echo "> No WAS is connected to nginx"
#fi

# query pid using the TCP protocol and using the port 'TARGET_PORT'
echo "> Kill WAS running at ${TARGET_PORT}."
sudo kill $(sudo lsof -t -i:${TARGET_PORT})
#echo "> Kill WAS running at ${TARGET_PORT}."
#sudo kill $(sudo lsof -t -i:${TARGET_PORT})

# run jar file in background
nohup sudo java -jar -Duser.timezone="Asia/Seoul" -Dspring.profiles.active=${CURRENT_PROFILE} -Dserver.port=${TARGET_PORT} /home/ubuntu/dev/build/libs/backend-0.0.1-SNAPSHOT.jar > /home/ubuntu/dev/nohup.out 2>&1 &
Expand Down
15 changes: 1 addition & 14 deletions src/main/java/com/backend/global/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.backend.auth.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;

import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider;

@Configuration
@EnableRedisRepositories
public class RedisConfig {
Expand All @@ -23,20 +18,12 @@ public class RedisConfig {
@Value("${spring.data.redis.port}")
private int port;

@Autowired
Environment env;

@Bean
public RedisConnectionFactory connectionFactory(){
public RedisConnectionFactory connectionFactory() {
RedisStandaloneConfiguration redisConfiguration = new RedisStandaloneConfiguration();
redisConfiguration.setHostName(host);
redisConfiguration.setPort(port);
return new LettuceConnectionFactory(redisConfiguration);
}

@Bean
public LockProvider lockProvider(RedisConnectionFactory connectionFactory) {
String lockEnv = env.getProperty("spring.profiles.active");
return new RedisLockProvider(connectionFactory, lockEnv);
}
}
7 changes: 0 additions & 7 deletions src/main/java/com/backend/global/config/SchedulerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;

@Configuration
@EnableScheduling
@EnableSchedulerLock(defaultLockAtLeastFor = "5s", defaultLockAtMostFor = "5s")
public class SchedulerConfig implements SchedulingConfigurer {

private static final String SCHEDULER_THREAD_POOL_NAME = "scheduler thread pool";
private static final String THREAD_NAME_PREFIX = "scheduler-thread-";
private static final int POOL_SIZE = 3;

/*
쓰레드풀 사이즈를 선정할때는 필요 이상으로 크게 할당하는걸 경계해야 합니다.
서비스에 쓰레드 개수가 늘어나는건 쓰레드 간 경합을 증가시켜서 컨텍스트 스위칭 비용을 증가시킵니다.
따라서 현재 서비스에 스케쥴러가 2개만 존재하고 스케쥴링 간격이 긴 만큼 여유분 1개를 추가해서 총 3개의 쓰레드를 할당했습니다.
*/
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/backend/global/entity/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import org.mariadb.jdbc.plugin.codec.LocalDateTimeCodec;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/com/backend/global/scheduler/SchedulerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;

import com.backend.detailgoal.application.dto.response.DetailGoalAlarmResponse;
import com.backend.detailgoal.domain.event.AlarmEvent;
import com.backend.detailgoal.domain.repository.DetailGoalQueryRepository;
Expand All @@ -31,14 +29,7 @@ public class SchedulerService {

private final ApplicationEventPublisher applicationEventPublisher;

/*
매일 0시 0분에 달성 기간이 지난 목표들을 보관함으로 이동시킵니다.
서버가 Scale out되면 스케쥴러가 중복 실행될 수 있으므로 Redis 기반의 스케쥴러 락을 사용해서 하나의 스케쥴러만 실행되도록 만들었습니다.
RDBMS(MySQL)를 사용할수도 있고, Redis를 사용할 수도 있습니다. 현재 서비스에서 인증 토큰 용도로 Redis를 도입했기 때문에 추가 인프라 비용 없이 Redis를 선택했습니다.
서비스가 성장해서 스케쥴러의 종류가 많아지고 스케일 아웃으로 서버 수도 증가하면, 스케쥴러 락을 사용하기 보다는 알림 서버를 따로 분리하는 선택을 할 것 같습니다.
- 현재는 인프라 비용 문제로 AWS 상에서 단일 서버만 운영하고 있습니다.
*/
@SchedulerLock(name = OUTDATED_GOAL_LOCK)

@Scheduled(cron = "0 0 * * * *", zone = LOCAL_TIME_ZONE)
@Transactional
public void storeOutDateGoal() {
Expand All @@ -50,7 +41,6 @@ public void storeOutDateGoal() {
/*
사용자가 지정한 시간(30분 단위)에 목표에 대한 알림을 전송합니다.
*/
@SchedulerLock(name = SEND_ALARM_LOCK)
@Scheduled(cron = "0 */30 * * * *", zone = LOCAL_TIME_ZONE)
public void sendAlarm() {
List<DetailGoalAlarmResponse> detailGoalAlarmList = detailGoalQueryRepository.getMemberIdListDetailGoalAlarmTimeArrived(
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config

0 comments on commit f626a8f

Please sign in to comment.