name: ${COMPOSE_PROJECT_NAME:-pcp-local}

x-pcp-service-env: &pcp-service-env
  CONFIG_SERVER_URI: http://spring-cloud-config-server:8888
  CONFIG_SERVER_FAIL_FAST: "true"
  SPRING_PROFILES_ACTIVE: local,docker-local
  SPRING_CLOUD_CONFIG_PROFILE: local,docker-local
  SPRING_CLOUD_CONFIG_LABEL: ""
  SPRING_KAFKA_ADMIN_AUTO_CREATE: "true"
  SPRING_KAFKA_LISTENER_AUTO_STARTUP: "true"

x-pcp-service-common: &pcp-service-common
  restart: unless-stopped
  depends_on:
    spring-cloud-config-server:
      condition: service_started

services:
  postgres:
    image: ${POSTGRES_IMAGE:-postgis/postgis:16-3.4}
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password}
      POSTGRES_DB: postgres
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d postgres"]
      interval: 5s
      timeout: 5s
      retries: 30

  kafka:
    image: ${KAFKA_IMAGE:-apache/kafka:3.7.2}
    restart: unless-stopped
    environment:
      KAFKA_NODE_ID: "1"
      KAFKA_PROCESS_ROLES: broker,controller
      KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093
      KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:29092
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,EXTERNAL://localhost:${KAFKA_PORT:-29092}
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT
      KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: "1"
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: "1"
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: "0"
      KAFKA_LOG_DIRS: /var/lib/kafka/data
    ports:
      - "${KAFKA_PORT:-29092}:29092"
    volumes:
      - kafka-data:/var/lib/kafka/data
    healthcheck:
      test: ["CMD-SHELL", "kafka-topics.sh --bootstrap-server kafka:9092 --list >/dev/null 2>&1"]
      interval: 10s
      timeout: 10s
      retries: 30

  spring-cloud-config-server:
    image: pcp/spring-cloud-config-server:${PCP_IMAGE_TAG:-local}
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
      kafka:
        condition: service_started
    environment:
      SPRING_PROFILES_ACTIVE: local
      CONFIG_NATIVE_SEARCH_LOCATIONS: file:/config-repo
      SERVER_PORT: 8888
    ports:
      - "${CONFIG_SERVER_PORT:-38888}:8888"
    volumes:
      - ${CONFIG_REPO_DIR:-./config-repo}:/config-repo:ro

  pcp-srpring-boot-admin-server:
    <<: *pcp-service-common
    image: pcp/pcp-srpring-boot-admin-server:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_ADMIN_PORT:-7000}:7000"

  tle-monitoring-service:
    <<: *pcp-service-common
    image: pcp/tle-monitoring-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_TLE_MONITORING_PORT:-7001}:7001"

  pcp-complex-mission-service:
    <<: *pcp-service-common
    image: pcp/pcp-complex-mission-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_COMPLEX_MISSION_PORT:-7002}:7002"

  pcp-ballistics-service:
    <<: *pcp-service-common
    image: pcp/pcp-ballistics-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_BALLISTICS_PORT:-7003}:7003"

  pcp-request-service:
    <<: *pcp-service-common
    image: pcp/pcp-request-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_REQUEST_PORT:-7005}:7005"

  slots-service:
    <<: *pcp-service-common
    image: pcp/slots-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_SLOTS_PORT:-7006}:7006"

  pcp-ui-service:
    <<: *pcp-service-common
    image: pcp/pcp-ui-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_UI_PORT:-7008}:7008"

  pcp-stations-service:
    <<: *pcp-service-common
    image: pcp/pcp-stations-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_STATIONS_PORT:-7009}:7009"

  pcp-mission-planing-service:
    <<: *pcp-service-common
    image: pcp/pcp-mission-planing-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_MISSION_PORT:-7010}:7010"

  pcp-tgu-service:
    <<: *pcp-service-common
    image: pcp/pcp-tgu-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_TGU_PORT:-7011}:7011"

  pcp-coverage-scheme-service:
    <<: *pcp-service-common
    image: pcp/pcp-coverage-scheme-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_COVERAGE_SCHEME_PORT:-7012}:7012"

  pcp-satellite-catalog-service:
    <<: *pcp-service-common
    image: pcp/pcp-satellite-catalog-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_SATELLITE_CATALOG_PORT:-7013}:7013"

  pcp-dynamic-plan-service:
    <<: *pcp-service-common
    image: pcp/pcp-dynamic-plan-service:${PCP_IMAGE_TAG:-local}
    environment:
      <<: *pcp-service-env
    ports:
      - "${PCP_DYNAMIC_PLAN_PORT:-7014}:7014"

volumes:
  postgres-data:
  kafka-data:
