x-common-envs: &common-envs
  SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE:-docker,auth0}
  OAUTH2_SECURITY_ENABLED: ${OAUTH2_SECURITY_ENABLED:-false}
  TRACING_ENABLED: ${TRACING_ENABLED:-false}
  FLUENT_BIT_ENABLED: ${FLUENT_BIT_ENABLED:-false}
  CIRCUIT_BREAKER_ENABLED: ${CIRCUIT_BREAKER_ENABLED:-false}

services:
  postgres:
    image: postgres:15
    container_name: postgres
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: "postgres"
      POSTGRES_DB: postgres
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U $$POSTGRES_USER" ]
      interval: 10s
      timeout: 5s
      retries: 5
    ports:
      - "5432:5432"
    volumes:
      - postgres:/var/lib/postgresql/data
      - ./docker/postgres/:/docker-entrypoint-initdb.d/

  gateway:
    build: ./gateway
    image: romanowalex/store-gateway:${VERSION}
    container_name: gateway
    restart: on-failure
    environment:
      <<: *common-envs
    healthcheck:
      test: [ "CMD", "curl", "--silent", "--fail", "http://localhost:8080/manage/health" ]
      interval: 10s
      timeout: 10s
      retries: 10
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy

  store-service:
    build: ./store-service
    image: romanowalex/store-service:${VERSION}
    container_name: store
    restart: on-failure
    environment:
      <<: *common-envs
    healthcheck:
      test: [ "CMD", "curl", "--silent", "--fail", "http://localhost:8180/manage/health" ]
      interval: 10s
      timeout: 10s
      retries: 10
    ports:
      - "8180:8180"
    depends_on:
      postgres:
        condition: service_healthy

  warehouse-service:
    build: ./warehouse-service
    image: romanowalex/warehouse-service:${VERSION}
    container_name: warehouse
    restart: on-failure
    environment:
      <<: *common-envs
    healthcheck:
      test: [ "CMD", "curl", "--silent", "--fail", "http://localhost:8280/manage/health" ]
      interval: 10s
      timeout: 10s
      retries: 10
    ports:
      - "8280:8280"
    depends_on:
      postgres:
        condition: service_healthy

  warranty-service:
    build: ./warranty-service
    image: romanowalex/warranty-service:${VERSION}
    container_name: warranty
    restart: on-failure
    environment:
      <<: *common-envs
    healthcheck:
      test: [ "CMD", "curl", "--silent", "--fail", "http://localhost:8380/manage/health" ]
      interval: 10s
      timeout: 10s
      retries: 10
    ports:
      - "8380:8380"
    depends_on:
      postgres:
        condition: service_healthy

volumes:
  postgres:
