-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (91 loc) · 2.83 KB
/
dev_deploy.yml
File metadata and controls
106 lines (91 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: idedu backend CI/DE
on:
push:
branches:
- develop
permissions:
contents: read
jobs:
build:
name: Build in Github Actions
runs-on: ubuntu-22.04
steps:
# 저장소 Checkout하여 코드 가져오기
- name: Checkout branch
uses: actions/checkout@v3
# 최신 커밋 출력하기 (확인용)
- name: Show latest commit
run: |
latest_commit=$(git log -1 --pretty=format:"%h %s (%an)")
echo "Latest commit: $latest_commit"
# Java 버전 세팅
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'zulu'
# yml 파일 복사
- name: Copy secret
env:
APPLICATION_FILE: ${{ secrets.APPLICATION_PROFILE }}
APPLICATION_FILE_NAME: application.yml
DIR: ./src/main/resources
run: |
touch $DIR/$APPLICATION_FILE_NAME
echo "$APPLICATION_FILE" > $DIR/$APPLICATION_FILE_NAME
# gradlew 실행 권한 부여
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
shell: bash
# JAR 파일 생성
- name: Build with Gradle
run: ./gradlew clean build -x test
shell: bash
# jar 및 소스코드 업로드
- name: Upload Build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
build/libs/*-SNAPSHOT.jar
src/main/java/com/gdg/backend
deploy:
name: Deliver using SSH
needs: build
runs-on: ubuntu-22.04
steps:
# jar 및 소스코드 다운로드
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
# SCP로 jar 파일 EC2에 배포
- name: SCP JAR to EC2
uses: appleboy/scp-action@master
with:
key: ${{ secrets.EC2_KEY }}
host: ${{ secrets.EC2_HOST }}
username: ubuntu
source: "build/libs/*.jar"
target: "/home/ubuntu/app"
# SCP로 소스코드 EC2에 붙여넣기 (확인용)
- name: SCP project source code to EC2
uses: appleboy/scp-action@master
with:
key: ${{ secrets.EC2_KEY }}
host: ${{ secrets.EC2_HOST }}
username: ubuntu
source: "src/"
target: "/home/ubuntu/app"
# jar 실행
- name: Deploy SSH
uses: appleboy/ssh-action@master
with:
key: ${{ secrets.EC2_KEY }}
host: ${{ secrets.EC2_HOST }}
username: ubuntu
# 8080 포트에서 실행 중인 서버 종료 후 재실행
script: |
sudo fuser -k -n tcp 8080
sleep 15
sudo nohup java -jar -Duser.timezone=Asia/Seoul ./app/build/libs/*.jar > ./nohup.out 2>&1 &