Deploy to Ubuntu Server #46
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
name: Deploy to Ubuntu Server | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- 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: 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.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
source: 'userService/target/*.jar' | |
target: '/home/${{ secrets.SERVER_USERNAME }}/myJavaProjects/weatherProject/userService' | |
port: 22 | |
timeout: 30s | |
command_timeout: 10m | |
use_insecure_cipher: false | |
rm: false | |
debug: false | |
strip_components: 0 | |
overwrite: false | |
tar_dereference: false | |
tar_exec: tar | |
proxy_port: 22 | |
proxy_timeout: 30s | |
proxy_use_insecure_cipher: false | |
- name: SSH into server and restart userService | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
sudo systemctl stop userService || true | |
sudo cp /home/${{ secrets.SERVER_USERNAME }}/myJavaProjects/weatherProject/userService/*.jar /opt/userService/ | |
sudo systemctl start userService |