From 5a3a44d7f695722e23a6e9c71c1c4b00e09eff63 Mon Sep 17 00:00:00 2001 From: Kerboul Date: Thu, 24 Apr 2025 00:15:16 +0200 Subject: [PATCH] =?UTF-8?q?Refactor=20le=20workflow=20de=20d=C3=A9ploiemen?= =?UTF-8?q?t=20pour=20simplifier=20la=20connexion=20SSH=20et=20ex=C3=A9cut?= =?UTF-8?q?er=20une=20commande=20de=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yml | 48 +++++++++---------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 3faf0ea..7fc249a 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -1,48 +1,22 @@ -# Le fichier .gitea-ci.yml pour Gitea CI/CD +name: SSH Hello on: push: branches: - - main # Déclenche l'action pour la branche principale + - main jobs: - - deployment: + ssh-hello: runs-on: ubuntu-latest + steps: - # Étape 1: Setup SSH - - name: Setup SSH and Add Private Key + - name: Write SSH Key run: | - # Créez un dossier pour stocker les clés SSH - mkdir -p ~/.ssh + echo "$SSH_PRIVATE_KEY" > id_rsa + chmod 600 id_rsa + env: + SSH_PRIVATE_KEY: ${{ vars.SSH_PRIVATE_KEY }} - # Ajoutez la clé privée stockée dans le secret à un fichier id_rsa - echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa - - # Protéger les permissions du fichier de la clé privée - chmod 600 ~/.ssh/id_rsa - - # Ajoutez l'hôte distant à known_hosts pour éviter les erreurs de vérification de l'host - ssh-keyscan -H 192.168.1.87 >> ~/.ssh/known_hosts - - # Vérifiez les permissions du fichier id_rsa (optionnel, juste pour être sûr) - ls -l ~/.ssh/id_rsa - - # Étape 2: Test SSH Connection - - name: Test SSH connection + - name: Run SSH Hello run: | - # Testez la connexion SSH avec l'hôte distant - ssh -v kerboul@192.168.1.87 "echo 'Connection successful!'" - - # Étape 3: Ajouter une action qui utilise la connexion SSH - - name: Run remote command - run: | - # Exemple de commande distante exécutée sur le serveur distant via SSH - ssh kerboul@192.168.1.87 "cd /home/kerboul/scripts/timelapse && ./update_timelapse.sh -o" - - # Étape 4: Nettoyage (optionnel) - - name: Clean up SSH keys - run: | - # Supprimer la clé privée pour des raisons de sécurité (optionnel) - rm -f ~/.ssh/id_rsa - rm -f ~/.ssh/known_hosts \ No newline at end of file + ssh -i id_rsa -o StrictHostKeyChecking=no ${{ vars.SSH_USER }}@${{ vars.SSH_HOST }} "echo 'Hello from Gitea Action!'"