services:
  reitti:
    image: dedicatedcode/reitti:latest
    ports:
      - "8080:8080"
    depends_on:
      rabbitmq:
        condition: service_healthy
      postgis:
        condition: service_healthy
        restart: true
      redis:
        condition: service_healthy
      postgis_init:
        condition: service_completed_successfully
    environment:
      POSTGIS_USER: reitti
      POSTGIS_PASSWORD: reitti
      POSTGIS_DB: reittidb
      POSTGIS_HOST: postgis
  postgis:
    image: postgis/postgis:17-3.5-alpine
    environment:
      POSTGRES_USER: reitti
      POSTGRES_PASSWORD: reitti
      POSTGRES_DB: reittidb
      POSTGRES_HOST_AUTH_METHOD: trust
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U reitti -d reittidb"]
      interval: 10s
      timeout: 5s
      retries: 5
  postgis_init:
    image: postgis/postgis:17-3.5-alpine
    command: /bin/sh -c 'pg_restore -h postgis --no-owner --no-privileges -d reittidb -U reitti data.dump || true'
    volumes:
      - ./data.dump:/data.dump
    environment:
      POSTGRES_USER: reitti
      POSTGRES_PASSWORD: reitti
      POSTGRES_DB: reittidb
      POSTGRES_HOST_AUTH_METHOD: trust
    depends_on:
      postgis:
        condition: service_healthy
  rabbitmq:
    image: rabbitmq:3-management-alpine
    environment:
      RABBITMQ_DEFAULT_USER: reitti
      RABBITMQ_DEFAULT_PASS: reitti
    healthcheck:
      test: ["CMD", "rabbitmq-diagnostics", "check_port_connectivity"]
      interval: 30s
      timeout: 10s
      retries: 5
  redis:
    image: redis:7-alpine
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
