version: '3.8'

services:
  faas-postgres:
    image: docker.io/library/postgres:15-alpine
    container_name: faas-postgres
    environment:
      POSTGRES_DB: faas
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - "5434:5432"
    volumes:
      - faas_postgres_data:/var/lib/postgresql/data
      - ./migrations:/docker-entrypoint-initdb.d:Z
    networks:
      - faas-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d faas"]
      interval: 10s
      timeout: 5s
      retries: 5

  faas-api-service:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: faas-api-service
    # user: "1000:1000" # Run as root to access Podman socket properly
    environment:
      FAAS_APP_ENV: development
      FAAS_DB_HOST: faas-postgres
      FAAS_DB_PORT: 5432
      FAAS_DB_NAME: faas
      FAAS_DB_USER: postgres
      FAAS_DB_PASSWORD: postgres
      FAAS_DB_SSLMODE: disable
      DB_CONN_MAX_LIFETIME: 5m
      DB_MAX_OPEN_CONNS: 25
      DB_MAX_IDLE_CONNS: 5
      FAAS_SERVER_HOST: 0.0.0.0
      FAAS_SERVER_PORT: 8083
      FAAS_LOG_LEVEL: debug
      FAAS_DEFAULT_RUNTIME: docker
      FAAS_FUNCTION_TIMEOUT: 300s
      FAAS_MAX_MEMORY: 3008
      FAAS_MAX_CONCURRENT: 100
      FAAS_SANDBOX_ENABLED: true
      FAAS_NETWORK_ISOLATION: true
      FAAS_RESOURCE_LIMITS: true
      AUTH_PROVIDER: header
      AUTH_HEADER_USER_EMAIL: X-User-Email
      RATE_LIMIT_ENABLED: true
      METRICS_ENABLED: true
      METRICS_PORT: 9091
    ports:
      - "8083:8083"
      - "9091:9091" # Metrics port
    depends_on:
      faas-postgres:
        condition: service_healthy
    networks:
      - faas-network
    volumes:
      - /run/user/1000/podman:/run/user/1000/podman:z # Mount entire Podman runtime directory
      - ./migrations:/app/migrations:ro,Z
    cap_add:
      - SYS_ADMIN
      - MKNOD
    devices:
      - /dev/fuse
    security_opt:
      - label=disable
    restart: unless-stopped

#  faas-frontend:
#    build:
#      context: ./web
#      dockerfile: Dockerfile
#    container_name: faas-frontend
#    ports:
#      - "3003:80"
#    networks:
#      - faas-network
#    restart: unless-stopped

volumes:
  faas_postgres_data:
    driver: local

networks:
  faas-network:
    driver: bridge
