-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (58 loc) · 2.21 KB
/
cicd.yml
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: [ main ]
jobs:
build:
runs-on: ubuntu-latest # 실행 환경 지정
# 실행 스텝 지정
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
# application.properties 파일 설정
- name: Setup application properties
run: |
echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.properties
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run : ./gradlew clean build -x test
# 빌드해서 생긴 JAR 파일을 깃허브 아티팩트로 업로드!!
- name: Upload build artifact
uses: actions/upload-artifact@v2
with:
name: outstagram
path: build/libs/outstagram-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: Download build artifact
uses: actions/download-artifact@v2
with:
name: outstagram
path: build/libs/
- name: EC2 Deploy
env:
EC2_SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER }}
run: |
# SSH Key 파일 생성
echo "$EC2_SSH_PRIVATE_KEY" > ec2_ssh_key
chmod 600 ec2_ssh_key
# 패키지 파일을 EC2 인스턴스로 복사
scp -i ec2_ssh_key -o StrictHostKeyChecking=no build/libs/outstagram-0.0.1-SNAPSHOT.jar ${EC2_USER}@${EC2_HOST}:/home/${EC2_USER}/outstagram
# 인스턴스에서 JAR 파일 실행
ssh -i ec2_ssh_key -o StrictHostKeyChecking=no ${EC2_USER}@${EC2_HOST} "pgrep java | xargs kill -9; nohup java -jar /home/${EC2_USER}/outstagram/outstagram-0.0.1-SNAPSHOT.jar > /home/${EC2_USER}/outstagram/log/app.log 2>&1 &"