Verify Server Resources #26
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: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- service-catalog | |
pull_request: | |
branches: | |
- service-catalog | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Build with Maven | |
run: | | |
cd catalog/catalog-service/ | |
mvn clean package -Dquarkus.package.type=uber-jar | |
- name: Archive JAR Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: service-catalog.jar | |
path: catalog/catalog-service/target/*-runner.jar | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Install sshpass | |
run: sudo apt-get install -y sshpass | |
- name: Download JAR Artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: service-catalog.jar | |
path: ./ | |
- name: List files to verify download | |
run: | | |
echo "Listing files in the current directory:" | |
ls -l /home/runner/work/projet-soa-ecommerce-enit-2024-3AINFO2/projet-soa-ecommerce-enit-2024-3AINFO2 | |
- name: Verify if the correct JAR file exists | |
run: | | |
ls /home/runner/work/projet-soa-ecommerce-enit-2024-3AINFO2/projet-soa-ecommerce-enit-2024-3AINFO2/catalog-service-1.0.0-SNAPSHOT-runner.jar | |
- 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: | | |
# Vérification de la présence du fichier téléchargé | |
if [ -f "./catalog-service-1.0.0-SNAPSHOT-runner.jar" ]; then | |
echo "File exists, proceeding with SCP transfer" | |
sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" scp ./catalog-service-1.0.0-SNAPSHOT-runner.jar ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }}:~/service-catalog/service-catalog.jar | |
else | |
echo "File not found, aborting transfer" | |
exit 1 | |
fi | |
- 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-catalog/service-catalog.jar" | |
- name: Show system resources usage after file transfer | |
run: | | |
# Vérifier l'utilisation des ressources sur le serveur après le transfert | |
echo "Utilisation des ressources sur le serveur VPS après transfert :" | |
# Vérification de l'espace disque utilisé | |
echo "Espace disque utilisé :" | |
sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" ssh ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }} "df -h" | |
# Vérification de l'utilisation de la mémoire | |
echo "Mémoire utilisée :" | |
sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" ssh ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }} "free -h" | |
# Vérification de l'utilisation du CPU | |
echo "Utilisation du CPU :" | |
sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" ssh ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }} "top -bn1 | grep 'Cpu(s)'" | |
- name: Set execute permissions for the JAR file | |
run: | | |
sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" ssh ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }} "chmod +x ~/service-catalog/service-catalog.jar" | |
- 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: | | |
mkdir -p ~/service-catalog | |
# Tuer le processus existant Java si présent | |
pkill -f 'java.*service-catalog.jar' || true | |
# Attendre 5 secondes avant de relancer le service | |
sleep 5 | |
# Lancer le service en arrière-plan | |
java -jar ~/service-catalog/service-catalog.jar --server.port=8082 > ~/service-catalog/app.log 2>&1 & | |
# Vérification des logs pour détecter des erreurs | |
tail -n 10 ~/service-catalog/app.log |