version: "3"

services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
    networks:
      justpickup-network:
        ipv4_address: 172.18.0.100
  kafka:
    image: wurstmeister/kafka:2.12-2.3.0
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 172.18.0.101
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - zookeeper
    networks:
      - justpickup-network

  discovery:
    container_name: discovery
    build: 
      context: ./discovery-service/
      dockerfile: Dockerfile
    ports: 
      - 8761:8761
    networks:
      - justpickup-network

  owner-gateway:
    container_name: owner-gateway
    build:
      context: ./owner-apigateway-service/
      dockerfile: Dockerfile
    ports:
      - 8001:8001
    networks:
      - justpickup-network
    environment:
      - eureka.client.serviceUrl.defaultZone=http://discovery:8761/eureka/
    depends_on:
      - discovery
  
  customer-gateway:
    container_name: customer-gateway
    build:
      context: ./customer-apigateway-service/
      dockerfile: Dockerfile
    ports:
      - 8000:8000
    networks:
      - justpickup-network
    environment:
      - eureka.client.serviceUrl.defaultZone=http://discovery:8761/eureka/
    depends_on:
      - discovery

  config:
    container_name: config
    build:
      context: ./config-service/
      dockerfile: Dockerfile
    ports:
      - 8888:8888
    networks:
      - justpickup-network

  postgres-db:
    container_name: postgres
    build:
      context: ./postgres_data/
      dockerfile: Dockerfile
    ports:
      - 5432:5432
    networks:
      - justpickup-network

  redis:
    container_name: redis
    image: redis:alpine
    command: redis-server --port 6379
    hostname: redis_boot
    labels:
      - "name=redis"
      - "mode=standalone"
    ports:
      - 6379:6379
    networks:
      - justpickup-network
  
  user-service:
    container_name: user
    build:
      context: ./user-service/
      dockerfile: Dockerfile
    environment:
      - eureka.client.serviceUrl.defaultZone=http://discovery:8761/eureka/
      - spring.config.import=optional:configserver:http://config:8888
      - spring.datasource.url=jdbc:postgresql://postgres:5432/userdb
      - spring.redis.host=redis
    depends_on:
      - discovery
      - config
      - postgres-db
      - redis
    restart: always
    networks:
      - justpickup-network

  order-service:
    container_name: order
    build:
      context: ./order-service/
      dockerfile: Dockerfile
    environment:
      - eureka.client.serviceUrl.defaultZone=http://discovery:8761/eureka/
      - spring.datasource.url=jdbc:postgresql://postgres:5432/orderdb
      - kafka.host=172.18.0.101
      - kafka.port=9092
    depends_on:
      - discovery
      - config
      - postgres-db
      - kafka
    restart: always
    networks:
      - justpickup-network

  store-service:
    container_name: store
    build:
      context: ./store-service/
      dockerfile: Dockerfile
    environment:
      - eureka.client.serviceUrl.defaultZone=http://discovery:8761/eureka/
      - spring.datasource.url=jdbc:postgresql://postgres:5432/storedb
    depends_on:
      - discovery
      - config
      - postgres-db
    restart: always
    networks:
      - justpickup-network
  
  notification-service:
    container_name: notification
    build:
      context: ./notification-service/
      dockerfile: Dockerfile
    environment:
      - eureka.client.serviceUrl.defaultZone=http://discovery:8761/eureka/
      - spring.datasource.url=jdbc:postgresql://postgres:5432/notificationdb
    depends_on:
      - discovery
      - config
      - postgres-db
    restart: always
    networks:
      - justpickup-network

networks:
  justpickup-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.18.0.0/16
          gateway: 172.18.0.1
    
    
