# Custom images (backend, frontend) are tagged for the private registry so
# `docker compose push backend frontend` publishes them. Override via .env:
#   DOCKER_REGISTRY=static.ranneft.ru:25000
#   IMAGE_TAG=latest
services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: ${DB_NAME:-autohero}
      POSTGRES_USER: ${DB_USER:-autohero}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-autohero}
    ports:
      - "${DB_PORT:-5432}:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./backend/migrations:/docker-entrypoint-initdb.d:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-autohero} -d ${DB_NAME:-autohero}"]
      interval: 5s
      timeout: 3s
      retries: 5
    networks:
      - autohero

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
    networks:
      - autohero

  backend:
    image: ${DOCKER_REGISTRY:-static.ranneft.ru:25000}/autohero/backend:${IMAGE_TAG:-latest}
    build:
      context: ./backend
      dockerfile: Dockerfile
    ports:
      - "${SERVER_PORT:-8080}:8080"
    environment:
      SERVER_PORT: "8080"
      DB_HOST: postgres
      DB_PORT: "5432"
      DB_USER: ${DB_USER:-autohero}
      DB_PASSWORD: ${DB_PASSWORD:-autohero}
      DB_NAME: ${DB_NAME:-autohero}
      REDIS_ADDR: redis:6379
      BOT_TOKEN: ${BOT_TOKEN:-}
      ADMIN_BASIC_AUTH_USERNAME: ${ADMIN_BASIC_AUTH_USERNAME:-}
      ADMIN_BASIC_AUTH_PASSWORD: ${ADMIN_BASIC_AUTH_PASSWORD:-}
      ADMIN_BASIC_AUTH_REALM: ${ADMIN_BASIC_AUTH_REALM:-AutoHero Admin}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    restart: on-failure
    networks:
      - autohero

  frontend:
    image: ${DOCKER_REGISTRY:-static.ranneft.ru:25000}/autohero/frontend:${IMAGE_TAG:-latest}
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "3000:443"
      - "3001:80"
    volumes:
      - ./ssl:/etc/nginx/ssl:ro
    depends_on:
      - backend
    networks:
      - autohero

volumes:
  pgdata:

networks:
  autohero:
    driver: bridge
