services:
  backend:
    image: git.koppkb.com/kopkb/my-kopkb-be:${IMAGE_TAG:-latest}
    container_name: mykopkb-be-production
    restart: unless-stopped
    ports:
      - "${API_PORT:-8080}:80"
    environment:
      - APP_ENV=production
      - APP_DEBUG=true
      - REDIS_HOST=redis
      - REDIS_PASSWORD=${REDIS_PASSWORD}
      - CACHE_DRIVER=redis
      - SESSION_DRIVER=redis
      - QUEUE_CONNECTION=redis
    volumes:
      - app-storage-production:/var/www/storage
      - app-logs-production:/var/www/storage/logs
      - ./.env.production:/var/www/.env:ro
      - ${NGINX_CONF:-./be/docker/production/nginx/nginx.conf}:/etc/nginx/nginx.conf:ro
    networks:
      - mykopkb-production-network
    depends_on:
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

  frontend:
    image: git.koppkb.com/kopkb/my-kopkb-fe:${IMAGE_TAG:-latest}
    container_name: mykopkb-fe-production
    restart: unless-stopped
    ports:
      - "${FE_PORT:-8081}:80"
    networks:
      - mykopkb-production-network
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost/"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

  redis:
    image: redis:8
    container_name: mykopkb-redis-production
    restart: unless-stopped
    volumes:
      - redis-data-production:/data
      - ./redis-config/redis.conf:/usr/local/etc/redis/redis.conf:ro
    command: redis-server /usr/local/etc/redis/redis.conf
    networks:
      - mykopkb-production-network
    healthcheck:
      test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 10s
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

networks:
  mykopkb-production-network:
    driver: bridge

volumes:
  app-storage-production:
    driver: local
  app-logs-production:
    driver: local
  redis-data-production:
    driver: local
