services:
  api: &main_app
    build:
      context: .
      target: dev
      dockerfile: ./Dockerfile
    image: zangramru:${ZANGRAMRU_VERSION:-latest}
    restart: always
    ports:
      # Exposes application port.
      - "8000:8000"
    env_file:
      - path: .env
        required: false
    depends_on:
      db:
        condition: service_healthy
      migrator:
        condition: service_completed_successfully
    environment:
      ZANGRAMRU_HOST: 0.0.0.0
      ZANGRAMRU_RELOAD: "True"
      ZANGRAMRU_DB_HOST: zangramru-db
      ZANGRAMRU_DB_PORT: 5432
      ZANGRAMRU_DB_USER: zangramru
      ZANGRAMRU_DB_PASS: zangramru
      ZANGRAMRU_DB_BASE: zangramru
    # volumes:
    #   - .:/app/src/

  db:
    image: postgres:18.3-trixie
    hostname: zangramru-db
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: "zangramru"
      POSTGRES_USER: "zangramru"
      POSTGRES_DB: "zangramru"
    volumes:
      - zangramru-db-data:/var/lib/postgresql
    restart: always
    healthcheck:
      test: pg_isready -U zangramru
      interval: 2s
      timeout: 3s
      retries: 40

  migrator:
    <<: *main_app
    restart: "no"
    command:
      - bash
      - -c
      - "ls && piccolo migrations forwards all"
    depends_on:
      db:
        condition: service_healthy

volumes:
  zangramru-db-data:
    name: zangramru-db-data
