services:
  postgres:
    image: postgres:17-alpine
    environment:
      POSTGRES_DB: bartered
      POSTGRES_USER: bartered
      POSTGRES_PASSWORD: bartered
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U bartered -d bartered"]
      interval: 5s
      timeout: 3s
      retries: 10

  backend:
    build:
      context: ./backend
    environment:
      HTTP_ADDR: :8080
      DATABASE_URL: postgres://bartered:bartered@postgres:5432/bartered?sslmode=disable
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "/app/healthcheck"]
      interval: 5s
      timeout: 2s
      retries: 10
      start_period: 2s

  backend-test:
    image: golang:1.24-alpine
    working_dir: /src
    volumes:
      - ./backend:/src
    command: go test ./...
    profiles: ["test"]

  frontend:
    build:
      context: ./frontend
    ports:
      - "3000:80"
    depends_on:
      backend:
        condition: service_healthy

volumes:
  postgres-data:
