Cloud & DevOps Nodes

I nodi Cloud & DevOps permettono di automatizzare pipeline CI/CD, build Docker, deploy su cloud e gestione infrastruttura.


Docker Build

dockerBuild

Costruisce immagini Docker da Dockerfile o build context.

Configurazione

CampoTipoObbligatorioDescrizione
labeltextNome identificativo
contextPathtextPath al build context
dockerfiletextNoPath Dockerfile (default: Dockerfile)
imageNametextNome immagine
tagtextTag immagine
buildArgskeyvalueNoBuild arguments
targettextNoTarget stage per multi-stage
platformselectNoPiattaforma target
pushbooleanNoPush a registry dopo build
registrytextPer pushRegistry URL

Workflow Esempio: CI/CD Pipeline

Diagramma di flusso

Configurazione build
type: dockerBuild
contextPath: "/app"
dockerfile: "Dockerfile.prod"
imageName: "myapp"
tag: "{{trigger.data.commit.sha | slice: 0, 7}}"
buildArgs:
  NODE_ENV: "production"
  VERSION: "{{trigger.data.commit.sha}}"
target: "production"
platform: "linux/amd64"
push: true
registry: "registry.example.com"
registryUser: "{{secrets.REGISTRY_USER}}"
registryPassword: "{{secrets.REGISTRY_PASS}}"
label: "Build Production Image"

Output

{
  "imageName": "registry.example.com/myapp",
  "tag": "abc1234",
  "fullName": "registry.example.com/myapp:abc1234",
  "digest": "sha256:...",
  "size": "125MB",
  "buildTime": 45000,
  "pushed": true,
  "layers": 12,
  "buildLog": "Step 1/12: FROM node:18-alpine..."
}

Multi-stage Build

Esempio di Dockerfile ottimizzato per produzione.

Dockerfile multi-stage
# Stage 1: Build
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build

# Stage 2: Production
FROM node:18-alpine AS production
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/server.js"]

Configurazione per stage specifico

type: dockerBuild
contextPath: "/app"
target: "production"  # Usa solo lo stage production
imageName: "myapp"
tag: "latest"

Cloud Deploy

cloudDeploy

Deploy di applicazioni su cloud provider (AWS, GCP, Azure, DigitalOcean, etc.).

Configurazione

CampoTipoObbligatorioDescrizione
labeltextNome identificativo
providerselectCloud provider
serviceselectTipo servizio
regiontextRegione deploy
credentialssecretCredenziali cloud
configjsonConfigurazione specifica

Provider supportati

ProviderServizi
awsECS, Lambda, EC2, S3, CloudFront
gcpCloud Run, GKE, Compute Engine, Cloud Functions
azureApp Service, AKS, Container Instances
digitaloceanApp Platform, Droplets, Kubernetes
vercelStatic, Serverless
flyFly Machines

Workflow Esempio: Deploy AWS ECS

Diagramma di flusso

Configurazione AWS ECS
type: cloudDeploy
provider: aws
service: ecs
region: "eu-west-1"
credentials:
  accessKeyId: "{{secrets.AWS_ACCESS_KEY}}"
  secretAccessKey: "{{secrets.AWS_SECRET_KEY}}"
config:
  cluster: "production"
  service: "myapp-service"
  taskDefinition: "myapp-task"
  image: "{{dockerBuild.output.fullName}}"
  desiredCount: 3
  deploymentConfig:
    maximumPercent: 200
    minimumHealthyPercent: 50
  loadBalancer:
    targetGroupArn: "arn:aws:elasticloadbalancing:..."
    containerName: "myapp"
    containerPort: 3000
label: "Deploy ECS Production"

Output

{
  "provider": "aws",
  "service": "ecs",
  "deploymentId": "ecs-svc/abc123",
  "status": "success",
  "taskDefinition": "myapp-task:42",
  "desiredCount": 3,
  "runningCount": 3,
  "pendingCount": 0,
  "events": [
    {
      "timestamp": "2024-01-15T10:35:00Z",
      "message": "service myapp-service has reached a steady state."
    }
  ],
  "deployedAt": "2024-01-15T10:30:00Z"
}

Deploy Kubernetes

Deploy su cluster Kubernetes.

Workflow Esempio: K8s Rolling Update

Diagramma di flusso

Configurazione Kubernetes
type: cloudDeploy
provider: kubernetes
config:
  kubeconfig: "{{secrets.KUBECONFIG}}"
  namespace: "production"
  deployment: "myapp"
  container: "main"
  image: "{{dockerBuild.output.fullName}}"
  strategy:
    type: RollingUpdate
    maxUnavailable: 1
    maxSurge: 1
  replicas: 3
  resources:
    requests:
      cpu: "100m"
      memory: "256Mi"
    limits:
      cpu: "500m"
      memory: "512Mi"
label: "K8s Deploy"

Deploy Serverless

Deploy di funzioni serverless.

Workflow Esempio: AWS Lambda

Diagramma di flusso

Configurazione Lambda
type: cloudDeploy
provider: aws
service: lambda
region: "eu-west-1"
credentials:
  accessKeyId: "{{secrets.AWS_ACCESS_KEY}}"
  secretAccessKey: "{{secrets.AWS_SECRET_KEY}}"
config:
  functionName: "myFunction"
  runtime: "nodejs18.x"
  handler: "index.handler"
  zipFile: "/tmp/function.zip"
  memorySize: 256
  timeout: 30
  environment:
    NODE_ENV: "production"
    DB_URL: "{{secrets.DB_URL}}"
label: "Deploy Lambda"

CI/CD Pipeline Completa

Pipeline completa con test, build, deploy staging e production.

Diagramma di flusso


Blue-Green Deployment

Strategia di deploy con zero downtime.

Diagramma di flusso

Workflow Blue-Green

Diagramma di flusso


Canary Deployment

Deploy graduale con percentuale crescente di traffico.

Diagramma di flusso


Best Practices

Immagini Docker
  1. Usa multi-stage build per immagini più piccole
  2. Tag immutabili (commit SHA) oltre a latest
  3. Scan vulnerabilità prima del push
  4. Layer caching per build veloci
Deploy sicuri
  1. Sempre health check dopo deploy
  2. Rollback automatico in caso di errori
  3. Deploy progressivi (canary/blue-green)
  4. Feature flags per rilasci controllati
Secrets management
  1. Mai credenziali in immagini Docker
  2. Usa secrets manager (AWS Secrets Manager, Vault)
  3. Rotazione automatica delle credenziali
  4. Least privilege per credenziali CI/CD
Monitoring deploy
  1. Metriche chiave: error rate, latency, throughput
  2. Alert automatici su anomalie post-deploy
  3. Logging centralizzato per debug
  4. Trace distribuito per problemi complessi