Skip to content

Commit

Permalink
Server Test
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeg00 committed Sep 10, 2023
1 parent 9627d03 commit 0146030
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ name: Deploy to Amazon EC2
on:
pull_request:
branches:
- develop
- develop
- 'feat/**' # feat으로 시작하는 브랜치에 대해서도 동작
push:
branches:
- develop
- 'feat/**' # feat으로 시작하는 브랜치에 대해서도 동작


# 본인이 설정한 값을 여기서 채워넣습니다.
# 리전, 버킷 이름, CodeDeploy 앱 이름, CodeDeploy 배포 그룹 이름
env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: megabrain-just-s3-bucket
CODE_DEPLOY_APPLICATION_NAME: my-codedeploy-app
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: my-codedeploy-deployment-group
S3_BUCKET_NAME: pick-read-me-actions-s3-bucket
CODE_DEPLOY_APPLICATION_NAME: pick-read-me-codedeploy-app
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: pick-read-me-codedeploy-deployment-group

permissions:
contents: read
Expand All @@ -36,12 +39,14 @@ jobs:
with:
distribution: 'temurin'
java-version: '11'

- name: Copy Secret
env:
OCCUPY_SECRET: ${{ secrets.OCCUPY_SECRET }}
OCCUPY_SECRET_DIR: src/main/resources
OCCUPY_SECRET_DIR_FILE_NAME: application.yml
run: echo $OCCUPY_SECRET | base64 --decode > $OCCUPY_SECRET_DIR/$OCCUPY_SECRET_DIR_FILE_NAME

# (3) Gradle build (Test 제외)
- name: Build with Gradle
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
Expand All @@ -64,11 +69,12 @@ jobs:
--ignore-hidden-files \
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \
--source .
# (6) S3 버킷에 있는 파일을 대상으로 CodeDeploy 실행
- name: Deploy to AWS EC2 from S3
run: |
aws deploy create-deployment \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip
5 changes: 3 additions & 2 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PROJECT_ROOT="/home/ec2-user/app"
PROJECT_ROOT="/home/ubuntu/app"
JAR_FILE="$PROJECT_ROOT/spring-webapp.jar"

APP_LOG="$PROJECT_ROOT/application.log"
Expand All @@ -7,6 +7,7 @@ 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

Expand All @@ -15,4 +16,4 @@ 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 > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG
echo "$TIME_NOW > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG
20 changes: 12 additions & 8 deletions scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
PROJECT_ROOT="/home/ec2-user/app"
PROJECT_ROOT="/home/ubuntu/app"
JAR_FILE="$PROJECT_ROOT/spring-webapp.jar"

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

TIME_NOW=$(date +%c)

CURRENT_PID=$(pgrep -f $JAR_FILE)
# 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 &

if [ -z $CURRENT_PID ]; then
echo "$TIME_NOW > 현재 실행중이 애플리케이션이 없습니다" >> $DEPLOY_LOG
else
echo "$TIME_NOW > 실행중인 $CURRENT_PID 애플리케이션 종료 " >> $DEPLOY_LOG
kill -15 $CURRENT_PID
fi
CURRENT_PID=$(pgrep -f $JAR_FILE)
echo "$TIME_NOW > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG

0 comments on commit 0146030

Please sign in to comment.