Skip to content

Merge branch 'main' of github.com:gntc-youth-it/hidden-treasure-be #2

Merge branch 'main' of github.com:gntc-youth-it/hidden-treasure-be

Merge branch 'main' of github.com:gntc-youth-it/hidden-treasure-be #2

name: Deploy to EC2
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew build -x test
env:
DB_HOST: ${{ secrets.DB_HOST }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
rm -f /home/ubuntu/app/*.jar
- name: Copy JAR
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
source: "build/libs/*.jar"
target: "/home/ubuntu/app"
strip_components: 2
- name: Restart Spring Boot App
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
sudo systemctl restart spring-app