-
Notifications
You must be signed in to change notification settings - Fork 0
44 lines (35 loc) · 1.21 KB
/
deploy.yml
File metadata and controls
44 lines (35 loc) · 1.21 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
name: Deploy to EC2
on:
push:
branches:
- main # main 브랜치 push 시 자동 배포
jobs:
build-and-deploy:
name: Build and Deploy to EC2 Server
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build -x test
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
- name: Securely copy JAR file to EC2
run: |
scp -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no \
./build/libs/Debug_Visual-0.0.1-SNAPSHOT.jar \
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:"/home/ec2-user/Zivorp_Backend/Debug_Visual-0.0.1-SNAPSHOT.jar"
- name: SSH and run deploy script
run: |
ssh ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} "cd ~ && ./deploy.sh"