services:
  backend:
    container_name: backend
    restart: always
    build:
      context: ./backend
      dockerfile: Dockerfile
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    depends_on:
      db:
        condition: service_healthy
    networks:
      - proxy

  frontend:
    container_name: frontend
    restart: always
    build:
      context: ./frontend
      dockerfile: Dockerfile
    networks:
      - proxy
    depends_on:
      - backend

  db:
    image: postgres:alpine3.23
    container_name: db
    restart: always
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-myuser}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD должен быть задан в .env}
      POSTGRES_DB: ${POSTGRES_DB:-app_db}
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U \"$${POSTGRES_USER}\" -d \"$${POSTGRES_DB}\"" ]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - proxy

networks:
  proxy:
    external: true
