forked from codesquad-members-2024/issue-tracker
-
Notifications
You must be signed in to change notification settings - Fork 3
63 lines (52 loc) · 1.92 KB
/
deploy.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
name: Deploy Spring Boot Application to EC2
on:
push:
branches: [be/dev2-setting]
pull_request:
branches: [be/dev2-setting]
jobs:
build_and_deploy:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt' # 오류나면 Correto로 변경하기
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}
- name: Build with Gradle
run: ./gradlew clean build -x test
working-directory: /be/issue-tracker/
- name: Archive JAR
uses: actions/upload-artifact@v2
with:
name: spring-boot-app
path: build/libs/*.jar
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2 # 원하는 리전으로 수정
- name: Transfer JAR to EC2 (Root 계정 사용 시)
run: |
scp -o StrictHostKeyChecking=no root@${{ secrets.EC2_HOST }}:/root/spring-boot-app.jar
- name: Deploy on EC2 (Root 계정 사용 시)
run: |
ssh -o StrictHostKeyChecking=no root@${{ secrets.EC2_HOST }} << 'EOF'
# Stop existing application
pkill -f 'java.*spring-boot-app.jar'
# Start new application
export DB_USERNAME=${{ secrets.DB_USERNAME }}
export DB_PASSWORD=${{ secrets.DB_PASSWORD }}
nohup java -jar /root/spring-boot-app.jar > /dev/null 2>&1 &
EOF