version: "3.3"

volumes:
  ganache-db: {}
  postgres-db: {}
  bee-data: {}
  signer-data: {}
  bloxberg-data: {}
  contract-config: {} 

networks:
  traefik-public:
    # Allow setting it to false for testing
    external: ${TRAEFIK_PUBLIC_NETWORK_IS_EXTERNAL-true}

services:
  proxy:
    image: traefik:v2.2
    networks:
      - ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
      - default
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command:
      # Enable Docker in Traefik, so that it reads labels from Docker services
      - --providers.docker
      # Add a constraint to only use services with the label for this stack
      # from the env var TRAEFIK_TAG
      - --providers.docker.constraints=Label(`traefik.constraint-label-stack`, `${TRAEFIK_TAG?Variable not set}`)
      # Do not expose all Docker services, only the ones explicitly exposed
      - --providers.docker.exposedbydefault=false
      # Enable Docker Swarm mode
      - --providers.docker.swarmmode
      # Enable the access log, with HTTP requests
      - --accesslog
      # Enable the Traefik log, for configurations and errors
      - --log
      # Enable the Dashboard and API
      - --api
    deploy:
      placement:
        constraints:
          - node.role == manager
      labels:
        # Enable Traefik for this service, to make it available in the public network
        - traefik.enable=true
        # Use the traefik-public network (declared below)
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        # Use the custom label "traefik.constraint-label=traefik-public"
        # This public Traefik will only use services with this label
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        # traefik-http set up only to use the middleware to redirect to https
        - traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.scheme=https
        - traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.permanent=true
        # Handle host with and without "www" to redirect to only one of them
        # Uses environment variable DOMAIN
        # To disable www redirection remove the Host() you want to discard, here and
        # below for HTTPS
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.entrypoints=http
        # traefik-https the actual router using HTTPS
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls=true
        # Use the "le" (Let's Encrypt) resolver created below
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls.certresolver=le
        # Define the port inside of the Docker service to use
        - traefik.http.services.${STACK_NAME?Variable not set}-proxy.loadbalancer.server.port=80
        # Handle domain with and without "www" to redirect to only one
        # To disable www redirection remove the next line
        - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^https?://(www.)?(${DOMAIN?Variable not set})/(.*)
        # Redirect a domain with www to non-www
        # To disable it remove the next line
        - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=https://${DOMAIN?Variable not set}/$${3}
        # Redirect a domain without www to www
        # To enable it remove the previous line and uncomment the next
        # - traefik.http.middlewares.${STACK_NAME}-www-redirect.redirectregex.replacement=https://www.${DOMAIN}/$${3}
        # Middleware to redirect www, to disable it remove the next line 
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
        # Middleware to redirect www, and redirect HTTP to HTTPS
        # to disable www redirection remove the section: ${STACK_NAME?Variable not set}-www-redirect,
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.middlewares=${STACK_NAME?Variable not set}-www-redirect,${STACK_NAME?Variable not set}-https-redirect

  cicada:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cicada:latest
    build:
      context: ./apps/cic-staff-client
      args:
        BUILD_ENV: prod
    deploy:
      labels:
        - traefik.enable=true
        - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-cicada-http.rule=PathPrefix(`/`)
        - traefik.http.services.${STACK_NAME?Variable not set}-cicada.loadbalancer.server.port=80

  eth:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/bloxberg-node:${TAG:-latest}
    env_file:
      - .env
    build:
      context: apps/bloxbergValidatorSetup
    ports:
      - 8545
      - 8546
      - 30303
    volumes:
      - ./apps/bloxbergValidatorSetup/keys:/root/keys # stores the signing key locally
      - bloxberg-data:/root/.local/share/io.parity.ethereum/
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-bloxberg-http.rule=Host(`bloxberg.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-bloxberg-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-bloxberg-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-bloxberg-https.rule=Host(`bloxberg.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-bloxberg-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-bloxberg-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-bloxberg-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-bloxberg.loadbalancer.server.port=5050

  # See contents of /initdb/create_db.sql for app user, password and databases
  postgres:
    image: postgres:12.5-alpine
    env_file: 
      - .env
    ports:
      - 5432
    command: [ "-c", "max_connections=200" ]
    deploy:
      placement:
        constraints:
          - node.labels.${STACK_NAME?Variable not set}.app-db-data == true
    volumes:
      - ./scripts/initdb/create_db.sql:/docker-entrypoint-initdb.d/1-create_all_db.sql 
      - postgres-db:/var/lib/postgresql/data

  redis:
    image: redis:6.0.9-alpine
    env_file:
      - .env
    ports:
      - 6379

  pgadmin:
    image: dpage/pgadmin4
    networks:
      - ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
      - default
    env_file:
      - .env
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.rule=Host(`pgadmin.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.rule=Host(`pgadmin.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-pgadmin.loadbalancer.server.port=5050

  flower:
    image: mher/flower
    networks:
      - ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
      - default
    env_file:
      - .env
    command: [ "celery", "--broker=redis://redis:6379", "flower" ] 
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.rule=Host(`flower.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.rule=Host(`flower.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-flower.loadbalancer.server.port=5555

  bee:
    image: ethersphere/bee:0.4.1
    container_name: bee
    env_file:
      - .env
    environment:
      BEE_NETWORK_ID: ${BEE_NETWORK_ID:-313}
      BEE_PASSWORD: ${BEE_PASSWORD:-password}
    ports:
      - ${DEV_BEE_PORT:-63633}:1633
      - ${DEV_BEE_PORT_DEBUG:-63635}:1635
    command: "start --swap-enable=false --standalone"
    volumes:
      - bee-data:/tmp/cic/bee

  contract-migration:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/contract-migration:${TAG:-latest}
    build:
      context: apps/contract-migration
      dockerfile: docker/Dockerfile
      args:
        pip_index_url: ${PIP_DEFAULT_INDEX_URL:-https://pypi.org/simple}
        pip_extra_args: $PIP_EXTRA_ARGS
    # image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/contract-migration:latest
    env_file:
      - .env
    environment:
      # ETH_PROVIDER should be broken out into host/port but cic-eth expects this
      # And these two are for wait-for-it (could parse this)
      DEV_USE_DOCKER_WAIT_SCRIPT: 1
      ETH_PROVIDER_HOST: eth 
      ETH_PROVIDER_PORT: 8545
      CIC_DATA_DIR: ${CIC_DATA_DIR:-/tmp/cic/config}
      DATABASE_NAME: ${DEV_DATABASE_NAME_CIC_ETH:-cic_eth}
      DATABASE_USER: ${DATABASE_USER:-postgres}
      RUN_MASK: ${RUN_MASK:-0} 
      DEV_FAUCET_AMOUNT: ${DEV_FAUCET_AMOUNT:-0}
      #DEV_SARAFU_DEMURRAGE_LEVEL: ${DEV_SARAFU_DEMURRAGE_LEVEL:-196454828847045000000000000000000}
      DEV_ETH_GAS_PRICE: ${DEV_ETH_GAS_PRICE:-1}
      CIC_DEFAULT_TOKEN_SYMBOL: $CIC_DEFAULT_TOKEN_SYMBOL
      TOKEN_NAME: $TOKEN_NAME
      TOKEN_DECIMALS: $TOKEN_DECIMALS
      TOKEN_REDISTRIBUTION_PERIOD: $TOKEN_REDISTRIBUTION_PERIOD
      TOKEN_SUPPLY_LIMIT: $TOKEN_SUPPLY_LIMIT
      TOKEN_DEMURRAGE_LEVEL: ${TOKEN_DEMURRAGE_LEVEL:-196454828847045000000000000000000}
      TOKEN_SINK_ADDRESS: $TOKEN_SINK_ADDRESS
      TOKEN_TYPE: $TOKEN_TYPE
        #CONFINI_DIR: ${CONFINI_DIR:-/tmp/cic/config}
    command: ["./run_job.sh"]
        #command: ["./reset.sh"]
    volumes:
      - contract-config:/tmp/cic/config

  data-seeding:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/data-seeding:${TAG:-latest}
    build:
      context: apps/data-seeding
      dockerfile: docker/Dockerfile
      args:
        pip_index_url: ${PIP_DEFAULT_INDEX_URL:-https://pypi.org/simple}
        pip_extra_args: $PIP_EXTRA_ARGS
    # image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/contract-migration:latest
    environment:
      CIC_REGISTRY_ADDRESS: $CIC_REGISTRY_ADDRESS
      # ETH_PROVIDER should be broken out into host/port but cic-eth expects this
      ETH_PROVIDER: http://eth:8545
      # And these two are for wait-for-it (could parse this)
      CIC_DATA_DIR: ${CIC_DATA_DIR:-/tmp/cic/config}
      DEV_USE_DOCKER_WAIT_SCRIPT: 1
      ETH_PROVIDER_HOST: eth 
      ETH_PROVIDER_PORT: 8545
      REDIS_HOST: ${REDIS_HOST:-redis}
      REDIS_PORT: ${REDIS_PORT:-6379}
      REDIS_DB: ${REDIS_DB:-0}
      CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis:6379}
      CELERY_RESULT_URL: ${CELERY_RESULT_URL:-redis://redis:6379}
      RUN_MASK: ${RUN_MASK:-0} # 7
      TOKEN_SYMBOL: ${TOKEN_SYMBOL:-GFT}
      USER_USSD_HOST: cic-user-ussd-server
      USER_USSD_PORT: 9000
      KEYSTORE_FILE_PATH: "/root/keystore/UTC--2021-01-08T17-18-44.521011372Z--eb3907ecad74a0013c259d5874ae7f22dcbcc95c"
      OUT_DIR: out
      NUMBER_OF_USERS: 10
    command: ["bash", "./scripts/run_job.sh"]
    volumes:
      - contract-config:/tmp/cic/config

  cic-cache-tracker:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-cache:${TAG:-latest}
    build:
      context: apps/cic-cache
      dockerfile: docker/Dockerfile
    environment:
      CIC_REGISTRY_ADDRESS: $CIC_REGISTRY_ADDRESS # supplied at contract-config after contract provisioning
      ETH_PROVIDER: ${ETH_PROVIDER:-http://eth:8545}
      DATABASE_USER: ${DATABASE_USER:-grassroots}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala} # this is is set at initdb see: postgres/initdb/create_db.sql
      DATABASE_HOST: ${DATABASE_HOST:-postgres}
      DATABASE_PORT: ${DATABASE_PORT:-5432}
      DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_cache}
      DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
      DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
      DATABASE_DEBUG: 1
      ETH_ABI_DIR: ${ETH_ABI_DIR:-/usr/local/share/cic/solidity/abi}
      CIC_TRUST_ADDRESS: ${DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER:-0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C}
      CIC_CHAIN_SPEC: ${CIC_CHAIN_SPEC:-evm:bloxberg:8996}
      CELERY_BROKER_URL: redis://redis:6379
      CELERY_RESULT_URL: redis://redis:6379
    deploy: 
      restart_policy:
        condition: on-failure
    command:
      - /bin/bash
      - -c
      - |
        if [[ -f /tmp/cic/config/.env ]]; then source /tmp/cic/config/.env; fi 
        ./start_tracker.sh -c /usr/local/etc/cic-cache -vv
    volumes:
      - contract-config:/tmp/cic/config/:ro

  cic-cache-tasker:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-cache:${TAG:-latest}
    build:
      context: apps/cic-cache
      dockerfile: docker/Dockerfile
    environment:
      CIC_REGISTRY_ADDRESS: $CIC_REGISTRY_ADDRESS # supplied at contract-config after contract provisioning
      ETH_PROVIDER: ${ETH_PROVIDER:-http://eth:8545}
      DATABASE_USER: ${DATABASE_USER:-grassroots}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala} # this is is set at initdb see: postgres/initdb/create_db.sql
      DATABASE_HOST: ${DATABASE_HOST:-postgres}
      DATABASE_PORT: ${DATABASE_PORT:-5432}
      DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_cache}
      DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
      DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
      DATABASE_DEBUG: 1
      DATABASE_POOL_SIZE: 0
      ETH_ABI_DIR: ${ETH_ABI_DIR:-/usr/local/share/cic/solidity/abi}
      CIC_TRUST_ADDRESS: ${DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER:-0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C}
      CIC_CHAIN_SPEC: ${CIC_CHAIN_SPEC:-evm:bloxberg:8996}
      CELERY_BROKER_URL: redis://redis:6379
      CELERY_RESULT_URL: redis://redis:6379
    deploy: 
      restart_policy:
        condition: on-failure
    command:
      - /bin/bash
      - -c
      - |
        if [[ -f /tmp/cic/config/.env ]]; then source /tmp/cic/config/.env; fi 
        /usr/local/bin/cic-cache-taskerd -vv
    volumes:
      - contract-config:/tmp/cic/config/:ro

  cic-cache-server:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-cache:${TAG:-latest}
    build:
      context: apps/cic-cache
      dockerfile: docker/Dockerfile
    environment:
      DATABASE_USER: ${DATABASE_USER:-grassroots}
      DATABASE_HOST: ${DATABASE_HOST:-postgres}
      DATABASE_PORT: ${DATABASE_PORT:-5432}
        #DATABASE_PASSWORD: ${DATABASE_PASSWORD:-
      DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_cache}
      DATABASE_DEBUG: 1
        #PGPASSWORD: $DATABASE_PASSWORD
      SERVER_PORT: 8000
    ports:
      - 8000
    command:
      - /bin/bash
      - -c
      - |
        if [[ -f /tmp/cic/config/.env ]]; then source /tmp/cic/config/.env; fi 
        "/usr/local/bin/uwsgi" \
        --wsgi-file /usr/src/cic-cache/cic_cache/runnable/daemons/server.py \
        --http :8000 \
        --pyargv "-vv"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-cache-http.rule=Host(`cache.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-cache-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-cache-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-cache-https.rule=Host(`cache.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-cache-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-cache-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-cache-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-cache.loadbalancer.server.port=80

  cic-eth-tasker:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-eth:${TAG:-latest}
    build: 
        context: apps/cic-eth
        dockerfile: docker/Dockerfile
    environment:
      CIC_REGISTRY_ADDRESS: $CIC_REGISTRY_ADDRESS
      ETH_GAS_PROVIDER_ADDRESS: $DEV_ETH_ACCOUNT_GAS_PROVIDER
      ETH_PROVIDER: http://eth:8545
      ETH_ABI_DIR: ${ETH_ABI_DIR:-/usr/local/share/cic/solidity/abi}
      DATABASE_USER: ${DATABASE_USER:-grassroots}
      DATABASE_HOST: ${DATABASE_HOST:-postgres}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala}
      DATABASE_NAME: ${DATABASE_NAME_CIC_ETH:-cic_eth}
      DATABASE_PORT: ${DATABASE_PORT:-5432}
      DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
      DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
      DATABASE_DEBUG: ${DATABASE_DEBUG:-0}
      DATABASE_POOL_SIZE: 0
      REDIS_PORT: 6379
      REDIS_HOST: redis
      PGPASSWORD: ${DATABASE_PASSWORD:-tralala}
      CIC_CHAIN_SPEC: ${CIC_CHAIN_SPEC:-evm:bloxberg:8996}
      BANCOR_DIR: ${BANCOR_DIR:-/usr/local/share/cic/bancor}
      CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
      CELERY_RESULT_URL: ${CELERY_RESULT_URL:-redis://redis}
      CELERY_DEBUG: ${CELERY_DEBUG:-1}
      SIGNER_SOCKET_PATH: ${SIGNER_SOCKET_PATH:-ipc:///run/crypto-dev-signer/jsonrpc.ipc}
      SIGNER_SECRET: ${SIGNER_SECRET:-deadbeef}
      ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER: ${DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER:-0xACB0BC74E1686D62dE7DC6414C999EA60C09F0eA}
      TASKS_TRACE_QUEUE_STATUS: ${TASKS_TRACE_QUEUE_STATUS:-1}
      CIC_DEFAULT_TOKEN_SYMBOL: ${CIC_DEFAULT_TOKEN_SYMBOL:-GFT}
    deploy:
      restart_policy:
        condition: on-failure
    volumes:
      - signer-data:/tmp/cic/signer
      - contract-config:/tmp/cic/config/:ro
    command:
      - /bin/bash
      - -c
      - |
        if [[ -f /tmp/cic/config/.env ]]; then source /tmp/cic/config/.env; fi 
        ./start_tasker.sh --aux-all -q cic-eth  -vv
    # command: [/bin/sh, "./start_tasker.sh", -q, cic-eth, -vv ]

  cic-eth-tracker:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-eth:${TAG:-latest}
    build:
        context: apps/cic-eth
        dockerfile: docker/Dockerfile
    environment:
      ETH_PROVIDER: http://eth:8545
      DATABASE_USER: ${DATABASE_USER:-grassroots}
      DATABASE_HOST: ${DATABASE_HOST:-postgres}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala}
      DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_eth}
      DATABASE_PORT: ${DATABASE_PORT:-5432}
      DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
      DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
      DATABASE_DEBUG: ${DATABASE_DEBUG:-0}
      CIC_CHAIN_SPEC: ${CIC_CHAIN_SPEC:-evm:bloxberg:8996}
      CIC_REGISTRY_ADDRESS: $CIC_REGISTRY_ADDRESS
        #BANCOR_DIR: $BANCOR_DIR
      CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
      CELERY_RESULT_URL: ${CELERY_RESULT_URL:-redis://redis}
      TASKS_TRANSFER_CALLBACKS: $TASKS_TRANSFER_CALLBACKS
    deploy:
      restart_policy:
        condition: on-failure
    volumes:
      - contract-config:/tmp/cic/config/:ro
    command:
      - /bin/bash
      - -c
      - |
        if [[ -f /tmp/cic/config/.env ]]; then source /tmp/cic/config/.env; fi 
        ./start_tracker.sh -vv -c /usr/local/etc/cic-eth
    # command: "/root/start_manager.sh head -vv"


  cic-eth-dispatcher:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-eth:${TAG:-latest}
    build:
        context: apps/cic-eth
        dockerfile: docker/Dockerfile
    environment:
      ETH_PROVIDER: http://eth:8545
      DATABASE_USER: ${DATABASE_USER:-grassroots}
      DATABASE_HOST: ${DATABASE_HOST:-postgres}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala}
      DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_eth}
      DATABASE_PORT: ${DATABASE_PORT:-5432}
      DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
      DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
      CIC_CHAIN_SPEC: ${CIC_CHAIN_SPEC:-evm:bloxberg:8996}
      CIC_REGISTRY_ADDRESS: $CIC_REGISTRY_ADDRESS
        #BANCOR_DIR: $BANCOR_DIR
      CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
      CELERY_RESULT_URL: ${CELERY_RESULT_URL:-redis://redis}
      TASKS_TRANSFER_CALLBACKS: $TASKS_TRANSFER_CALLBACKS
      DATABASE_DEBUG: ${DATABASE_DEBUG:-false}
        #DATABASE_DEBUG: 1
    deploy:
      restart_policy:
        condition: on-failure
    volumes:
        - contract-config:/tmp/cic/config/:ro
    command:
      - /bin/bash
      - -c
      - |
        if [[ -f /tmp/cic/config/.env ]]; then source /tmp/cic/config/.env; fi 
        ./start_dispatcher.sh -q cic-eth -vv
    # command: "/root/start_dispatcher.sh -q cic-eth -vv"


  cic-eth-retrier:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-eth:${TAG:-latest}
    build:
        context: apps/cic-eth
        dockerfile: docker/Dockerfile
    environment:
      ETH_PROVIDER: http://eth:8545
      DATABASE_USER: ${DATABASE_USER:-grassroots}
      DATABASE_HOST: ${DATABASE_HOST:-postgres}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala}
      DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_eth}
      DATABASE_PORT: ${DATABASE_PORT:-5432}
      DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
      DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
      DATABASE_DEBUG: ${DATABASE_DEBUG:-0}
      CIC_CHAIN_SPEC: ${CIC_CHAIN_SPEC:-evm:bloxberg:8996}
      CIC_REGISTRY_ADDRESS: $CIC_REGISTRY_ADDRESS
        #BANCOR_DIR: $BANCOR_DIR
      CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
      CELERY_RESULT_URL: ${CELERY_RESULT_URL:-redis://redis}
      TASKS_TRANSFER_CALLBACKS: $TASKS_TRANSFER_CALLBACKS
      CIC_TX_RETRY_DELAY: 60
      BATCH_SIZE: ${RETRIER_BATCH_SIZE:-50}
        #DATABASE_DEBUG: 1
    deploy:
      restart_policy:
        condition: on-failure
    volumes:
        - contract-config:/tmp/cic/config/:ro
    command:
      - /bin/bash
      - -c
      - |
        if [[ -f /tmp/cic/config/.env ]]; then source /tmp/cic/config/.env; fi 
        ./start_retry.sh -vv 
    # command: "/root/start_retry.sh -q cic-eth -vv"



  cic-notify-tasker:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-notify:${TAG:-latest}
    build:
      context: apps/cic-notify
      dockerfile: docker/Dockerfile
    environment:
      DATABASE_USER: ${DATABASE_USER:-grassroots}
      DATABASE_HOST: ${DATABASE_HOST:-postgres}
      DATABASE_PORT: ${DATABASE_PORT:-5432}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala}
      DATABASE_NAME: ${DATABASE_NAME_CIC_NOTIFY:-cic_notify}
      DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
      DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
      DATABASE_POOL_SIZE: 0
      PGPASSWORD: ${DATABASE_PASSWORD:-tralala}
      CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
      CELERY_RESULT_URL: ${CELERY_BROKER_URL:-redis://redis}
      AFRICASTALKING_API_USERNAME: $AFRICASTALKING_API_USERNAME
      AFRICASTALKING_API_KEY: $AFRICASTALKING_API_KEY
      AFRICASTALKING_API_SENDER_ID: $AFRICASTALKING_API_SENDER_ID
    deploy:
      restart_policy:
        condition: on-failure
    command: "/root/start_tasker.sh -q cic-notify -vv"


  cic-meta-server:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-meta:${TAG:-latest}
    hostname: meta
    build:
      context: apps/cic-meta
      dockerfile: docker/Dockerfile
    environment:
      DATABASE_NAME: ${DATABASE_NAME:-cic_meta}
      DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
      DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
      DATABASE_USER: ${DATABASE_USER:-grassroots}
      DATABASE_HOST: ${DATABASE_HOST:-postgres}
      DATABASE_PORT: ${DATABASE_PORT:-5432}
      SERVER_HOST: localhost
      SERVER_PORT: 8000
      DATABASE_SCHEMA_SQL_PATH: ""
      PGP_EXPORTS_DIR: /root/tests/
      PGP_PRIVATEKEY_FILE: privatekeys.asc
      PGP_PASSPHRASE: merman
      PGP_PUBLICKEY_TRUSTED_FILE: publickeys.asc
      PGP_PUBLICKEY_ACTIVE_FILE: publickeys.asc
      PGP_PUBLICKEY_ENCRYPT_FILE: publickeys.asc
      SCHEMA_SQL_PATH: scripts/initdb/server.postgres.sql
    ports:
      - 8000
    volumes:
      - ./apps/contract-migration/testdata/pgp/:/tmp/cic/pgp
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-meta-http.rule=Host(`meta.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-meta-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-meta-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-meta-https.rule=Host(`meta.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-meta-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-meta-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-meta-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-meta.loadbalancer.server.port=80
    # command: "/root/start_server.sh -vv"

  cic-user-ussd-server:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-ussd:${TAG:-latest}
    build:
      context: apps/cic-ussd
      dockerfile: docker/Dockerfile
    environment:
      APP_PASSWORD_PEPPER: ${APP_PASSWORD_PEPPER:-"QYbzKff6NhiQzY3ygl2BkiKOpER8RE/Upqs/5aZWW+I="}
      DATABASE_USER: grassroots
      DATABASE_HOST: postgres
      DATABASE_PORT: 5432
      DATABASE_PASSWORD: tralala
      DATABASE_NAME: cic_ussd
      DATABASE_ENGINE: postgresql
      DATABASE_DRIVER: psycopg2
      CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
      CELERY_RESULT_URL: ${CELERY_BROKER_URL:-redis://redis}
      PGP_PASSPHRASE: merman
      SERVER_PORT: 9000
      CIC_META_URL: ${CIC_META_URL:-http://meta:8000}
    ports:
      - 9000
    volumes:
      - ./apps/contract-migration/testdata/pgp/:/usr/src/secrets/
    command: "/root/start_cic_user_ussd_server.sh -vv"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-ussd-http.rule=Host(`ussd.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-ussd-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-ussd-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-ussd-https.rule=Host(`ussd.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-ussd-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-ussd-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-ussd-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-ussd.loadbalancer.server.port=80

  cic-user-server:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-ussd:${TAG:-latest}
    build:
      context: apps/cic-ussd
      dockerfile: docker/Dockerfile
    environment:
      APP_PASSWORD_PEPPER: ${APP_PASSWORD_PEPPER:-"QYbzKff6NhiQzY3ygl2BkiKOpER8RE/Upqs/5aZWW+I="}
      DATABASE_USER: grassroots
      DATABASE_HOST: postgres
      DATABASE_PORT: 5432
      DATABASE_PASSWORD: tralala
      DATABASE_NAME: cic_ussd
      DATABASE_ENGINE: postgresql
      DATABASE_DRIVER: psycopg2
      DATABASE_POOL_SIZE: 0
    ports:
      - 9500
    command: "/root/start_cic_user_server.sh -vv"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-user-http.rule=Host(`user.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-user-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-user-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-user-https.rule=Host(`user.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-user-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-user-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-user-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-user.loadbalancer.server.port=80

  cic-user-tasker:
    image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/cic-ussd:${TAG:-latest}
    build:
      context: apps/cic-ussd/
      dockerfile: docker/Dockerfile
    environment:
      APP_PASSWORD_PEPPER: ${APP_PASSWORD_PEPPER:-"QYbzKff6NhiQzY3ygl2BkiKOpER8RE/Upqs/5aZWW+I="}
      DATABASE_USER: grassroots
      DATABASE_HOST: postgres
      DATABASE_PORT: 5432
      DATABASE_PASSWORD: tralala
      DATABASE_NAME: cic_ussd
      DATABASE_ENGINE: postgresql
      DATABASE_DRIVER: psycopg2
      DATABASE_POOL_SIZE: 0
      CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
      CELERY_RESULT_URL: ${CELERY_BROKER_URL:-redis://redis}
      PGP_PASSPHRASE: merman
      CIC_META_URL: ${CIC_META_URL:-http://meta:8000}
    volumes:
      - ./apps/contract-migration/testdata/pgp/:/usr/src/secrets/
    deploy:
      restart_policy:
        condition: on-failure
    command: "/root/start_cic_user_tasker.sh -q cic-ussd -vv"
