version: "3.9"

services:
  api-gateway:
    image: git.pbiernat.dev/egommerce/api-gateway:latest
    # command:
    #   - '--providers.consulcatalog.refreshinterval=5s'
    # FIXME ^^ only on config option: static/env/cli must be selected
    environment:
      - APP_NAME=api-gateway
      - APP_DOMAIN
      - API_REGISTRY_REFRESH_INTERVAL=5s
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - api-gateway-network
      - api-registry-network
      - api-logger-network

  api-registry:
    image: git.pbiernat.dev/egommerce/api-registry:latest
    environment:
      - APP_NAME=api-registry
      - APP_DOMAIN
      - CONSUL_HTTP_TOKEN=VeryS3cr3tTok3N
    volumes:
      - registry_data:/consul/data
    networks:
      - api-registry-network
      - api-logger-network

  api-eventbus:
    image: git.pbiernat.dev/egommerce/api-eventbus:latest
    environment:
      # - RABBITMQ_NODENAME=api-eventbus
      - RABBITMQ_ERLANG_COOKIE=rabbitmq
      - APP_NAME=api-eventbus
      - APP_DOMAIN
    volumes:
      - eventbus_data:/var/lib/rabbitmq
      - eventbus_logs:/var/log/rabbitmq
    networks:
      - api-gateway-network
      - api-eventbus-network
      - api-registry-network
      - api-logger-network
    
  api-cache:
    image: git.pbiernat.dev/egommerce/api-cache:latest
    environment:
      - APP_NAME=api-cache
    networks:
      - api-cache-network
      - api-logger-network

  api-logger:
    image: git.pbiernat.dev/egommerce/api-logger:latest
    environment:
      - APP_NAME=api-logger
      - APP_DOMAIN
    networks:
      - api-logger-network
  
  #api-prometheus:
  #  image: prom/prometheus:latest # FIXME: create private image(prod/dev)...
  #  user: root
  #  environment:
  #    - APP_NAME=api-prometheus
  #    - APP_DOMAIN
  #  volumes:
  #    - ./etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
  #    - /var/run/docker.sock:/var/run/docker.sock
  #  networks:
  #    - api-prometheus-network
      #- api-grafana-network
  #    - api-gateway-network
  #    - api-registry-network
  #    - api-eventbus-network
      # - api-cache-network
      # - api-logger-network
  #    - basket-svc-network
  #    - basket-worker-network
  #    - catalog-svc-network
  #    - catalog-worker-network
  #    - identity-svc-network
  #    - order-svc-network
  #    - order-worker-network
  #    - pricing-svc-network
  #    - pricing-worker-network

  #api-grafana:
  #  image: grafana/grafana-oss:latest # FIXME: create private image(prod/dev)...
  #  environment:
  #    - APP_NAME=api-grafana
  #    - APP_DOMAIN
  #  volumes:
  #    - grafana-db:/var/lib/grafana
  #  networks:
  #    - api-grafana-network

  postgres-db:
    image: postgres:14.1-alpine
    environment:
      - APP_NAME=postgres-db
      - APP_DOMAIN
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./db_migrations/init/:/docker-entrypoint-initdb.d/
    networks:
      - postgres-db-network
      - api-logger-network

  mongo-db:
    image: mongo:5.0.14
    environment:
      - APP_NAME=mongo-db
      - APP_DOMAIN
      - MONGO_INITDB_ROOT_USERNAME=mongodb
      - MONGO_INITDB_ROOT_PASSWORD
    volumes:
      - mongodb_data:/data/db
    networks:
      - mongodb-db-network
      - api-logger-network

  # API micro-services
  identity-svc:
    image: git.pbiernat.dev/egommerce/identity-svc:latest
    environment:
      - APP_NAME=identity-svc
      - APP_PATH_PREFIX=/identity
      - APP_DOMAIN
      - APP_KV_NAMESPACE
      - DATABASE_URL
      - MONGODB_URL
      - EVENTBUS_URL
    volumes:
      - ./db_migrations/identity-svc:/migrations
    networks:
      - identity-svc-network
      - api-gateway-network
      - api-registry-network
      - api-eventbus-network
      - api-logger-network
      - postgres-db-network
      - mongodb-db-network

  basket-svc:
    image: git.pbiernat.dev/egommerce/basket-svc:latest
    environment:
      - APP_NAME=basket-svc
      - APP_PATH_PREFIX=/basket
      - APP_DOMAIN
      - APP_KV_NAMESPACE
      - DATABASE_URL
      - MONGODB_URL
      - EVENTBUS_URL
    volumes:
      - ./db_migrations/basket-svc:/migrations
    networks:
      - basket-svc-network
      - order-svc-network
      - pricing-svc-network
      - api-gateway-network
      - api-registry-network
      - api-eventbus-network
      - api-logger-network
      - postgres-db-network
      - mongodb-db-network

  catalog-svc:
    image: git.pbiernat.dev/egommerce/catalog-svc:latest
    environment:
      - APP_NAME=catalog-svc
      - APP_PATH_PREFIX=/catalog
      - APP_DOMAIN
      - APP_KV_NAMESPACE
      - DATABASE_URL
      - MONGODB_URL
      - EVENTBUS_URL
    volumes:
      - ./db_migrations/catalog-svc:/migrations
    networks:
      - catalog-svc-network
      - api-gateway-network
      - api-registry-network
      - api-eventbus-network
      - api-logger-network
      - postgres-db-network
      - mongodb-db-network

  pricing-svc:
    image: git.pbiernat.dev/egommerce/pricing-svc:latest
    environment:
      - APP_NAME=pricing-svc
      - APP_PATH_PREFIX=/pricing
      - APP_DOMAIN
      - APP_KV_NAMESPACE
      - DATABASE_URL
      - MONGODB_URL
      - EVENTBUS_URL
    volumes:
      - ./db_migrations/pricing-svc:/migrations
    networks:
      - pricing-svc-network
      - api-gateway-network
      - api-registry-network
      - api-eventbus-network
      - api-logger-network
      - postgres-db-network
      - mongodb-db-network

  order-svc:
    image: git.pbiernat.dev/egommerce/order-svc:latest
    environment:
      - APP_NAME=order-svc
      - APP_PATH_PREFIX=/order
      - APP_DOMAIN
      - APP_KV_NAMESPACE
      - DATABASE_URL
      - MONGODB_URL
      - EVENTBUS_URL
    volumes:
      - ./db_migrations/order-svc:/migrations
    networks:
      - order-svc-network
      - api-gateway-network
      - api-registry-network
      - api-eventbus-network
      - api-logger-network
      - postgres-db-network
      - mongodb-db-network

  # Workers (EventBus)
  basket-worker:
    image: git.pbiernat.dev/egommerce/basket-worker:latest
    environment:
      - APP_NAME=basket-worker
      - APP_KV_NAMESPACE
      - DATABASE_URL
      - MONGODB_URL
      - EVENTBUS_URL
    networks:
      - basket-worker-network
      - pricing-svc-network
      - api-gateway-network
      - api-registry-network
      - api-eventbus-network
      - api-logger-network
      - postgres-db-network
      - mongodb-db-network

  catalog-worker:
    image: git.pbiernat.dev/egommerce/catalog-worker:latest
    environment:
      - APP_NAME=catalog-worker
      - DATABASE_URL
      - MONGODB_URL
      - EVENTBUS_URL
    networks:
      - catalog-worker-network
      - api-gateway-network
      - api-registry-network
      - api-eventbus-network
      - api-logger-network
      - postgres-db-network
      - mongodb-db-network

  pricing-worker:
    image: git.pbiernat.dev/egommerce/pricing-worker:latest
    environment:
      - APP_NAME=pricing-worker
      - DATABASE_URL
      - MONGODB_URL
      - EVENTBUS_URL
    networks:
      - pricing-worker-network
      - api-gateway-network
      - api-registry-network
      - api-eventbus-network
      - api-logger-network
      - postgres-db-network
      - mongodb-db-network

  order-worker:
    image: git.pbiernat.dev/egommerce/order-worker:latest
    environment:
      - APP_NAME=order-worker
      - DATABASE_URL
      - MONGODB_URL
      - EVENTBUS_URL
    networks:
      - order-worker-network
      - basket-svc-network
      - api-gateway-network
      - api-registry-network
      - api-eventbus-network
      - api-logger-network
      - postgres-db-network
      - mongodb-db-network

volumes:
  postgres_data: ~
  mongodb_data: ~
  registry_data: ~
  eventbus_data: ~
  eventbus_logs: ~
  #grafana-db: ~

networks:
  api-gateway-network:
    driver: overlay
    #internal: true

  api-registry-network:
    driver: overlay
    #internal: true

  api-eventbus-network:
    driver: overlay
    #internal: true

  api-cache-network:
    driver: overlay
    #internal: true

  api-logger-network:
    driver: overlay
    #internal: true
  
  api-prometheus-network:
    driver: overlay
    #internal: true

  #api-grafana-network:
  #  driver: overlay
  #  internal: true

  postgres-db-network:
    driver: overlay
    #internal: true

  mongodb-db-network:
    driver: overlay
    #internal: true

  # api micro-services networks
  identity-svc-network:
    driver: overlay
    #internal: true

  basket-svc-network:
    driver: overlay
    #internal: true

  catalog-svc-network:
    driver: overlay
    #internal: true

  pricing-svc-network:
    driver: overlay
    #internal: true

  order-svc-network:
    driver: overlay
    #internal: true

  # Workers networks
  # identity-worker-network:
  #   driver: overlay
  #   internal: true

  basket-worker-network:
    driver: overlay
    #internal: true

  catalog-worker-network:
    driver: overlay
    #internal: true

  pricing-worker-network:
    driver: overlay
    #internal: true

  order-worker-network:
    driver: overlay
    #internal: true