-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (57 loc) · 2.18 KB
/
cicd.yml
File metadata and controls
73 lines (57 loc) · 2.18 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
name: CI/CD
# 워크플로가 시작될 조건 지정
on:
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest # 실행 환경 지정
# 실행 스텝 지정
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
# application.yml 파일 설정
- name: Setup application yml
run: |
echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.yml
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run : ./gradlew clean build -x test -Dfile.encoding=UTF-8
# 빌드해서 생긴 JAR 파일을 깃허브 아티팩트로 업로드
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: interview
path: build/libs/interview-0.0.1-SNAPSHOT.jar
deploy:
needs: build
runs-on: ubuntu-latest
steps:
# 현재 시간 가져오기
- name: Get current time
uses: josStorer/[email protected]
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"
- name: Install sshpass
run: sudo apt-get install -y sshpass
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: interview
path: build/libs/
- name: NCP Deploy
env:
NCP_PASSWORD: ${{ secrets.NCP_PASSWORD }}
NCP_HOST: ${{ secrets.NCP_HOST }}
NCP_USER: ${{ secrets.NCP_USER }}
run: |
# 패키지 파일을 NCP 인스턴스로 복사
sshpass -p "$NCP_PASSWORD" scp -o StrictHostKeyChecking=no build/libs/interview-0.0.1-SNAPSHOT.jar ${NCP_USER}@${NCP_HOST}:/home/interview-server
# 인스턴스에서 JAR 파일 실행
sshpass -p "$NCP_PASSWORD" ssh -o StrictHostKeyChecking=no ${NCP_USER}@${NCP_HOST} "pgrep java | xargs kill -9; nohup java -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Seoul -jar /home/interview-server/interview-0.0.1-SNAPSHOT.jar >> /home/log/app.log 2>> /home/log/error.log &"