Skip to content

Commit

Permalink
Merge pull request #11 from 9oormthon-univ/feature/GOORM-6-github-act…
Browse files Browse the repository at this point in the history
…ions

[GOORM-6]- 자동화 배포 오류 수정
  • Loading branch information
sunny2you authored Nov 21, 2024
2 parents 9af96d4 + fcfadab commit 0b45833
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 47 deletions.
68 changes: 31 additions & 37 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,47 @@ name: Deploy to EC2
on:
push:
branches:
- master # master 브랜치에 Push될 때 실행
- master

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up SSH
run: |
echo "${{ secrets.EC2_PEM_KEY }}" > ec2-key.pem
chmod 600 ec2-key.pem
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.EC2_PEM_KEY }}

- name: Deploy to EC2
env:
EC2_USER: ubuntu # EC2 사용자 이름
EC2_HOST: ${{ secrets.EC2_HOST }} # EC2 호스트 주소
EC2_PATH: 2024_DANPOONG_TEAM_49_BE # 프로젝트 경로
DB_NAME: ${{ secrets.DB_NAME }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
REST_API_KEY: ${{ secrets.REST_API_KEY }}
run: |
ssh -o StrictHostKeyChecking=no -i ec2-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
set -x
# 배포 디렉토리로 이동
cd /home/ubuntu
# .env 파일 백업
if [ -f .env ]; then
echo "Backing up existing .env file..."
cp .env /tmp/.env_backup
fi
# 최신 코드 가져오기
echo "Pulling latest code from repository..."
git pull origin master
# .env 파일 복원
if [ -f /tmp/.env_backup ]; then
echo "Restoring .env file..."
mv /tmp/.env_backup .env
fi
# Gradle 빌드
echo "Building the project..."
./gradlew build
# 기존 애플리케이션 종료
echo "Stopping existing application..."
kill -9 $(lsof -t -i:8080) || true
# 새 애플리케이션 실행
echo "Starting new application..."
nohup java -jar build/libs/team49-0.0.1-SNAPSHOT.jar > app.log 2>&1 &
ssh -o StrictHostKeyChecking=no $EC2_USER@${{ secrets.EC2_HOST }} << 'EOF'
cd $EC2_PATH
git pull origin master
# application.yml 업데이트
cat > src/main/resources/application.yml << EOL
spring:
datasource:
url: jdbc:mysql://localhost:3306/${DB_NAME}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
external:
api-key: ${REST_API_KEY}
EOL
# Gradle 빌드 및 애플리케이션 실행
./gradlew build -x test
nohup java -jar build/libs/*.jar > app.log 2>&1 &
EOF
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ plugins {

group = 'com.goormthon3'
version = '0.0.1-SNAPSHOT'
jar {
archiveBaseName.set("team49")
archiveVersion.set("1.0.0")
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

jar {
archiveBaseName.set("team49Server")
archiveVersion.set("0.0.1-SNAPSHOT")
}


configurations {
compileOnly {
extendsFrom annotationProcessor
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
spring:
application:
name: Team49 # ?????? ?? ??, ???? ?? ?? ? ??
name: Team49
datasource:
url: jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:team49}?useSSL=false&allowPublicKeyRetrieval=true # ?????? ?? URL, ???? ?? MySQL
username: ${DB_USERNAME:root} # ?????? ????, ?? ??? ?? ??
password: ${DB_PASSWORD:root} # ?????? ????, ?? ??? ?? ??
driver-class-name: com.mysql.cj.jdbc.Driver # MySQL JDBC ???? ????
username: ${DB_USERNAME:root}
password: ${DB_PASSWORD:root}
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update # Hibernate? ?????? ???? ???? ?? (update? ??? ?? ? ??? ??)
default_batch_fetch_size: 1000 # ?? ?? ? ? ?? ??? ???? ??
ddl-auto: update
default_batch_fetch_size: 1000
jdbc:
time_zone: Asia/Seoul # JDBC ???? ??? ??? ??
defer-datasource-initialization: true # ????? ???? ???? JPA ??? ?? ???? ?? ??
Expand Down

0 comments on commit 0b45833

Please sign in to comment.