Files
innotexBoard/DOCKER_EXAMPLES.sh
innotex c51592c7ea feat: Add Docker image update system (TrueNAS Scale inspired)
- Implement UpdateService for image version checking and atomic updates
- Add DockerComposeManager for centralized docker-compose management
- Create 12 docker-compose references in /home/innotex/Docker
- Add 13 new API endpoints (6 for images, 7 for compose management)
- Add comprehensive documentation and examples
2026-01-16 19:37:23 +01:00

333 lines
9.7 KiB
Bash

#!/bin/bash
# ============================================
# Exemples d'utilisation du système de mise à jour Docker
# Inspiré de TrueNAS Scale
# ============================================
# Configuration
API="http://localhost:8000/api/v1"
AUTH_TOKEN="your-auth-token-here"
# Couleurs
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Exemples d'utilisation - Mise à jour Docker${NC}"
echo -e "${BLUE}========================================${NC}\n"
# ============================================
# 1. GESTION DES IMAGES
# ============================================
echo -e "${YELLOW}1. GESTION DES IMAGES${NC}\n"
echo -e "${GREEN}Lister toutes les images locales:${NC}"
echo "curl -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/images"
echo ""
echo -e "${GREEN}Vérifier si portainer a une mise à jour:${NC}"
echo "curl -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/images/check-update/portainer/portainer-ce:latest"
echo ""
echo -e "${GREEN}Vérifier TOUTES les mises à jour disponibles:${NC}"
echo "curl -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/images/check-all-updates"
echo ""
echo -e "${GREEN}Réponse attendue:${NC}"
cat << 'EOF'
{
"total_containers": 3,
"containers_with_updates": 1,
"updates": [
{
"container": "portainer",
"update": {
"image": "portainer/portainer-ce:latest",
"current_tag": "latest",
"latest_tag": "2.19.3",
"has_update": true,
"registry": "docker.io"
}
}
]
}
EOF
echo ""
# ============================================
# 2. TÉLÉCHARGER UNE IMAGE
# ============================================
echo -e "\n${YELLOW}2. TÉLÉCHARGER UNE IMAGE${NC}\n"
echo -e "${GREEN}Télécharger la dernière version de portainer:${NC}"
echo "curl -X POST -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " -H \"Content-Type: application/json\" \\"
echo " -d '{\"image\":\"portainer/portainer-ce\",\"tag\":\"latest\"}' \\"
echo " $API/docker/images/pull"
echo ""
# ============================================
# 3. METTRE À JOUR UN CONTENEUR
# ============================================
echo -e "\n${YELLOW}3. METTRE À JOUR UN CONTENEUR${NC}\n"
echo -e "${GREEN}Workflow complet de mise à jour:${NC}"
echo ""
echo "# Étape 1: Obtenir l'ID du conteneur"
echo "CONTAINER_ID=\$(docker ps | grep portainer | awk '{print \$1}')"
echo ""
echo "# Étape 2: Appeler l'API de mise à jour"
echo "curl -X POST -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " -H \"Content-Type: application/json\" \\"
echo " -d '{\"new_image\":\"portainer/portainer-ce\",\"new_tag\":\"2.19.3\"}' \\"
echo " $API/docker/containers/\$CONTAINER_ID/update-image"
echo ""
echo -e "${GREEN}Réponse attendue:${NC}"
cat << 'EOF'
{
"success": true,
"message": "Conteneur portainer mis à jour avec succès",
"old_image": "portainer/portainer-ce:latest",
"new_image": "portainer/portainer-ce:2.19.3"
}
EOF
echo ""
# ============================================
# 4. NETTOYER LES IMAGES
# ============================================
echo -e "\n${YELLOW}4. NETTOYER LES IMAGES ORPHELINES${NC}\n"
echo -e "${GREEN}Nettoyer les images non utilisées:${NC}"
echo "curl -X POST -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/images/prune?dangling_only=true"
echo ""
echo -e "${GREEN}Réponse attendue:${NC}"
cat << 'EOF'
{
"success": true,
"deleted_images": 3,
"space_freed_mb": "234.56",
"details": [...]
}
EOF
echo ""
# ============================================
# 5. GESTION DES DOCKER-COMPOSE
# ============================================
echo -e "\n${YELLOW}5. GESTION DES DOCKER-COMPOSE${NC}\n"
echo -e "${GREEN}Lister tous les docker-compose disponibles:${NC}"
echo "curl -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/compose/list"
echo ""
echo -e "${GREEN}Réponse attendue:${NC}"
cat << 'EOF'
[
{
"name": "portainer",
"file": "docker-compose.portainer.yml",
"path": "/home/innotex/Docker/docker-compose.portainer.yml",
"exists": true
},
{
"name": "sonarr",
"file": "docker-compose.sonarr.yml",
"path": "/home/innotex/Docker/docker-compose.sonarr.yml",
"exists": true
},
...
]
EOF
echo ""
# ============================================
# 6. CONTRÔLER UN DOCKER-COMPOSE
# ============================================
echo -e "\n${YELLOW}6. CONTRÔLER UN DOCKER-COMPOSE${NC}\n"
echo -e "${GREEN}Vérifier l'état de Portainer:${NC}"
echo "curl -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/compose/portainer/status"
echo ""
echo -e "${GREEN}Démarrer Portainer:${NC}"
echo "curl -X POST -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/compose/portainer/start"
echo ""
echo -e "${GREEN}Arrêter Portainer:${NC}"
echo "curl -X POST -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/compose/portainer/stop"
echo ""
echo -e "${GREEN}Redémarrer Portainer:${NC}"
echo "curl -X POST -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/compose/portainer/restart"
echo ""
echo -e "${GREEN}Arrêter et supprimer Portainer (down):${NC}"
echo "curl -X POST -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/compose/portainer/down"
echo ""
# ============================================
# 7. METTRE À JOUR LES IMAGES D'UN DOCKER-COMPOSE
# ============================================
echo -e "\n${YELLOW}7. METTRE À JOUR LES IMAGES D'UN DOCKER-COMPOSE${NC}\n"
echo -e "${GREEN}Télécharger les dernières images pour Portainer:${NC}"
echo "curl -X POST -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " $API/docker/compose/portainer/pull"
echo ""
# ============================================
# 8. RÉCUPÉRER LES LOGS
# ============================================
echo -e "\n${YELLOW}8. RÉCUPÉRER LES LOGS D'UN DOCKER-COMPOSE${NC}\n"
echo -e "${GREEN}Récupérer les 100 dernières lignes de logs:${NC}"
echo "curl -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " \"$API/docker/compose/portainer/logs?tail=100\""
echo ""
echo -e "${GREEN}Récupérer les 50 dernières lignes:${NC}"
echo "curl -H \"Authorization: Bearer $AUTH_TOKEN\" \\"
echo " \"$API/docker/compose/portainer/logs?tail=50\""
echo ""
# ============================================
# 9. SCRIPTS BASH - AUTOMATISATION
# ============================================
echo -e "\n${YELLOW}9. SCRIPTS BASH - AUTOMATISATION${NC}\n"
echo -e "${GREEN}Script: Mettre à jour tous les services avec le label update-enabled:${NC}"
cat << 'BASHSCRIPT'
#!/bin/bash
API="http://localhost:8000/api/v1"
TOKEN="your-token"
# Récupérer tous les docker-compose
COMPOSES=$(curl -s -H "Authorization: Bearer $TOKEN" $API/docker/compose/list | jq -r '.[].name')
for COMPOSE in $COMPOSES; do
echo "Mise à jour de $COMPOSE..."
# Télécharger les nouvelles images
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
$API/docker/compose/$COMPOSE/pull
# Redémarrer les services
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
$API/docker/compose/$COMPOSE/restart
echo "✓ $COMPOSE mis à jour"
done
# Nettoyer les images orphelines
echo "Nettoyage des images orphelines..."
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
$API/docker/images/prune
echo "✓ Nettoyage terminé"
BASHSCRIPT
echo ""
# ============================================
# 10. MONITORING - RECHERCHER DES MISES À JOUR CHAQUE JOUR
# ============================================
echo -e "\n${YELLOW}10. MONITORING - CRON JOB${NC}\n"
echo -e "${GREEN}Ajouter à crontab pour vérifier les mises à jour chaque jour à 6h:${NC}"
echo "0 6 * * * curl -s -H \"Authorization: Bearer $TOKEN\" \\"
echo " $API/docker/images/check-all-updates | \\"
echo " jq 'if .containers_with_updates > 0 then \"Mises à jour disponibles!\" else empty end'"
echo ""
# ============================================
# 11. LANCER PLUSIEURS DOCKER-COMPOSE
# ============================================
echo -e "\n${YELLOW}11. LANCER PLUSIEURS DOCKER-COMPOSE${NC}\n"
echo -e "${GREEN}Script: Lancer le stack complet (Portainer + Monitoring):${NC}"
cat << 'BASHSCRIPT'
#!/bin/bash
API="http://localhost:8000/api/v1"
TOKEN="your-token"
SERVICES=("portainer" "monitoring" "jellyfin")
for SERVICE in "${SERVICES[@]}"; do
echo "Démarrage de $SERVICE..."
curl -X POST -H "Authorization: Bearer $TOKEN" \
$API/docker/compose/$SERVICE/start
sleep 2
done
echo "✓ Tous les services sont démarrés"
# Vérifier les statuts
for SERVICE in "${SERVICES[@]}"; do
curl -H "Authorization: Bearer $TOKEN" \
$API/docker/compose/$SERVICE/status | jq '.count'
done
BASHSCRIPT
echo ""
# ============================================
# RÉSUMÉ
# ============================================
echo -e "\n${BLUE}========================================${NC}"
echo -e "${BLUE}RÉSUMÉ${NC}"
echo -e "${BLUE}========================================${NC}\n"
echo -e "${GREEN}✓ Images Management:${NC}"
echo " - Lister, vérifier, télécharger, mettre à jour, nettoyer"
echo ""
echo -e "${GREEN}✓ Docker Compose Management:${NC}"
echo " - Lister, vérifier état, démarrer, arrêter, redémarrer"
echo ""
echo -e "${GREEN}✓ Automatisation:${NC}"
echo " - Scripts bash pour mise à jour batch"
echo " - Cron jobs pour monitoring"
echo " - Orchestration complète"
echo ""
echo -e "${BLUE}Documentation:${NC}"
echo " - DOCKER_UPDATE_SYSTEM.md"
echo " - /home/innotex/Docker/README.md"
echo " - docker-compose-registry.json"
echo ""
echo -e "${YELLOW}Pour commencer:${NC}"
echo " 1. Remplacer YOUR_AUTH_TOKEN par votre token valide"
echo " 2. Tester: curl http://localhost:8000/api/v1/docker/status"
echo " 3. Consulter la documentation complète"
echo ""