Formation Automatisation Python & Go

Fiche pédagogique

  • Objectifs SMART : créer des outils CLI Python & Go, publier un package interne et automatiser un opérateur de service en 12 jours.
  • Durée : 14 h (6 h théorie, 8 h pratique)
  • Prérequis : Git, Linux, notions DevOps.
  • Niveau : Intermédiaire.

Sommaire

  1. Automatisation Python (Typer, asyncio, API)
  2. Automatisation Go (CLI, concurrency, gRPC)
  3. Packaging, distribution & observabilité
  4. Cas réels : opérateur interne & SDK CLI
  5. Labs, quiz, checklist
  6. Ressources & synthèse

1. Automatisation Python

import httpx
import typer

app = typer.Typer()

@app.command()
def deploy(env: str = "dev"):
    resp = httpx.post(f"https://api.example.com/{env}/deploy")
    typer.echo(resp.json())

if __name__ == "__main__":
    app()

2. Automatisation Go

package main
import (
  "context"
  "fmt"
  "time"
)
func main() {
  ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
  defer cancel()
  go func() {
    <-ctx.Done()
    fmt.Println("timeout!")
  }()
  // work ...
}

3. Packaging, distribution & observabilité

  • Python : build wheels, publier sur Devpi.
  • Go : release multi-plateforme via Goreleaser.
  • Observabilité : logging structuré (structlog, zerolog), tracing OpenTelemetry.
  • Sécurité : Bandit, gosec.

4. Cas réels

  • Opérateur interne : Operator SDK + Argo Events pour créer namespaces et secrets.
  • CLI FinOps : Typer + boto3 pour générer rapports coûts.
  • Résultats : temps de provisioning -60%, erreurs humaines quasi nulles.

5. Labs, quiz, checklist

Lab Objectif Livrable
Lab Typer CLI déploiement + tests pytest Package Poetry + CI
Lab Cobra CLI Go + release Goreleaser binaire multiplateforme
Lab Operator Controller Go + CRD Repo + manifestes

Quiz : asyncio vs threads, différence goroutines/tasks, comment gèrer contexts, comment signer releases. Checklist : doc CLI, tests unitaires/integration, observabilité, sécurité.

6. Ressources & synthèse

À retenir : traitez vos scripts comme du produit logiciel (tests, packaging, observabilité).