33800 Docs

← Retour

Smart-Deploy System - Documentation Complète

Date de création: 20/01/2026 Status: Phases 1-6 terminées, Phase 7+ à faire

Vue d'ensemble

Système de déploiement hybride combinant GitLab CI/CD avec des scripts bash modulaires pour supporter plusieurs stratégies de déploiement (Docker, Files, Remote).

┌─────────────────────────────────────────────────────────────────┐
│                      SMART-DEPLOY SYSTEM                         │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  git push → GitLab CI → Runner → smart-deploy.sh                │
│                                       │                          │
│                    ┌──────────────────┼──────────────────┐       │
│                    ▼                  ▼                  ▼       │
│               [docker.sh]        [files.sh]        [remote.sh]   │
│                    │                  │                  │       │
│                    ▼                  ▼                  ▼       │
│              prod-portainer      nginx/pve          o2switch     │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

Phase 1 - Infrastructure de base

GitLab CI Templates

Scripts créés

/stock_8to/33800-stack/scripts/deploy/
├── smart-deploy.sh          # Script principal
├── machines-registry.json   # Registre des machines cibles
├── lib/
│   ├── common.sh            # Fonctions utilitaires (log_*, require_var)
│   ├── parse-yaml.sh        # Parser YAML pour conf.gouroubleu.yml
│   ├── targets.sh           # Résolution des targets
│   └── services.sh          # Injection variables de services
├── strategies/
│   ├── docker.sh            # Déploiement Docker
│   ├── files.sh             # Déploiement fichiers (releases)
│   └── remote.sh            # Déploiement distant (rsync/git)
└── templates/
    └── ...                  # Templates Dockerfile et nginx

Machines Registry

{
  "machines": {
    "prod-portainer": { "type": "docker", "ip": "192.168.1.12" },
    "nginx": { "type": "files", "ip": "192.168.1.104" },
    "o2switch": { "type": "remote", "host": "yellow.o2switch.net", "ssh_alias": "o2switch" }
  }
}

Phase 2 - Stratégie Docker

Templates Dockerfile créés

/stock_8to/33800-stack/scripts/deploy/templates/
├── Dockerfile.node          # Node.js
├── Dockerfile.bun           # Bun runtime
├── Dockerfile.python        # Python
├── Dockerfile.rust          # Rust
├── Dockerfile.static        # Sites statiques
├── Dockerfile.qwik          # Qwik SSR
└── Dockerfile.next          # Next.js

Fonctionnalités docker.sh


Phase 3 - Services & Variables

services.sh

Injection automatique des variables d'environnement selon les services déclarés.

# conf.gouroubleu.yml
services:
  - supabase
  - redis
  - ntfy

Variables injectées

Service Variables
supabase DATABASE_URL, SUPABASE_URL, SUPABASE_ANON_KEY
redis REDIS_URL
ntfy NTFY_URL, NTFY_TOPIC
ai ORCHESTRATOR_URL, WIN11_HOST
monitoring GRAFANA_URL, PROMETHEUS_URL, LOKI_URL
gitlab GITLAB_URL, GITLAB_TOKEN

Phase 4 - DNS & Nginx

lib/dns.sh

lib/nginx.sh

Templates Nginx

templates/
├── nginx-api.conf.template      # API avec rate limiting
├── nginx-websocket.conf.template # WebSocket support
└── nginx-static.conf.template    # SPA/sites statiques

Phase 5 - Stratégies Files & Remote

files.sh (type Capistrano)

Structure créée sur le serveur :

/opt/33800-services/mon-app/
├── releases/
│   ├── 2026-01-20_12-00-00-abc1234/
│   └── 2026-01-20_13-00-00-def5678/
├── shared/
│   ├── logs/
│   ├── data/
│   └── config/
└── current -> releases/2026-01-20_13-00-00-def5678

Fonctionnalités :

remote.sh (rsync/git)

Pour hébergeurs mutualisés (O2switch) :


Phase 6 - Notifications & Registre

lib/notifications.sh

Notifications push via ntfy :

notify_deploy_start "app" "target"
notify_deploy_success "app" "target" "commit" "duration"
notify_deploy_failure "app" "target" "error"
notify_rollback "app" "target"

lib/registry.sh

Registre JSON des services :

rollback.sh

Script standalone :

./rollback.sh conf.gouroubleu.yml [steps]

Configuration conf.gouroubleu.yml

Exemple complet

name: "mon-api"
target: "prod-portainer"    # ou nginx, o2switch, pve
type: "node"                # node, bun, python, rust, static
domain: "api.33800.nowhere84.com"
port: 3000

# Services à injecter
services:
  - supabase
  - redis
  - ntfy

# Stratégie files
strategy: "files"
shared: "logs data"
keep_releases: 5

# Stratégie remote
deploy:
  method: rsync              # rsync ou git
  dest: "mon-api"
  backup: true
  pre_deploy: "npm install"
  post_deploy: "pm2 restart"

# Nginx
nginx:
  enabled: true
  ssl: true
  websocket: false

# Logs
logs:
  enabled: true
  driver: loki

Commandes

Déploiement

# Via CI/CD (automatique sur push)
git push origin main

# Manuel
cd /path/to/project
DEPLOY_CONFIG=conf.gouroubleu.yml /stock_8to/33800-stack/scripts/deploy/smart-deploy.sh

Rollback

# Files (1 version en arrière)
/stock_8to/33800-stack/scripts/deploy/rollback.sh conf.gouroubleu.yml 1

# Files (2 versions)
/stock_8to/33800-stack/scripts/deploy/rollback.sh conf.gouroubleu.yml 2

Registre

# Lister services
source /stock_8to/33800-stack/scripts/deploy/lib/common.sh
source /stock_8to/33800-stack/scripts/deploy/lib/registry.sh
registry_list_services

# Voir JSON
cat /stock_8to/33800-stack/monitoring/services-registry.json | jq .

Targets disponibles

Target Type IP/Host Usage
prod-portainer docker 192.168.1.12 Containers PROD
dev-portainer docker 192.168.1.51 Containers DEV
nginx files 192.168.1.104 Sites statiques, apps Node
pve files 192.168.1.4 Scripts, services locaux
o2switch remote yellow.o2switch.net Dashboard, sites externes
win11 files 192.168.1.30 Apps Windows
gitlab files 192.168.1.196 Services GitLab

Tests effectués

Test Target Status
Docker build + deploy prod-portainer
Files deploy nginx
Files rollback nginx
Remote rsync + backup o2switch
Remote post_deploy o2switch
Remote rollback o2switch
Notifications ntfy -
Registre JSON -

À faire (Phase 7+)