|
| 1 | +🚀 CHEATSHEET - DÉPLOIEMENT AUTO GITHUB → VPS HOSTINGER |
| 2 | + |
| 3 | +⚡ Workflow |
| 4 | +Windows (local) → GitHub → GitHub Actions → VPS → Site Live |
| 5 | +________________________________________ |
| 6 | +✅ Dev Workflow |
| 7 | +git add . |
| 8 | +git commit -m "Message" |
| 9 | +git push |
| 10 | +➡️ Déploiement auto (~15s) |
| 11 | +________________________________________ |
| 12 | +📊 Suivi |
| 13 | +• GitHub → Repo → Actions |
| 14 | +• Statut : ✅ (ok) / ❌ (erreur) / 🔄 (en cours) |
| 15 | +• Logs : cliquer sur un run |
| 16 | +________________________________________ |
| 17 | +⚠️ Règle d’or |
| 18 | +• ❌ NE PAS modifier sur le VPS |
| 19 | +• ✅ Toujours : modifier → commit → git push |
| 20 | +________________________________________ |
| 21 | +🔧 Dépannage rapide |
| 22 | +1. Lire logs GitHub Actions |
| 23 | +2. Erreurs fréquentes : |
| 24 | +o Permission denied → clé SSH invalide |
| 25 | +o No such file → mauvais DEPLOYMENT_PATH |
| 26 | +o Host key verification failed → déjà géré |
| 27 | +3. Tester manuellement : |
| 28 | +ssh root@IP |
| 29 | +cd /var/www/site.com |
| 30 | +git pull origin main |
| 31 | +4. Relancer manuellement : GitHub → Actions → Run workflow |
| 32 | +________________________________________ |
| 33 | +🆕 Nouveau projet (raccourci) |
| 34 | +1. Créer repo GitHub |
| 35 | +2. Générer clés SSH |
| 36 | +3. Configurer VPS : /var/www/mon-site |
| 37 | +4. Ajouter workflow .github/workflows/deploy.yml |
| 38 | +5. Configurer 4 secrets : |
| 39 | +o HOSTINGER_HOST |
| 40 | +o HOSTINGER_USERNAME |
| 41 | +o HOSTINGER_SSH_KEY |
| 42 | +o DEPLOYMENT_PATH |
| 43 | +________________________________________ |
| 44 | +📋 Checklist |
| 45 | +• Repo GitHub ok |
| 46 | +• Clés SSH ok |
| 47 | +• Répertoire VPS ok |
| 48 | +• Workflow ajouté |
| 49 | +• Secrets configurés |
| 50 | +• Push effectué → déploiement ✅ |
| 51 | +________________________________________ |
| 52 | +🛡️ Sécurité |
| 53 | +• 1 clé SSH par projet |
| 54 | +• Rotation 6-12 mois |
| 55 | +• Secrets jamais en dur |
| 56 | +• VPS à jour + firewall |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +📖 README - Déploiement Automatique GitHub → VPS Hostinger |
| 61 | + |
| 62 | +🎯 Vue d'ensemble |
| 63 | + |
| 64 | +Ce système permet de déployer automatiquement votre code depuis GitHub vers votre VPS Hostinger à chaque git push sur la branche main. |
| 65 | + |
| 66 | +🏗️ Architecture du workflow |
| 67 | +Windows (Local) → GitHub → GitHub Actions → VPS Hostinger → Site Live |
| 68 | + |
| 69 | +________________________________________ |
| 70 | +✅ Workflow normal de développement |
| 71 | +1. Modifier le code localement (Windows / VS Code) |
| 72 | +2. Tester localement si nécessaire |
| 73 | + |
| 74 | +Commiter les changements : |
| 75 | +``` |
| 76 | +git add . |
| 77 | +git commit -m "Description de tes modifications" |
| 78 | +``` |
| 79 | + |
| 80 | +Pousser vers GitHub : |
| 81 | +``` |
| 82 | + git push |
| 83 | +``` |
| 84 | + |
| 85 | +✨ Déploiement automatique ! |
| 86 | +• GitHub Actions se déclenche automatiquement |
| 87 | +• Le code est déployé sur le VPS en ~15 secondes |
| 88 | +• Le site web est mis à jour |
| 89 | + |
| 90 | + |
| 91 | +________________________________________ |
| 92 | +📊 Surveiller les déploiements |
| 93 | +• GitHub Actions : https://github.com/TON_USERNAME/TON_REPO/actions |
| 94 | +• Statut des runs : ✅ (succès) / ❌ (échec) / 🔄 (en cours) |
| 95 | +• Logs détaillés : cliquer sur un run pour voir les détails |
| 96 | + |
| 97 | +________________________________________ |
| 98 | +⚠️ Que faire JAMAIS |
| 99 | + |
| 100 | +❌ NE JAMAIS modifier directement sur le VPS |
| 101 | +cd /var/www/tonsite.com |
| 102 | +nano index.html # ❌ Modifications perdues au prochain déploiement |
| 103 | + |
| 104 | +✅ Toujours modifier sur Windows puis git push |
| 105 | + |
| 106 | +cd "ton_projet_local" |
| 107 | +code index.html # Modifier dans VS Code |
| 108 | +git add index.html |
| 109 | +git commit -m "Update homepage" |
| 110 | +git push # Déploiement automatique |
| 111 | + |
| 112 | +________________________________________ |
| 113 | +🔧 Dépannage |
| 114 | + |
| 115 | +Workflow GitHub Actions en échec ❌ |
| 116 | +1. Vérifier les logs : |
| 117 | + GitHub → Repository → Actions → Cliquer sur le run en échec → Lire le message d'erreur dans la section "Deploy to Hostinger VPS" |
| 118 | +2. Erreurs communes : |
| 119 | + |
| 120 | +Erreur Cause probable Solution |
| 121 | +Permission denied Clé SSH invalide Vérifier HOSTINGER_SSH_KEY dans les secrets |
| 122 | +No such file or directory Chemin incorrect Vérifier DEPLOYMENT_PATH = /var/www/tonsite.com |
| 123 | +Host key verification failed Première connexion StrictHostKeyChecking=no (déjà configuré) |
| 124 | + |
| 125 | +Tester manuellement sur le VPS : |
| 126 | + |
| 127 | +ssh root@TON_IP_VPS |
| 128 | +cd /var/www/tonsite.com |
| 129 | +git status |
| 130 | +git pull origin main # Doit fonctionner sans erreur |
| 131 | + |
| 132 | +3. Forcer un déploiement manuel : |
| 133 | + GitHub → Repository → Actions → "Deploy to Hostinger VPS" → "Run workflow" |
| 134 | + |
| 135 | + |
| 136 | +________________________________________ |
| 137 | +🆕 Appliquer ce système à un nouveau projet |
| 138 | + |
| 139 | +Étape 1 : Préparer le nouveau projet |
| 140 | +cd "C:\chemin\vers\nouveau\projet" |
| 141 | +git init |
| 142 | +git remote add origin https://github.com/USERNAME/NOUVEAU_REPO.git |
| 143 | + |
| 144 | +Étape 2 : Créer les clés SSH |
| 145 | +ssh-keygen -t rsa -b 4096 -C "github-actions-nouveau-projet" -f %USERPROFILE%\.ssh\github_actions_nouveau_projet |
| 146 | +type %USERPROFILE%\.ssh\github_actions_nouveau_projet.pub |
| 147 | + |
| 148 | +Étape 3 : Configurer le VPS |
| 149 | +sudo mkdir -p /var/www/nouveau-site.com |
| 150 | +sudo chown -R www-data:www-data /var/www/nouveau-site.com |
| 151 | + |
| 152 | +echo "ssh-rsa AAAAB3...nouvelle_cle_publique...= github-actions-nouveau-projet" >> ~/.ssh/authorized_keys |
| 153 | + |
| 154 | +cd /var/www/nouveau-site.com |
| 155 | +git init |
| 156 | +git remote add origin https://github.com/USERNAME/NOUVEAU_REPO.git |
| 157 | +git config --global --add safe.directory /var/www/nouveau-site.com |
| 158 | + |
| 159 | +Étape 4 : Copier le workflow GitHub Actions |
| 160 | +Créer : .github/workflows/deploy-hostinger.yml |
| 161 | + |
| 162 | +``` |
| 163 | +name: Deploy to Hostinger VPS |
| 164 | +
|
| 165 | +on: |
| 166 | + push: |
| 167 | + branches: [ main ] |
| 168 | + workflow_dispatch: |
| 169 | +
|
| 170 | +jobs: |
| 171 | + deploy: |
| 172 | + runs-on: ubuntu-latest |
| 173 | + |
| 174 | + steps: |
| 175 | + - name: Checkout Repository |
| 176 | + uses: actions/checkout@v4 |
| 177 | + |
| 178 | + - name: Deploy to Hostinger VPS |
| 179 | + uses: appleboy/ssh-action@v1 |
| 180 | + with: |
| 181 | + host: ${{ secrets.HOSTINGER_HOST }} |
| 182 | + username: ${{ secrets.HOSTINGER_USERNAME }} |
| 183 | + key: ${{ secrets.HOSTINGER_SSH_KEY }} |
| 184 | + script: | |
| 185 | + set -e |
| 186 | + cd ${{ secrets.DEPLOYMENT_PATH }} |
| 187 | + git fetch origin main |
| 188 | + git reset --hard origin/main |
| 189 | + echo "Deployment completed at $(date)" |
| 190 | +``` |
| 191 | + |
| 192 | +Étape 5 : Configurer les secrets GitHub |
| 193 | +• HOSTINGER_HOST → TON_IP_VPS |
| 194 | +• HOSTINGER_USERNAME → root |
| 195 | +• HOSTINGER_SSH_KEY → clé privée complète |
| 196 | +• DEPLOYMENT_PATH → /var/www/nouveau-site.com |
| 197 | + |
| 198 | +Étape 6 : Premier déploiement |
| 199 | +git add .github/workflows/deploy-hostinger.yml |
| 200 | +git add . |
| 201 | +git commit -m "Initial commit with automated deployment" |
| 202 | +git push -u origin main |
| 203 | + |
| 204 | +________________________________________ |
| 205 | +📋 Checklist nouveau projet |
| 206 | +• Nouveau repository GitHub créé |
| 207 | +• Clés SSH générées et configurées |
| 208 | +• Répertoire VPS créé avec bonnes permissions |
| 209 | +• Workflow ajouté |
| 210 | +• 4 secrets GitHub configurés |
| 211 | +• Premier push effectué avec succès ✅ |
| 212 | +• Workflow GitHub Actions réussi ✅ |
| 213 | +• Site accessible sur le VPS ✅ |
| 214 | + |
| 215 | + |
| 216 | +________________________________________ |
| 217 | +🛡️ Bonnes pratiques de sécurité |
| 218 | + |
| 219 | +🔑 Gestion des clés SSH |
| 220 | +• Une paire de clés par projet (isolation) |
| 221 | +• Noms descriptifs : github_actions_[nom-projet] |
| 222 | +• Rotation tous les 6-12 mois |
| 223 | + |
| 224 | +🔒 Secrets GitHub |
| 225 | +• Jamais de secrets en dur dans le code |
| 226 | +• Principe du moindre privilège |
| 227 | +• Audit régulier |
| 228 | + |
| 229 | +🖥️ VPS |
| 230 | +• Mises à jour régulières |
| 231 | +• Firewall (ports 22, 80, 443 uniquement) |
| 232 | +• Monitoring des connexions SSH |
| 233 | + |
| 234 | +________________________________________ |
| 235 | +📈 Optimisations possibles |
| 236 | + |
| 237 | +🔔 Ajout de notifications |
| 238 | +- name: Notify on success |
| 239 | + if: success() |
| 240 | + run: echo "Deployment successful! 🎉" |
| 241 | + |
| 242 | +- name: Notify on failure |
| 243 | + if: failure() |
| 244 | + run: echo "Deployment failed! ❌" |
| 245 | + |
| 246 | +🧪 Tests automatiques avant déploiement |
| 247 | +- name: Run tests |
| 248 | + run: npm test |
| 249 | + |
| 250 | +- name: Deploy only if tests pass |
| 251 | + if: success() |
| 252 | + uses: appleboy/ssh-action@v1 |
| 253 | + |
| 254 | +💾 Backup automatique |
| 255 | +script: | |
| 256 | + # Backup avant déploiement |
| 257 | + tar -czf backup-$(date +%Y%m%d-%H%M%S).tar.gz /var/www/tonsite.com |
| 258 | + |
| 259 | + # Déploiement normal |
| 260 | + cd ${{ secrets.DEPLOYMENT_PATH }} |
| 261 | + git fetch origin main |
| 262 | + git reset --hard origin/main |
| 263 | + |
| 264 | +________________________________________ |
| 265 | +🆘 Support |
| 266 | +En cas de problème : |
| 267 | +• Vérifier les logs GitHub Actions |
| 268 | +• Tester manuellement sur le VPS |
| 269 | +• Vérifier les secrets GitHub |
| 270 | +• Consulter ce README |
0 commit comments