services:
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-polskalokalnie}
      POSTGRES_USER: ${POSTGRES_USER:-polskalokalnie}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-polskalokalnie_dev}
    ports:
      - "${POSTGRES_BIND_ADDRESS:-127.0.0.1}:5432:5432"
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-polskalokalnie} -d ${POSTGRES_DB:-polskalokalnie}"]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ./backend
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/${POSTGRES_DB:-polskalokalnie}
      SPRING_DATASOURCE_USERNAME: ${POSTGRES_USER:-polskalokalnie}
      SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD:-polskalokalnie_dev}
      SPRING_JPA_HIBERNATE_DDL_AUTO: ${SPRING_JPA_HIBERNATE_DDL_AUTO:-update}
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "${BACKEND_BIND_ADDRESS:-127.0.0.1}:8080:8080"

  web:
    build:
      context: .
      dockerfile: nginx/Dockerfile
    depends_on:
      - backend
    ports:
      - "${WEB_BIND_ADDRESS:-0.0.0.0}:80:80"

volumes:
  postgres-data:
