-
Notifications
You must be signed in to change notification settings - Fork 2
61 lines (48 loc) · 1.79 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
name: ALGOHUB Deploy
on:
push:
branches:
- develop
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: JDK 21 Setup
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: CREDENTIAL_NAME, CREDENTIAL_PW
run: |
echo "CREDENTIAL_NAME=${{ secrets.CREDENTIAL_NAME }}" >> $GITHUB_ENV
echo "CREDENTIAL_PW=${{ secrets.CREDENTIAL_PW }}" >> $GITHUB_ENV
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
uses: gradle/[email protected]
with:
arguments: build -Dspring.profiles.active=prod -x test
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: algohub
path: build/libs/algohub-0.0.1-SNAPSHOT.jar
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: algohub
path: build/libs/
- name: Deploy to EC2
run: |
echo "${{ secrets.EC2_SSH_KEY }}" > private_key.pem
chmod 400 private_key.pem
sudo scp -i private_key.pem -o StrictHostKeyChecking=no build/libs/algohub-0.0.1-SNAPSHOT.jar ${{ secrets.EC2_USERNAME }}@${{ secrets.EC2_HOST }}:/home/${{ secrets.EC2_USERNAME }}/algohub.jar
sudo ssh -i private_key.pem -o StrictHostKeyChecking=no ${{ secrets.EC2_USERNAME }}@${{ secrets.EC2_HOST }} "pgrep java | xargs kill -9; nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=prod /home/${{ secrets.EC2_USERNAME }}/algohub.jar > app.log 2>&1 &"
rm -f private_key.pem