Refactor le workflow de déploiement pour simplifier la connexion SSH et exécuter une commande de test
All checks were successful
SSH Hello / ssh-hello (push) Successful in 2s
All checks were successful
SSH Hello / ssh-hello (push) Successful in 2s
This commit is contained in:
@@ -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
|
||||
ssh -i id_rsa -o StrictHostKeyChecking=no ${{ vars.SSH_USER }}@${{ vars.SSH_HOST }} "echo 'Hello from Gitea Action!'"
|
||||
|
||||
Reference in New Issue
Block a user