version: "3.9"

services:
  api-registry:
    env_file: ../.env.local
    environment:
      - CONSUL_HTTP_TOKEN=784746ec-0d5d-fb12-1a79-95f912dcaabd
      - VAULT_TOKEN=hvs.dZL3N8PAozQ7EbOYFFDeipui # ROOT TOKEN
      # - VAULT_TOKEN=hvs.CAESICxuTO_JieCbpMoZ4_qOPIohxSKim_4V8t11JLg93RtKGh4KHGh2cy5VUUFqUm5CdTQ3V3hMQ3BHSDB4dThNZHE
    volumes:
      - ../certs/api-registry/api-registry.crt:/etc/certs/registry.local.crt:ro
      # - ../certs/ca/vault-root.pem:/usr/local/share/ca-certificates/vaultCA.pem:ro

  api-gateway:
    env_file: ../.env.local
    environment:
      - CONSUL_HTTP_TOKEN=784746ec-0d5d-fb12-1a79-95f912dcaabd
      - VAULT_TOKEN=hvs.dZL3N8PAozQ7EbOYFFDeipui # ROOT TOKEN
      # - VAULT_TOKEN=hvs.CAESICxuTO_JieCbpMoZ4_qOPIohxSKim_4V8t11JLg93RtKGh4KHGh2cy5VUUFqUm5CdTQ3V3hMQ3BHSDB4dThNZHE
    volumes:
      - ../certs/api-gateway/api-gateway.crt:/etc/certs/gateway.local.crt:ro
      # - ../certs/ca/vault-root.pem:/usr/local/share/ca-certificates/vaultCA.pem:ro

  api-vault:
    env_file: ../.env.local
    # command: ["vault", "server", "-dev", "-dev-tls", "-dev-listen-address=0.0.0.0:8200", "-dev-root-token-id=dev-vault-token"]
    environment:
      - CONSUL_HTTP_TOKEN=784746ec-0d5d-fb12-1a79-95f912dcaabd
      - VAULT_TOKEN=hvs.dZL3N8PAozQ7EbOYFFDeipui # ROOT TOKEN
      # - VAULT_TOKEN=hvs.CAESICxuTO_JieCbpMoZ4_qOPIohxSKim_4V8t11JLg93RtKGh4KHGh2cy5VUUFqUm5CdTQ3V3hMQ3BHSDB4dThNZHE
    volumes:
      - ../certs/api-vault/api-vault.crt:/etc/certs/vault.crt:ro
      # - ../certs/ca/vault-root.pem:/usr/local/share/ca-certificates/vaultCA.pem:ro
    ports:
      - 48250:8200

  api-eventbus:
    env_file: ../.env.local
    volumes:
      - ../certs/api-eventbus/api-eventbus.crt:/etc/certs/eventbus.local.crt:ro
      # - ../certs/api-eventbus/eventbus.key:/etc/certs/eventbus.local.key:ro
    labels:
      - traefik.tcp.routers.eventbus.rule=HostSNI(`esb.service.ego.io`)
    ports:
      - 48200:15672
      - 48201:5672
  
  api-cache:
    env_file: ../.env.local
    command: ["redis-server", "/etc/redis.conf", "--requirepass", "12345678"]
    ports:
      - 48300:6379

  api-logger:
    env_file: ../.env.local
    ports:
      - 48400:24224

  # api-prometheus:
  #   ports:
  #     - 9090:9090

  # api-grafana:
  #   ports:
  #     - 3000:3000

  db-postgres:
    env_file: ../.env.local
    ports:
      - 48500:5432

  # db-mongo:
  #   env_file: ../.env.local
  #   environment:
  #     - APP_DOMAIN=mongodb.egommerce.local # FIXME
  #   ports:
  #     - 48600:27017

  identity-svc:
    deploy:
      mode: replicated
      replicas: 0
    env_file: ../.env.local
    environment:
      - DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce
      - MONGODB_URL=mongodb://mongodb:12345678@mongo-db:27017
      # - EVENTBUS_URL=amqp://guest:guest@esb.service.ego.io:5672
      - EVENTBUS_URL=amqp://guest:guest@api-eventbus:5672
    ports:
      - 48780:443

  catalog-svc:
    deploy:
      mode: replicated
      replicas: 1
    env_file: ../.env.local
    environment:
      - DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce
      - MONGODB_URL=mongodb://mongodb:12345678@mongo-db:27017
      - EVENTBUS_URL=amqp://guest:guest@api-eventbus:5672
    ports:
      - 48781:443

  basket-svc:
    deploy:
      mode: replicated
      replicas: 0
    env_file: ../.env.local
    environment:
      - DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce
      - MONGODB_URL=mongodb://mongodb:12345678@mongo-db:27017
      - EVENTBUS_URL=amqp://guest:guest@api-eventbus:5672
    ports:
      - 48782:443

  order-svc:
    deploy:
      mode: replicated
      replicas: 0
    env_file: ../.env.local
    environment:
      - DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce
      - MONGODB_URL=mongodb://mongodb:12345678@mongo-db:27017
      - EVENTBUS_URL=amqp://guest:guest@api-eventbus:5672
    ports:
      - 48783:443

  pricing-svc:
    deploy:
      mode: replicated
      replicas: 0
    env_file: ../.env.local
    environment:
      - DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce
      - MONGODB_URL=mongodb://mongodb:12345678@mongo-db:27017
      - EVENTBUS_URL=amqp://guest:guest@api-eventbus:5672
    ports:
      - 48784:443

  # Workers (EventBus)
  basket-worker:
    deploy:
      mode: replicated
      replicas: 0
    env_file: ../.env.local
    environment:
      - DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce
      - MONGODB_URL=mongodb://mongodb:12345678@mongo-db:27017
      - EVENTBUS_URL=amqp://guest:guest@api-eventbus:5672

  catalog-worker:
    deploy:
      mode: replicated
      replicas: 0
    env_file: ../.env.local
    environment:
      - DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce
      - MONGODB_URL=mongodb://mongodb:12345678@mongo-db:27017
      - EVENTBUS_URL=amqp://guest:guest@api-eventbus:5672

  pricing-worker:
    deploy:
      mode: replicated
      replicas: 0
    env_file: ../.env.local
    environment:
      - DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce
      - MONGODB_URL=mongodb://mongodb:12345678@mongo-db:27017
      - EVENTBUS_URL=amqp://guest:guest@api-eventbus:5672

  order-worker:
    deploy:
      mode: replicated
      replicas: 0
    env_file: ../.env.local
    environment:
      - DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce
      - MONGODB_URL=mongodb://mongodb:12345678@mongo-db:27017
      - EVENTBUS_URL=amqp://guest:guest@api-eventbus:5672
