version: '3.8'

services:
  db:
    image: postgres:16
    container_name: restaurant_db
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: "123"
      POSTGRES_DB: arseniyborisov
    ports:
      - "5434:5432"
    volumes:
      - pg_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

  app:
    build: .
    container_name: restaurant_app
    restart: always
    ports:
      - "8081:8080"
    environment:
      - DB_HOST=db
      - DB_PORT=5432
      - DB_NAME=arseniyborisov
      - DB_USER=postgres
      - DB_PASSWORD=123
    depends_on:
      db:
        condition: service_healthy

volumes:
  pg_data: