version: '3'

# sudo mkdir -p /srv/polymatica/data/pgdata
# sudo mkdir -p /srv/polymatica/manager/data/api/migrations/
# sudo mkdir -p /srv/polymatica/manager/data/api/storage/

services:
  traefik:
    image: traefik:2.5
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
      - 18080:8080
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./traefik-docker-provider.yml:/traefik.yml:ro
      - ./routes.yml:/traefik/routes.yaml:ro
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.dashboard.entrypoints=traefik"
      - "traefik.http.routers.dashboard.rule=HostRegexp(`{host:.+}`)"
      - "traefik.http.routers.dashboard.service=api@internal"
      - "traefik.http.services.traefik-dashboard.loadbalancer.server.port=8080"
    networks:
      - polymatica


  core:
    container_name: manager-backend
    restart: always
    image: registry.gitlab.ptnl.moscow/platform/manager/backend:e6921aad
    networks:
      - polymatica
    environment:
      - POLYMATICA_CORE_CACHE_TYPE=postgres
      - POLYMATICA_CORE_CACHE_DSN=postgres://polymatica:polymatica-secret@postgresql:5432/platform_manager_cache
      - POLYMATICA_CORE_CACHE_DB=platform-dev-datasets
      - POLYMATICA_CORE_STRUCT_DB_TYPE=postgres
      - POLYMATICA_CORE_STRUCT_DB_DSN=postgres://polymatica:polymatica-secret@postgresql:5432/platform_manager
      - POLYMATICA_CORE_STORAGE_PATH=/usr/share/poly/manager/storage/
      - POLYMATICA_CORE_REDIS_HOST=redis
      - POLYMATICA_CORE_LICENSE_FILE_PATH=/etc/polymatica/platform/manager/license.key
      - POLYMATICA_CORE_HOST=0.0.0.0
      - POLYMATICA_CORE_PORT=8081
    volumes:
      - /srv/polymatica/manager/data/api/migrations/:/usr/share/poly/manager/migrations/
      - /srv/polymatica/data/manager/api/storage/:/usr/share/poly/manager/storage/
#      - /srv/polymatica/license.key:/etc/polymatica/platform/manager/license.key
    # ports:
    #  - "8081:8081"
    depends_on:
      - postgresql
      - redis
      # - mongo
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.manager-api.entrypoints=http"
      - "traefik.http.routers.manager-api.rule=HostRegexp(`{host:.+}`) && PathPrefix(`/api`, `/api/v2/static`, `/swagger/`)"
 #     - "traefik.http.routers.manager-api.priority=100"
      - "traefik.http.routers.manager-api-https.tls=true"
      - "traefik.http.routers.manager-api-https.entrypoints=https"
      - "traefik.http.routers.manager-api-https.rule=HostRegexp(`{host:.+}`) && PathPrefix(`/api`, `/api/v2/static`, `/swagger/`)"
      - "traefik.http.services.manager-api-service.loadbalancer.server.port=8081"


  manager-front:
    container_name: manager-front
    restart: always
    image: registry.gitlab.ptnl.moscow/platform/manager/frontend:32e08c3b
    networks:
      - polymatica
    environment:
      - LC_ALL=C.UTF-8
      - LANG=C.UTF-8
    volumes:
      - /srv/polymatica/manager/data/api/storage/:/usr/share/poly/manager/storage/
    # ports:
    #  - "8081:8081"
    depends_on:
      - postgresql
      # - redis
      # - mongo
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.manager-frontend.entrypoints=http"
      - "traefik.http.routers.manager-frontend.rule=HostRegexp(`{host:.+}`)"
#      - "traefik.http.routers.manager-frontend.priority=1"
      - "traefik.http.routers.manager-frontend-https.tls=true"
      - "traefik.http.routers.manager-frontend-https.entrypoints=https"
      - "traefik.http.routers.manager-frontend-https.rule=HostRegexp(`{host:.+}`)"
      - "traefik.http.services.manager-frontend-service.loadbalancer.server.port=80"

  dashboard-api:
    container_name: dashboard-api
    restart: always
    image: registry.gitlab.ptnl.moscow/platform/dashboards/backend:d6626d48
    networks:
      - polymatica
    environment:
      - POLYMATICA_DASHBOARD_CORE_URL=http://core:8081
      - POLYMATICA_DASHBOARD_BACK_URL=http://dashboard-api:8081
      - POLYMATICA_DASHBOARD_STRUCT_DB_TYPE=postgres
      - POLYMATICA_DASHBOARD_STRUCT_DB_DSN=postgres://polymatica:polymatica-secret@postgresql:5432/platform_dashboard
      - POLYMATICA_DASHBOARD_PORT=8081
      - POLYMATICA_DASHBOARD_HOST=0.0.0.0
    # ports:
    #  - "8081:8081"
    depends_on:
      - postgresql
      # - redis
      # - mongo
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.dashboard-api.entrypoints=http"
      - "traefik.http.routers.dashboard-api.rule=HostRegexp(`{host:.+}`) && PathPrefix(`/dashboard/api`, `/dashboard/swagger/`)"
#      - "traefik.http.routers.dashboard-api.priority=300"
      - "traefik.http.routers.dashboard-api.middlewares=dashboard-strip"
#      - "traefik.http.middlewares.dashboard-strip.stripprefix.forceslash=true"
      - "traefik.http.routers.dashboard-api-https.tls=true"
      - "traefik.http.routers.dashboard-api-https.entrypoints=https"
      - "traefik.http.routers.dashboard-api-https.rule=HostRegexp(`{host:.+}`) && PathPrefix(`/dashboard/api`, `/dashboard/swagger/`)"
      - "traefik.http.routers.dashboard-api-https.middlewares=dashboard-strip"
      - "traefik.http.middlewares.dashboard-strip.stripprefix.prefixes=/dashboard"
#      - "traefik.http.middlewares.dashboard-strip.stripprefix.forceslash=true"
      - "traefik.http.middlewares.dashboard-strip.stripprefix.forceslash=false"
      - "traefik.http.services.dashboard-api.loadbalancer.server.port=8081"


  dashboard-front:
    container_name: dashboard-front
    restart: always
    image: registry.gitlab.ptnl.moscow/platform/dashboards/frontend:9f0de0be
    networks:
      - polymatica
    environment:
      - LC_ALL=C.UTF-8
      - LANG=C.UTF-8
#    ports:
#     - "8081:8081"
    depends_on:
      - postgresql
      # - redis
      # - mongo
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.dashboard-front.entrypoints=http"
      - "traefik.http.routers.dashboard-front.rule=HostRegexp(`{host:.+}`) && PathPrefix(`/dashboard`)"
#      - "traefik.http.routers.dashboard-front.priority=299"
      - "traefik.http.routers.dashboard-front.middlewares=dashboard-strip"
#      - "traefik.http.middlewares.dashboard-strip.stripprefix.forceslash=true"
      - "traefik.http.routers.dashboard-front-https.tls=true"
      - "traefik.http.routers.dashboard-front-https.entrypoints=https"
      - "traefik.http.routers.dashboard-front-https.rule=HostRegexp(`{host:.+}`) && PathPrefix(`/dashboard`)"
      - "traefik.http.services.dashboard-front-service.loadbalancer.server.port=80"
      - "traefik.http.routers.dashboard-front-https.middlewares=dashboard-strip"
      - "traefik.http.middlewares.dashboard-strip.stripprefix.prefixes=/dashboard"
#      - "traefik.http.middlewares.dashboard-strip.stripprefix.forceslash=true"
      - "traefik.http.middlewares.dashboard-strip.stripprefix.forceslash=false"


  service-renderer:
    container_name: service-renderer
    restart: always
    image: registry.gitlab.ptnl.moscow/platform/service/renderer:0a556f5f
    networks:
      - polymatica
    environment:
      - LC_ALL=C.UTF-8
      - LANG=C.UTF-8
      - POLYMATICA_RENDERER_HOST=0.0.0.0
      - POLYMATICA_RENDERER_PORT=9604
      - POLYMATICA_RENDERER_MANAGER_RPC_ADDRESS=http://core:8081/
      - POLYMATICA_RENDERER_BACK_URL=http://service-renderer:9604/

  postgresql:
    image: postgres:11
    container_name: polymatica_postgresql
    restart: always
    networks:
      - polymatica
    environment:
      POSTGRES_USER: polymatica
      POSTGRES_PASSWORD: polymatica-secret
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - ./psql_init.sh:/docker-entrypoint-initdb.d/init-database.sh
      - /srv/polymatica/data/pgdata:/var/lib/postgresql/data/pgdata

  redis:
    image: redis:6-alpine
    restart: always
    networks:
      - polymatica

networks:
  polymatica:

