global:
  reconcile_interval: 10s
  health_check_interval: 30s
  cleanup_interval: 5m
  networks:
    - name: app-network
      driver: bridge
      internal: false
      enable_ipv6: false
      ipam:
        driver: default
        config:
          - subnet: 172.20.0.0/16
            gateway: 172.20.0.1

containers:
  - name: web-server
    image: nginx:latest
    env:
      NGINX_HOST: localhost
      NGINX_PORT: "8080"
    ports:
      - host_port: "8080"
        container_port: "80"
        protocol: tcp
    restart_policy: always
    health_check:
      test: ["CMD", "curl", "-f", "http://localhost:80"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 5s
    volumes:
      - source: ./nginx.conf
        target: /etc/nginx/nginx.conf
        read_only: true
    networks:
      - app-network
    resources:
      memory: "128M"
      cpu_shares: 512
    labels:
      app: "web"
      environment: "production"
    dependencies:
      - redis-cache

  - name: redis-cache
    image: redis:latest
    ports:
      - host_port: "6379"
        container_port: "6379"
    restart_policy: unless-stopped
    health_check:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3
    networks:
      - app-network
    resources:
      memory: "256M"
      cpu_shares: 1024
    volumes:
      - source: redis-data
        target: /data
        type: volume
    labels:
      app: "cache"
      environment: "production" 