Skip to content

Commit

Permalink
chore: 배포지 변경으로 인해 배포 스크립트를 변경한다.
Browse files Browse the repository at this point in the history
  • Loading branch information
hseong3243 committed Mar 13, 2024
1 parent 0ac55c2 commit ecbe120
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CD

on:
push:
branches: [ "main" ]
branches: [ "develop", "main" ]

jobs:
build:
Expand Down Expand Up @@ -45,14 +45,14 @@ jobs:
aws-region: ap-northeast-2

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://team07-bucket/anifriends/$GITHUB_SHA.zip
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://anifriends-s3/deploy/$GITHUB_SHA.zip

- name: Deploy
run: |
aws deploy create-deployment \
--application-name team07-deploy \
--application-name anifriends \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name team07 \
--deployment-group-name anifriends \
--file-exists-behavior OVERWRITE \
--s3-location bucket=team07-bucket,bundleType=zip,key=anifriends/$GITHUB_SHA.zip \
--s3-location bucket=anifriends-s3,bundleType=zip,key=deploy/$GITHUB_SHA.zip \
--region ap-northeast-2 \
3 changes: 2 additions & 1 deletion .github/workflows/cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: cd-dev-docker

on:
push:
branches: [ "dev" ]
branches: [ "blank" ]
# - dev

jobs:
build:
Expand Down
8 changes: 4 additions & 4 deletions appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user/app/deploy
destination: /home/ubuntu/app/deploy

permissions:
- object: /
pattern: "**"
owner: ec2-user
group: ec2-user
owner: ubuntu
group: ubuntu

hooks:
ApplicationStart:
- location: scripts/deploy.sh
timeout: 60
runas: ec2-user
runas: ubuntu
33 changes: 18 additions & 15 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#!/bin/bash

BUILD_JAR=$(ls /home/ec2-user/app/deploy/build/libs/*.jar)
JAR_NAME=$(basename $BUILD_JAR)
echo ">>> build 파일명: $JAR_NAME" >> /home/ec2-user/app/deploy/deploy.log
# 변수 설정
build_jar=$(ls /home/ubuntu/app/deploy/build/libs/*.jar)
jar_name=$(basename "$build_jar")
deploy_path=/home/ubuntu/app/deploy/
deploy_log=$deploy_path/deloy.log

echo ">>> build 파일 복사" >> /home/ec2-user/app/deploy/deploy.log
DEPLOY_PATH=/home/ec2-user/app/deploy/
cp $BUILD_JAR $DEPLOY_PATH
echo ">>> build 파일명: $jar_name" >> $deploy_log

echo ">>> 현재 실행중인 애플리케이션 pid 확인" >> /home/ec2-user/app/deploy/deploy.log
CURRENT_PID=$(pgrep -f $JAR_NAME)
echo ">>> build 파일 복사" >> $deploy_log
cp "$build_jar" $deploy_path

if [ -z $CURRENT_PID ]
echo ">>> 현재 실행중인 애플리케이션 pid 확인" >> $deploy_log
CURRENT_PID=$(pgrep -f "$jar_name")

if [ -z "$CURRENT_PID" ]
then
echo ">>> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ec2-user/app/deploy/deploy.log
echo ">>> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> $deploy_log
else
echo ">>> kill -15 $CURRENT_PID"
kill -15 $CURRENT_PID
echo ">>> kill -15 $CURRENT_PID" >> $deploy_log
kill -15 "$CURRENT_PID"
sleep 5
fi

DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME
echo ">>> DEPLOY_JAR 배포" >> /home/ec2-user/app/deploy/deploy.log
nohup java -jar $DEPLOY_JAR --spring.profiles.active=dev >> /home/ec2-user/deploy.log 2>/home/ec2-user/app/deploy/deploy_err.log &
DEPLOY_JAR=$deploy_path$jar_name
echo ">>> DEPLOY_JAR 배포" >> $deploy_log
nohup java -jar "$DEPLOY_JAR" --spring.profiles.active=dev >> /home/ubuntu/app.log 2>$deploy_path/deploy_err.log &
2 changes: 1 addition & 1 deletion src/main/resources/backend-config

0 comments on commit ecbe120

Please sign in to comment.