# Copyright(c) 2022 aasaam software development group
version: "3.7"

services:
  metaflow-service:
    image: netflixoss/metaflow_metadata_service:v2.4.3
    restart: always
    container_name: metaflow-service
    ports:
      - "${MF_MIGRATION_PORT:-8082}:${MF_MIGRATION_PORT:-8082}"
      - "${MF_METADATA_PORT:-8080}:${MF_METADATA_PORT:-8080}"
    environment:
      - MF_METADATA_DB_HOST=${MF_METADATA_DB_HOST}
      - MF_METADATA_DB_PORT=5432
      - MF_METADATA_DB_USER=${POSTGRES_USER}
      - MF_METADATA_DB_PSWD=${POSTGRES_PASSWORD}
      - MF_METADATA_DB_NAME=${POSTGRES_DB}
      - MF_MIGRATION_ENDPOINTS_ENABLED=1
      - MF_METADATA_PORT=${MF_METADATA_PORT:-8080}
      - MF_METADATA_HOST=${MF_METADATA_HOST:-0.0.0.0}
      - MF_MIGRATION_PORT=${MF_MIGRATION_PORT:-8082}
    depends_on:
      - metaflow-postgres
    volumes:
      - ./metaflow-service:/code
      - ./metaflow-service/services:/root/services
    networks:
      - metaflow-net

  metaflow-ui-backend:
    image: ghcr.io/rezashabrang/metaflow-ui-backend:latest
    restart: always
    container_name: metaflow-ui-backend
    ports:
      - "8083:8083"
    environment:
      - MF_METADATA_DB_HOST=${MF_METADATA_DB_HOST}
      - MF_METADATA_DB_PORT=5432
      - MF_METADATA_DB_USER=${POSTGRES_USER}
      - MF_METADATA_DB_PSWD=${POSTGRES_PASSWORD}
      - MF_METADATA_DB_NAME=${POSTGRES_DB}
      - MF_UI_METADATA_PORT=${MF_UI_METADATA_PORT:-8083}
      - MF_UI_METADATA_HOST=${MF_UI_METADATA_HOST:-0.0.0.0}
      - MF_METADATA_DB_POOL_MIN=1
      - MF_METADATA_DB_POOL_MAX=10
      - LOGLEVEL=INFO
      - AIOPG_ECHO=0
      - UI_ENABLED=1
      - PREFETCH_RUNS_SINCE=2592000 # 30 days in seconds
      - PREFETCH_RUNS_LIMIT=1 # Prefetch only one run
      # - S3_NUM_WORKERS=2
      - CACHE_ARTIFACT_MAX_ACTIONS=4
      - CACHE_DAG_MAX_ACTIONS=4
      - CACHE_ARTIFACT_STORAGE_LIMIT=16000000
      - CACHE_DAG_STORAGE_LIMIT=16000000
      - WS_POSTPROCESS_CONCURRENCY_LIMIT=8
      - FEATURE_PREFETCH_DISABLE=0
      - FEATURE_CACHE_DISABLE=0
      - FEATURE_S3_DISABLE=0
      - FEATURE_REFINE_DISABLE=0
      - FEATURE_WS_DISABLE=0
      - FEATURE_HEARTBEAT_DISABLE=0
      - FEATURE_DB_LISTEN_DISABLE=0
      - FEATURE_ARTIFACT_SEARCH=1
      - FEATURE_ARTIFACT_TABLE=1
      # - CUSTOM_QUICKLINKS=$CUSTOM_QUICKLINKS
      # - NOTIFICATIONS=$NOTIFICATIONS
      - GA_TRACKING_ID=none
      # - PLUGINS=$PLUGINS
    # volumes:
    #   - ./metaflow-service/services:/root/services
      # - ${HOME}/.aws:/root/.aws
    depends_on:
      - metaflow-postgres
      - metaflow-service
    networks:
      - metaflow-net

  metaflow-postgres:
    image: postgres:15.3
    restart: always
    container_name: metaflow-postgres
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
    ports:
      - "5433:5432"
    volumes:
      - metaflow-db-vol:/var/lib/postgresql/data
    networks:
      - metaflow-net

  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin-metaflow
    restart: always
    ports:
      - "8084:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: rezashabrang.m@gmail.com
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
    volumes:
      - pg-metaflow-vol:/var/lib/pgadmin
    depends_on:
      - metaflow-postgres
    networks:
      - metaflow-net

networks:
  metaflow-net:
    name: metaflow-net

volumes:
  metaflow-db-vol:
    name: metaflow-db-vol
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: './metaflow-volume/'

  pg-metaflow-vol:
    name: pg-metaflow-vol
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: './pgadmin-volume/'
