YAML-Beispiele

YAML (YAML Ain't Markup Language)-Formatbeispiele von einfachen bis komplexen Strukturen

⚙️ Einfache Konfigurationsdatei

🟢 simple

Grundlegende Anwendungskonfigurationsdatei

# Application Configuration
app:
  name: "MyWebApp"
  version: "1.0.0"
  environment: "development"

server:
  host: "localhost"
  port: 3000
  ssl: false

logging:
  level: "info"
  format: "text"

⚙️ Datenbankkonfiguration

🟡 intermediate

Beispiel für Datenbankverbindungskonfiguration

# Database Configuration
database:
  type: "postgresql"
  host: "localhost"
  port: 5432
  name: "myapp_db"

  credentials:
    username: "db_user"
    password: "secure_password"
    ssl: true

  pool:
    min: 2
    max: 10
    timeout: 30s

  connection:
    timeout: 10s
    retries: 3
    backoff: 1s

⚙️ Benutzerprofil

🟡 intermediate

YAML-Struktur mit Benutzerinformationen

# User Profile
user:
  id: "USR12345"
  username: "johndoe"
  email: "[email protected]"

  profile:
    first_name: "John"
    last_name: "Doe"
    age: 30
    bio: >
      Software developer passionate about
      creating amazing applications.
      Love working with modern technologies.

    interests:
      - "programming"
      - "photography"
      - "travel"

  preferences:
    theme: "dark"
    language: "en"
    timezone: "UTC-5"
    notifications:
      email: true
      push: false

  roles:
    - "user"
    - "developer"

⚙️ Serverkonfiguration

🟡 intermediate

Beispiel für Webserver-Konfiguration

# Server Configuration
server:
  name: "Production Web Server"
  environment: "production"

  http:
    host: "0.0.0.0"
    port: 80
    timeout: 30s

  https:
    enabled: true
    port: 443
    certificate: "/etc/ssl/certs/server.crt"
    private_key: "/etc/ssl/private/server.key"

  middleware:
    - cors
    - rate_limit
    - compression
    - logging

  rate_limit:
    requests_per_minute: 100
    burst_size: 20

  cors:
    origins:
      - "https://example.com"
      - "https://app.example.com"
    methods:
      - GET
      - POST
      - PUT
      - DELETE
    headers:
      - Content-Type
      - Authorization

⚙️ Internationalisierungs-Nachrichten

🟡 intermediate

Beispiel für mehrsprachige Nachrichtenkonfiguration

# Internationalization Messages
en:
  common:
    welcome: "Welcome to our application"
    login: "Login"
    logout: "Logout"
    register: "Register"

  navigation:
    home: "Home"
    about: "About"
    contact: "Contact"
    services: "Services"

  messages:
    success: "Operation completed successfully"
    error: "An error occurred"
    loading: "Loading..."
    no_data: "No data available"

  validation:
    required: "This field is required"
    email: "Please enter a valid email"
    min_length: "Minimum length is {count} characters"

zh:
  common:
    welcome: "欢迎使用我们的应用程序"
    login: "登录"
    logout: "登出"
    register: "注册"

  navigation:
    home: "首页"
    about: "关于"
    contact: "联系"
    services: "服务"

  messages:
    success: "操作成功完成"
    error: "发生错误"
    loading: "加载中..."
    no_data: "暂无数据"

  validation:
    required: "此字段为必填项"
    email: "请输入有效的邮箱地址"
    min_length: "最小长度为 {count} 个字符"

es:
  common:
    welcome: "Bienvenido a nuestra aplicación"
    login: "Iniciar sesión"
    logout: "Cerrar sesión"
    register: "Registrarse"

  navigation:
    home: "Inicio"
    about: "Acerca de"
    contact: "Contacto"
    services: "Servicios"

  messages:
    success: "Operación completada exitosamente"
    error: "Ocurrió un error"
    loading: "Cargando..."
    no_data: "No hay datos disponibles"

  validation:
    required: "Este campo es obligatorio"
    email: "Por favor ingrese un email válido"
    min_length: "La longitud mínima es {count} caracteres"

⚙️ Docker Compose Konfiguration

🔴 complex

Orchestrierungskonfiguration für containerisierte Anwendungen

# Docker Compose Configuration
version: '3.8'

services:
  web:
    image: nginx:alpine
    container_name: web_server
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./ssl:/etc/ssl:ro
    depends_on:
      - app
    networks:
      - frontend

  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: web_app
    environment:
      NODE_ENV: "production"
      DATABASE_URL: "postgresql://user:password@db:5432/myapp"
      REDIS_URL: "redis://redis:6379"
    ports:
      - "3000:3000"
    volumes:
      - ./app:/usr/src/app
      - /usr/src/app/node_modules
    depends_on:
      - db
      - redis
    networks:
      - frontend
      - backend

  db:
    image: postgres:15
    container_name: postgres_db
    environment:
      POSTGRES_DB: "myapp"
      POSTGRES_USER: "user"
      POSTGRES_PASSWORD: "password"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
    ports:
      - "5432:5432"
    networks:
      - backend

  redis:
    image: redis:7-alpine
    container_name: redis_cache
    command: redis-server --appendonly yes
    volumes:
      - redis_data:/data
    ports:
      - "6379:6379"
    networks:
      - backend

volumes:
  postgres_data:
  redis_data:

networks:
  frontend:
    driver: bridge
  backend:
    driver: bridge

⚙️ CI/CD-Pipeline

🔴 complex

Beispiel für Continuous Integration Konfiguration

# CI/CD Pipeline Configuration
name: "CI/CD Pipeline"

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18, 20]

    steps:
      - name: "Checkout code"
        uses: actions/checkout@v3

      - name: "Setup Node.js ${{ matrix.node-version }}"
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'

      - name: "Install dependencies"
        run: npm ci

      - name: "Run linting"
        run: npm run lint

      - name: "Run type checking"
        run: npm run type-check

      - name: "Run unit tests"
        run: npm run test:unit

      - name: "Run integration tests"
        run: npm run test:integration

  build:
    needs: test
    runs-on: ubuntu-latest

    steps:
      - name: "Checkout code"
        uses: actions/checkout@v3

      - name: "Setup Node.js"
        uses: actions/setup-node@v3
        with:
          node-version: '20'
          cache: 'npm'

      - name: "Install dependencies"
        run: npm ci

      - name: "Build application"
        run: npm run build

      - name: "Upload build artifacts"
        uses: actions/upload-artifact@v3
        with:
          name: build-files
          path: dist/

  deploy:
    needs: build
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'

    environment: production

    steps:
      - name: "Download build artifacts"
        uses: actions/download-artifact@v3
        with:
          name: build-files
          path: dist/

      - name: "Deploy to production"
        run: |
          echo "Deploying to production server..."
          # Add your deployment commands here

      - name: "Run smoke tests"
        run: npm run test:smoke

⚙️ Kubernetes-Bereitstellung

🔴 complex

Container-Orchestrierungsbereitstellungskonfiguration

# Kubernetes Deployment Configuration
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
  namespace: production
  labels:
    app: web-app
    version: v1.0.0
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
        version: v1.0.0
    spec:
      containers:
      - name: web-app
        image: myregistry/web-app:1.0.0
        ports:
        - containerPort: 3000
          protocol: TCP

        env:
        - name: NODE_ENV
          value: "production"
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: app-secrets
              key: database-url
        - name: REDIS_URL
          valueFrom:
            configMapKeyRef:
              name: app-config
              key: redis-url

        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "512Mi"
            cpu: "500m"

        livenessProbe:
          httpGet:
            path: /health
            port: 3000
          initialDelaySeconds: 30
          periodSeconds: 10

        readinessProbe:
          httpGet:
            path: /ready
            port: 3000
          initialDelaySeconds: 5
          periodSeconds: 5

        volumeMounts:
        - name: config-volume
          mountPath: /app/config
          readOnly: true

      volumes:
      - name: config-volume
        configMap:
          name: app-config

      imagePullSecrets:
      - name: registry-secret

---
apiVersion: v1
kind: Service
metadata:
  name: web-app-service
  namespace: production
spec:
  selector:
    app: web-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 3000
  type: ClusterIP

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-app-ingress
  namespace: production
  annotations:
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  tls:
  - hosts:
    - app.example.com
    secretName: web-app-tls
  rules:
  - host: app.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: web-app-service
            port:
              number: 80