diff --git a/.github/workflows/catalog-service-ci-cd.yml b/.github/workflows/catalog-service-ci-cd.yml index b936cbb1..f67c6b82 100644 --- a/.github/workflows/catalog-service-ci-cd.yml +++ b/.github/workflows/catalog-service-ci-cd.yml @@ -22,50 +22,51 @@ jobs: distribution: 'temurin' java-version: '17' - - name: Install SDKMAN! + - name: Install SDKMAN! and Quarkus run: | curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install quarkus - + - name: Build with Quarkus run: | - cd catalog/catalog-service/ - quarkus build + source "$HOME/.sdkman/bin/sdkman-init.sh" + cd catalog/catalog-service/ + quarkus build --uber-jar # Génère un fichier JAR exécutable - name: Run Tests run: | - cd catalog/catalog-service/ - quarkus test - - - name: Set Docker Image Tag - id: docker_tag - run: echo "tag=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV - - - name: Build Docker image - run: | - cd catalog/catalog-service/ - docker-compose up --build -d + source "$HOME/.sdkman/bin/sdkman-init.sh" + cd catalog/catalog-service/ + quarkus test - - name: Push Docker image - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - run: | - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - docker push /:${{ env.tag }} + - name: Archive JAR Artifact + uses: actions/upload-artifact@v3 + with: + name: service-catalog.jar + path: catalog/catalog-service/target/*-runner.jar # Chemin vers le JAR généré deploy: runs-on: ubuntu-latest needs: build steps: - - name: Deploy to VM + - name: Download JAR Artifact + uses: actions/download-artifact@v3 + with: + name: service-catalog.jar + path: ./ + + - name: Deploy JAR to VM uses: appleboy/ssh-action@master with: host: ${{ secrets.VM_HOST }} username: ${{ secrets.VM_USERNAME }} key: ${{ secrets.VM_SSH_KEY }} script: | - docker pull /:${{ needs.build.outputs.tag }} - docker-compose down - docker-compose up -d + # Crée un répertoire pour l'application s'il n'existe pas + mkdir -p ~/service-catalog + # Copie le fichier JAR sur la VM + scp service-catalog.jar ${{ secrets.VM_USERNAME }}@${{ secrets.VM_HOST }}:~/service-catalog/service-catalog.jar + # Redémarre l'application avec le nouveau JAR sur le port 8082 + pkill -f 'java.*service-catalog.jar' || true # Arrête l'ancienne instance + nohup java -jar ~/service-catalog/service-catalog.jar --server.port=8082 > ~/service-catalog/app.log 2>&1 &