Skip to content

Commit

Permalink
Update deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
XyL1GaN4eG committed Jul 17, 2024
1 parent 98ca601 commit 7010069
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
name: Deploy to VPS
name: Deploy to Ubuntu Server

on:
push:
branches:
- main

jobs:
build:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v2
with:
distribution: 'adopt'
distribution: 'temurin'
java-version: '17'

- name: Build with Maven
run: mvn clean package
- name: Set environment variables
run: |
echo "DB_URL=${{ secrets.DB_URL }}" >> $GITHUB_ENV
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> $GITHUB_ENV
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> $GITHUB_ENV
- name: Copy files via SSH
uses: appleboy/[email protected]
- name: Debug environment variables
run: printenv

- name: Build userService
run: mvn -e -X -B package --file userService/pom.xml

- name: Deploy userService to Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "target/myapp.jar"
target: "/home/${{ secrets.SSH_USER }}/myJavaProjects/weatherProject/userService"

- name: Execute remote SSH commands
uses: appleboy/ssh-action@v0.1.2
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: 'userService/target/*.jar'
target: '/home/xyl1gan4eg/myJavaProjects/weatherProject/userService'

- name: SSH into server and restart userService
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
sudo systemctl stop userService
sudo systemctl stop userService || true
sudo cp /home/xyl1gan4eg/myJavaProjects/weatherProject/userService/*.jar /opt/userService/
sudo systemctl start userService
sudo systemctl start userService

0 comments on commit 7010069

Please sign in to comment.