Back to Home
    YAMLYAML 1.2Beginner

    YAML

    YAML syntax, data types, anchors, multi-line strings, and common config file patterns.

    6 min read
    yamlconfigdevopsdata

    Syntax

    2 topics

    Basic Types

    yaml
    # Strings
    name: Alice
    quoted: "Hello, World!"
    multiline: |
      Line one
      Line two
    folded: >
      This is a long line that
      gets folded into one.
    
    # Numbers & booleans
    age: 30
    price: 9.99
    enabled: true
    disabled: false
    not_set: null
    
    # Lists
    fruits:
      - apple
      - banana
      - cherry
    inline: [1, 2, 3]
    
    # Maps
    address:
      street: 123 Main St
      city: Springfield
    inline_map: {a: 1, b: 2}

    ⚠️ Indentation must be spaces, never tabs

    💡 | preserves newlines, > folds them into spaces

    Anchors & Aliases

    yaml
    # Define anchor
    defaults: &defaults
      timeout: 30
      retries: 3
      log_level: info
    
    # Reuse with alias
    production:
      <<: *defaults      # Merge defaults
      log_level: warn    # Override one field
      replicas: 5
    
    staging:
      <<: *defaults
      replicas: 1
    
    # Multiple environment example
    x-common: &common
      image: my-app:latest
      restart: unless-stopped
    
    services:
      web:
        <<: *common
        ports: ['80:8080']
      worker:
        <<: *common
        command: worker

    ⚡ Anchors & aliases DRY up Docker Compose and CI config files

    Docker Compose Patterns

    1 topic

    Multi-Service Config

    yaml
    services:
      app:
        build: .
        ports:
          - "3000:3000"
        environment:
          DATABASE_URL: postgres://db:5432/app
          REDIS_URL: redis://cache:6379
        depends_on:
          db:
            condition: service_healthy
        volumes:
          - ./src:/app/src        # Dev hot-reload
    
      db:
        image: postgres:16-alpine
        volumes:
          - pgdata:/var/lib/postgresql/data
        environment:
          POSTGRES_DB: app
          POSTGRES_PASSWORD: secret
        healthcheck:
          test: ["CMD", "pg_isready", "-U", "postgres"]
          interval: 5s
          retries: 5
    
      cache:
        image: redis:7-alpine
    
    volumes:
      pgdata:

    💡 condition: service_healthy waits for real readiness, not just container start

    ⚡ version: key is deprecated in Compose v2 — omit it entirely

    CI/CD YAML

    1 topic

    GitHub Actions Workflow

    yaml
    name: CI/CD
    
    on:
      push:
        branches: [main]
      pull_request:
        branches: [main]
    
    jobs:
      test:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
    
          - uses: actions/setup-node@v4
            with:
              node-version: '20'
              cache: 'npm'          # Caches node_modules
    
          - run: npm ci
          - run: npm test
    
      deploy:
        needs: test              # Only runs if test passes
        runs-on: ubuntu-latest
        if: github.ref == 'refs/heads/main'
        environment: production
        steps:
          - uses: actions/checkout@v4
          - run: ./deploy.sh
            env:
              API_KEY: ${{ secrets.API_KEY }}

    💡 needs: test ensures deploy only runs after tests pass on the same commit

    ⚡ cache: 'npm' dramatically speeds up repeated CI runs by caching node_modules

    Related Articles

    Background reading and deeper explanations for this sheet.

    Building Autonomous Agents Without Overengineering: A Practical Guide for Real-World Teams

    Autonomous agents can automate meaningful work, but many projects fail because teams overbuild too early. This practical guide shows you how to design, ship, and improve useful agents with simple patterns, clear guardrails, and real-world examples—without turning your stack into a science project.

    keyword overlap

    Create a Generative Email Triage App with FastAPI, Postgres, LangGraph, and Azure Foundry

    Learn how to build a production-ready generative email triage app using FastAPI, Postgres, LangGraph, and Azure Foundry. This guide walks you through architecture, data modeling, workflow orchestration, and practical implementation details with real-world examples. By the end, you’ll have a beginner-friendly but deep blueprint you can run, extend, and deploy.

    keyword overlap

    FastAPI Interview Questions: Practical Cheat Sheet for Developers

    Preparing for FastAPI interviews can feel overwhelming if you only memorize definitions. This practical cheat sheet helps you answer common FastAPI interview questions with confidence using real-world examples, production-ready patterns, and beginner-friendly explanations with depth.

    keyword overlap

    GenAI SaaS Architecture: A Practical Blueprint for Building, Scaling, and Securing AI Products

    Designing a SaaS product on top of GenAI is more than calling an LLM API—it requires thoughtful architecture across product, data, safety, and operations. This practical guide walks you through a beginner-friendly yet deep system blueprint, with real-world patterns, code snippets, and deployment strategies you can use immediately.

    keyword overlap