-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98ca601
commit 7010069
Showing
1 changed file
with
30 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |