-
Notifications
You must be signed in to change notification settings - Fork 1
55 lines (48 loc) · 1.74 KB
/
gradle-publish.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
name: CD with Gradle & Deploy
on:
pull_request:
types:
- closed
jobs:
if_merged:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Set YML
run: |
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_YML }}" > src/main/resources/application.yml
find src
- name: Make Gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: build
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: cicdsample
path: build/libs/game-0.0.1-SNAPSHOT.jar
deploy:
needs: if_merged
runs-on: ubuntu-latest
steps:
- name: Download build artifacts
uses: actions/download-artifact@v2
with:
name: cicdsample
path: build/libs/
- name: Deploy to EC2
run: |
echo "${{ secrets.SERVER_SSH_KEY }}" > private_key.pem
chmod 600 private_key.pem
scp -i private_key.pem -o StrictHostKeyChecking=no build/libs/game-0.0.1-SNAPSHOT.jar ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_HOST }}:/home/${{ secrets.SERVER_USERNAME }}/game.jar
ssh -i private_key.pem -o StrictHostKeyChecking=no ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_HOST }} "sudo lsof -ti:80 | xargs sudo kill -9; sudo nohup java -jar /home/${{ secrets.SERVER_USERNAME }}/game.jar > app.log 2>&1 &"
rm -f private_key.pem