diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 649e875..0e282eb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy to VPS +name: Deploy to Ubuntu Server on: push: @@ -6,7 +6,7 @@ on: - main jobs: - build: + deploy: runs-on: ubuntu-latest steps: @@ -14,30 +14,39 @@ jobs: 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/scp-action@v0.1.2 + - 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 \ No newline at end of file + sudo systemctl start userService