From fef61f6563fc21c3dc0f9915605828a29aa91686 Mon Sep 17 00:00:00 2001 From: ZeinebMESSAOUDI <130365664+Zeineb2001@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:07:48 +0100 Subject: [PATCH] Update search-ci-cd.yml --- .github/workflows/search-ci-cd.yml | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/.github/workflows/search-ci-cd.yml b/.github/workflows/search-ci-cd.yml index 5390bb10..3da26fb3 100644 --- a/.github/workflows/search-ci-cd.yml +++ b/.github/workflows/search-ci-cd.yml @@ -51,3 +51,46 @@ jobs: - name: Verify if the correct JAR file exists run: | ls search/target/service-search.jar || (echo "JAR file not found!" && exit 1) + + - name: Add Server to Known Hosts + run: | + mkdir -p ~/.ssh + ssh-keyscan -H ${{ secrets.DEPLOYMENT_MACHINE_IP }} >> ~/.ssh/known_hosts + + - name: Transfer JAR to VPS + run: | + sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" scp ./search/target/service-search.jar \ + ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }}:~/service-search/service-search.jar + + - name: Verify if the JAR file exists on the VPS + run: | + sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" ssh ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }} \ + "ls -l ~/service-search/service-search.jar" + + - name: Show system resources usage after file transfer + run: | + sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" ssh ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }} \ + "df -h && free -h && top -bn1 | grep 'Cpu(s)'" + + - name: Deploy JAR to VPS + uses: appleboy/ssh-action@v0.1.2 + with: + host: ${{ secrets.DEPLOYMENT_MACHINE_IP }} + username: ${{ secrets.DEPLOYMENT_MACHINE_USER }} + password: ${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }} + script: | + sleep 10 + + echo "Starting Spring Boot service..." + cd ~/service-search + nohup java -jar service-search.jar --server.port=8089 > service-search.log 2>&1 & + echo "Spring Boot service deployed successfully!" + + sleep 30 + + echo "Performing health check..." + curl -X 'GET' 'http://localhost:8089/actuator/health' -H 'accept: application/json' || (echo "Service health check failed!" && exit 1) + + echo "Service deployed and healthy!" + + tail -n 50 ~/service-search/service-search.log