Skip to content

Commit

Permalink
Merge pull request #4 from dnd-side-project/feat/#2
Browse files Browse the repository at this point in the history
#1 Feat: CI 구축
  • Loading branch information
min-0 authored Jul 29, 2024
2 parents a43b241 + d1e17f2 commit 174f5cb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ out/
.vscode/

### DB ###
application-*.yml
**/.DS_Store
21 changes: 21 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 0.0
os: linux

files:
- source: / # 인스턴스에 복사할 디렉터리 경로
destination: /home/ec2-user/mapddang-back # 인스턴스에서 파일이 복사되는 위치
overwrite: yes # 복사할 위치에 파일이 있는 경우 대체

permissions:
- object: / # 권한이 지정되는 파일 or 디렉터리
owner: ec2-user # object의 소유자
group: ec2-user # object의 그룹 이름

hooks:
AfterInstall: # CodeDeploy의 AfterInstall 단계에서 실행
- location: scripts/stop.sh # hooks에서 실행할 스크립트의 위치
timeout: 60 # 스크립트 실행에 허용되는 최대 시간, 넘으면 배포 실패

ApplicationStart: # CodeDeploy의 ApplicationStart 단계에서 실행
- location: scripts/start.sh
timeout: 60
19 changes: 19 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PROJECT_ROOT="/home/ec2-user/mapddang-back"
JAR_FILE="$PROJECT_ROOT/dnd-travel.jar"

APP_LOG="$PROJECT_ROOT/application.log"
ERROR_LOG="$PROJECT_ROOT/error.log"
DEPLOY_LOG="$PROJECT_ROOT/deploy.log"

TIME_NOW=$(date +%c)

# build 파일 복사
echo "$TIME_NOW > $JAR_FILE 복사" >> $DEPLOY_LOG
cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE

# jar 파일 실행
echo "$TIME_NOW > $JAR_FILE 실행" >> $DEPLOY_LOG
nohup java -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG &

CURRENT_PID=$(pgrep -f $JAR_FILE)
echo "$TIME_NOW > 서비스 PID: $CURRENT_PID " >> $DEPLOY_LOG
17 changes: 17 additions & 0 deletions scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PROJECT_ROOT="/home/ec2-user/mapddang-back"
JAR_FILE="$PROJECT_ROOT/dnd-travel.jar"

DEPLOY_LOG="$PROJECT_ROOT/deploy.log"

TIME_NOW=$(date +%c)

# 현재 구동 중인 애플리케이션 pid 확인
CURRENT_PID=$(pgrep -f $JAR_FILE)

# 프로세스가 켜져 있으면 종료
if [ -z $CURRENT_PID ]; then
echo "$TIME_NOW > 현재 실행 중인 애플리케이션이 없음" >> $DEPLOY_LOG
else
echo "$TIME_NOW > 실행 중인 $CURRENT_PID 애플리케이션 종료 " >> $DEPLOY_LOG
kill -15 $CURRENT_PID
fi
5 changes: 5 additions & 0 deletions src/main/resources/application-db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spring:
datasource:
url: ${{ secrets.MYSQL_URL }}
username: ${{ secrets.MYSQL_USERNAME }}
password: ${{ secrets.MYSQL_PASSWORD }}

0 comments on commit 174f5cb

Please sign in to comment.