x-env_file: &env
  - path: .env
    required: true
  - path: .env.local
    required: false

x-restart: &default_restart
  restart: unless-stopped

name: aviation
services:
  nginx:
    image: gitea.bensherriff.com/bsherriff/aviation-nginx:latest
    container_name: aviation-nginx
    build:
      context: .
      dockerfile: Dockerfile
    env_file: *env
    environment:
      SSL_CERT_PATH: /etc/nginx/ssl/localhost.crt
      SSL_CERT_KEY_PATH: /etc/nginx/ssl/localhost.key
    ports:
      - "${NGINX_HTTP_PORT:-8080}:80"
      - "${NGINX_HTTPS_PORT:-8443}:443"
    volumes:
      - ./ssl:/etc/nginx/ssl/
    networks:
      - frontend
      - backend
    <<: *default_restart

  postgres:
    image: gitea.bensherriff.com/homelab/postgis:17.4
    container_name: aviation-postgres
    env_file: *env
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_NAME}
    volumes:
     - postgres:/var/lib/postgresql/data
     - postgres_logs:/var/log
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    networks:
      - backend
    profiles:
      - backend
    <<: *default_restart

  redis:
    image: gitea.bensherriff.com/homelab/redis:8.0-M03
    container_name: aviation-redis
    volumes:
      - redis:/data
    ports:
      - "${REDIS_PORT:-6379}:6379"
    healthcheck:
      test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
      interval: 10s
      timeout: 5s
      retries: 3
    networks:
      - backend
    profiles:
      - backend
    <<: *default_restart

  minio:
    image: gitea.bensherriff.com/homelab/minio:RELEASE.2025-02-28T09-55-16Z
    container_name: aviation-minio
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
      MINIO_BROWSER_REDIRECT_URL: ${MINIO_BROWSER_REDIRECT_URL}
      MINIO_BROWSER_LOGIN_ANIMATION: false
    volumes:
      - minio:/data
    ports:
      - "${MINIO_PORT:-9000}:9000"
      - "${MINIO_INTERNAL_PORT:-9001}:9001"
    networks:
      - backend
    profiles:
      - backend
    command: server --console-address ":9001" /data
    <<: *default_restart

  api:
    image: gitea.bensherriff.com/bsherriff/aviation-api:latest
    container_name: aviation-api
    build:
      context: .
      dockerfile: Dockerfile
    env_file: *env
    environment:
      SSL_CA_PATH: /ssl/ca.pem
      API_PORT: 5000
      POSTGRES_HOST: aviation-postgres
      POSTGRES_PORT: 5432
      REDIS_HOST: aviation-redis
      REDIS_PORT: 6379
      MINIO_HOST: aviation-minio
      MINIO_PORT: 9000
    volumes:
      - ./ssl:/ssl
    ports:
      - "${API_PORT:-5000}:5000"
    depends_on:
      - postgres
      - redis
      - minio
    networks:
      - frontend
      - backend
    profiles:
      - api
    <<: *default_restart

  ui-dev:
    image: gitea.bensherriff.com/bsherriff/aviation-ui:latest
    container_name: aviation-ui-dev
    build:
      context: .
      dockerfile: Dockerfile
    env_file: *env
    environment:
      - VITE_NODE_ENV=${VITE_NODE_ENV:-development}
    ports:
      - "${UI_PORT:-3000}:3000"
    volumes:
      - ./ui/src:/app/src
      - ./ui/public:/app/public
      - ./ui/styles:/app/styles
    networks:
      - frontend
    profiles:
      - frontend
    command: ["npm", "run", "dev"]
    <<: *default_restart

volumes:
  postgres:
  postgres_logs:
  redis:
  minio:

networks:
  frontend:
  backend:
