Vai al contenuto

Waypoint

Guida completa ai comandi e ai workflow di HashiCorp Waypoint per la distribuzione e la gestione delle release di applicazioni su diverse piattaforme.

Installazione e Configurazione

Comando Descrizione
waypoint version Mostra versione Waypoint
waypoint server install -platform=docker Installare il server su Docker
waypoint server install -platform=kubernetes Installare server su Kubernetes
waypoint context create -server-addr=localhost:9701 Crea contesto
waypoint login Accedi al server Waypoint
## Gestione Progetto

Operazioni di Progetto

Comando Descrizione
waypoint init Inizializza progetto
waypoint project list Elenca progetti
waypoint project inspect myapp Ispeziona progetto
waypoint project destroy myapp Distruggere progetto
## Ciclo di Vita dell'Applicazione

Build, Deploy, Release

Comando Descrizione
waypoint build Costruisci applicazione
waypoint deploy Distribuisci applicazione
waypoint release Rilascia applicazione
waypoint up Costruisci, distribuisci e rilascia
### Gestione Applicazione
Comando Descrizione
--------- -------------
waypoint status Mostra stato applicazione
waypoint logs Mostra log dell'applicazione
waypoint logs -follow Segui i log dell'applicazione
waypoint exec /bin/bash Esegui comando in deployment
## Gestione Workspace
Comando Descrizione
waypoint workspace list Elenca workspace
waypoint workspace create dev Crea workspace
waypoint workspace use dev Cambia workspace
## Esempi di Configurazione

waypoint.hcl Base

project = "myapp"

app "web" \\\\{
  labels = \\\\{
    "service" = "web"
    "env"     = "dev"
  \\\\}

  build \\\\{
    use "docker" \\\\{
      dockerfile = "./Dockerfile"
    \\\\}

    registry \\\\{
      use "docker" \\\\{
        image = "myapp"
        tag   = "latest"
      \\\\}
    \\\\}
  \\\\}

  deploy \\\\{
    use "docker" \\\\{
      service_port = 3000
    \\\\}
  \\\\}

  release \\\\{
    use "docker" \\\\{\\\\}
  \\\\}
\\\\}

Distribuzione Kubernetes

project = "myapp"

app "web" \\\\{
  build \\\\{
    use "docker" \\\\{
      dockerfile = "./Dockerfile"
    \\\\}

    registry \\\\{
      use "docker" \\\\{
        image = "registry.example.com/myapp"
        tag   = gitrefpretty()
      \\\\}
    \\\\}
  \\\\}

  deploy \\\\{
    use "kubernetes" \\\\{
      probe_path = "/health"

      replicas = 3

      resources \\\\{
        requests \\\\{
          memory = "256Mi"
          cpu    = "250m"
        \\\\}
        limits \\\\{
          memory = "512Mi"
          cpu    = "500m"
        \\\\}
      \\\\}
    \\\\}
  \\\\}

  release \\\\{
    use "kubernetes" \\\\{
      load_balancer = true
      port          = 80
    \\\\}
  \\\\}
\\\\}

Distribuzione AWS ECS

project = "myapp"

app "web" \\\\{
  build \\\\{
    use "docker" \\\\{
      dockerfile = "./Dockerfile"
    \\\\}

    registry \\\\{
      use "aws-ecr" \\\\{
        region     = "us-west-2"
        repository = "myapp"
        tag        = gitrefpretty()
      \\\\}
    \\\\}
  \\\\}

  deploy \\\\{
    use "aws-ecs" \\\\{
      region = "us-west-2"
      cluster = "production"

      memory = 512
      cpu    = 256

      count = 3

      subnets = [
        "subnet-12345",
        "subnet-67890"
      ]

      security_groups = [
        "sg-abcdef"
      ]
    \\\\}
  \\\\}

  release \\\\{
    use "aws-alb" \\\\{
      listener_arn = "arn:aws:elasticloadbalancing:..."

      health_check \\\\{
        enabled             = true
        healthy_threshold   = 2
        interval            = 30
        matcher             = "200"
        path                = "/health"
        port                = "traffic-port"
        protocol            = "HTTP"
        timeout             = 5
        unhealthy_threshold = 2
      \\\\}
    \\\\}
  \\\\}
\\\\}

Progetto Multi-App

project = "microservices"

app "api" \\\\{
  labels = \\\\{
    "service" = "api"
    "tier"    = "backend"
  \\\\}

  build \\\\{
    use "docker" \\\\{
      dockerfile = "./api/Dockerfile"
    \\\\}

    registry \\\\{
      use "docker" \\\\{
        image = "mycompany/api"
        tag   = gitrefpretty()
      \\\\}
    \\\\}
  \\\\}

  deploy \\\\{
    use "kubernetes" \\\\{
      probe_path = "/health"
      replicas   = 2

      env = \\\\{
        "DATABASE_URL" = var.database_url
        "REDIS_URL"    = var.redis_url
      \\\\}
    \\\\}
  \\\\}

  release \\\\{
    use "kubernetes" \\\\{
      port = 8080
    \\\\}
  \\\\}
\\\\}

app "frontend" \\\\{
  labels = \\\\{
    "service" = "frontend"
    "tier"    = "frontend"
  \\\\}

  build \\\\{
    use "docker" \\\\{
      dockerfile = "./frontend/Dockerfile"
    \\\\}

    registry \\\\{
      use "docker" \\\\{
        image = "mycompany/frontend"
        tag   = gitrefpretty()
      \\\\}
    \\\\}
  \\\\}

  deploy \\\\{
    use "kubernetes" \\\\{
      probe_path = "/"
      replicas   = 3
    \\\\}
  \\\\}

  release \\\\{
    use "kubernetes" \\\\{
      load_balancer = true
      port          = 80
    \\\\}
  \\\\}
\\\\}

Variabili e Configurazione

Definizioni Variabili

variable "database_url" \\\\{
  description = "Database connection URL"
  type        = string
  sensitive   = true
\\\\}

variable "replicas" \\\\{
  description = "Number of replicas"
  type        = number
  default     = 2
\\\\}

variable "environment" \\\\{
  description = "Environment name"
  type        = string
  default     = "dev"
\\\\}

Utilizzo Variabili

app "web" \\\\{
  deploy \\\\{
    use "kubernetes" \\\\{
      replicas = var.replicas

      env = \\\\{
        "DATABASE_URL" = var.database_url
        "ENVIRONMENT"  = var.environment
      \\\\}
    \\\\}
  \\\\}
\\\\}

Funzioni ed Espressioni

Funzioni Integrate

app "web" \\\\{
  build \\\\{
    registry \\\\{
      use "docker" \\\\{
        image = "myapp"
        tag   = gitrefpretty()  # Git reference
      \\\\}
    \\\\}
  \\\\}

  deploy \\\\{
    use "kubernetes" \\\\{
      env = \\\\{
        "BUILD_TIME" = timestamp()
        "GIT_SHA"    = gitsha()
        "VERSION"    = gitrefpretty()
      \\\\}
    \\\\}
  \\\\}
\\\\}

Plugin e Builder

Plugin di Build Personalizzato

app "web" \\\\{
  build \\\\{
    use "pack" \\\\{
      builder = "heroku/buildpacks:20"
    \\\\}
  \\\\}
\\\\}

Plugin di Deploy Personalizzato

app "web" \\\\{
  deploy \\\\{
    use "nomad" \\\\{
      datacenter = "dc1"
      region     = "global"

      resources \\\\{
        cpu    = 500
        memory = 256
      \\\\}
    \\\\}
  \\\\}
\\\\}

Best Practice

Struttura Progetto

project/
├── waypoint.hcl
├── .waypointignore
├── apps/
│   ├── api/
│   │   ├── Dockerfile
│   │   └── src/
│   └── frontend/
│       ├── Dockerfile
│       └── src/
├── infrastructure/
│   └── terraform/
└── scripts/
    └── deploy.sh

Sicurezza