version: "2.3"

services:
  mysql:
    image: mysql:5.5.46
    environment:
      - MYSQL_ROOT_PASSWORD=toxic8_teary

  elasticsearch:
    image: elasticsearch:2.3
    ports:
      - "9200:9200"

  slurm:
    build:
      context: ./slurm
    ports:
      - "42022:22"
    volumes:
      - /tmp/pipedream_virtual_cluster:/tmp/pipedream_virtual_cluster
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker
      - /tmp:/tmp
    hostname: slurm
    entrypoint: "/entrypoint.sh master"

  slurm-worker:
    build:
      context: ./slurm
    ports:
      - "42023:22"
    volumes:
      - /tmp/pipedream_virtual_cluster:/tmp/pipedream_virtual_cluster
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker
      - /tmp:/tmp
    hostname: slurm-worker
    entrypoint: "/entrypoint.sh worker"

  aws-slurm-worker:
    build:
      context: ./slurm
    ports:
      - "42028:22"
    volumes:
      - /tmp/pipedream_virtual_cluster:/tmp/pipedream_virtual_cluster
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker
      - /tmp:/tmp
    hostname: aws-slurm-worker
    entrypoint: "/entrypoint.sh worker"

  postgres_accounting:
    image: "postgres:9.6.6"
    environment:
      POSTGRES_PASSWORD: "secret"
      POSTGRES_USER: "pipedream_accounting"
      POSTGRES_DB: "pipedream_accounting"

  pipedream_accounting:
    image: "docker-registry.zooxlabs.com/pipedream_accounting:${PIPEDREAM_ACCOUNTING_VERSION}"
    ports:
      - "42024:80"
      - "42025:443"
    depends_on:
      - postgres_accounting
    environment:
      PIPEDREAM_ACCOUNTING__POSTGRES__HOST: "postgres_accounting"
      PIPEDREAM_ACCOUNTING__SLURM_STORE__SLURM_SERVICE_HOST: "http://pipedream_slurm"
      PIPEDREAM_ACCOUNTING__SLURM_STORE__NO_CACHING: "true"
    entrypoint: "./entrypoint.sh"

  pipedream_slurm_redis:
    image: redis:6

  pipedream_slurm:
    image: "docker-registry.zooxlabs.com/pipedream_slurm:${PIPEDREAM_SLURM_VERSION}"
    ports:
      - "42026:80"
    environment:
      SLURM_HOST: "slurm"
      MYSQL_HOST: "mysql"
      MYSQL_PASSWORD: "toxic8_teary"
      NO_CACHING: "true"
      REDIS_HOST: "pipedream_slurm_redis"
      REDIS_PREFIX: "test"
      PIPEDREAM_CLUSTER: "test"
      LDAP_PASSWORD: "${LDAP_PASSWORD}"
    entrypoint: "./entrypoint.sh"

  pipedream_slurm_daemon:
    image: "docker-registry.zooxlabs.com/pipedream_slurm:${PIPEDREAM_SLURM_VERSION}"
    environment:
      SLURM_HOST: "slurm"
      MYSQL_HOST: "mysql"
      MYSQL_PASSWORD: "toxic8_teary"
      NO_CACHING: "true"
      REDIS_HOST: "pipedream_slurm_redis"
      REDIS_PREFIX: "test"
      PIPEDREAM_CLUSTER: "test"
      LDAP_PASSWORD: "${LDAP_PASSWORD}"
    entrypoint: "./entrypoint.sh daemon"

  postgres_requeue:
    image: "postgres:9.6.6"
    environment:
      POSTGRES_PASSWORD: "secret"
      POSTGRES_USER: "pipedream_requeue"
      POSTGRES_DB: "pipedream_requeue"

  pipedream_requeue:
    image: "docker-registry.zooxlabs.com/pipedream_requeue:${PIPEDREAM_REQUEUE_VERSION}"
    ports:
      - "42027:80"
    depends_on:
      - postgres_requeue
    environment:
      PIPEDREAM_REQUEUE__POSTGRES__HOST: "postgres_requeue"
      PIPEDREAM_REQUEUE__PIPEDREAM_REQUEUE_CONTROLLER__SLURM_SERVICE_HOST: "http://pipedream_slurm"
    entrypoint: "./entrypoint.sh"

  pipedream_scheduling:
    image: "docker-registry.zooxlabs.com/pipedream_scheduling:${PIPEDREAM_SCHEDULING_VERSION}"
    depends_on:
      - pipedream_accounting
      - vault_integration_tests
      - aws-localstack
    environment:
      PIPEDREAM_USER: "slurm"
      PIPEDREAM_CLUSTER: "test"
      PIPEDREAM_ACCOUNTING_HOST: "http://pipedream_accounting"
      VAULT_ADDR: "http://vault_integration_tests:8200"
      VAULT_TOKEN: "pd_token"
      LDAP_PASSWORD: "${LDAP_PASSWORD}"
      AWS_ACCESS_KEY_ID: "test"
      AWS_SECRET_ACCESS_KEY: "test"
    volumes:
      - "/tmp/pipedream_virtual_cluster:/tmp/pipedream_virtual_cluster"
      - "~/.pipedream/$USER.key:/root/.pipedream/$USER.key"
      - "/tmp"
    ports:
      - "5000:5000"

  pipedream_queue_worker:
    image: "docker-registry.zooxlabs.com/pipedream_queue_worker:${PIPEDREAM_QUEUE_WORKER_VERSION}"
    environment:
      PIPEDREAM_USER: "slurm"
      PIPEDREAM_CLUSTER: "test"
      LDAP_PASSWORD: "${LDAP_PASSWORD}"
      AWS_ACCESS_KEY_ID: "test"
      AWS_SECRET_ACCESS_KEY: "test"
    depends_on:
      - pipedream_accounting
      - vault_integration_tests
      - aws-localstack
    volumes:
      - "/tmp/pipedream_virtual_cluster:/tmp/pipedream_virtual_cluster"
      - "~/.pipedream/$USER.key:/root/.pipedream/$USER.key"
      - "/tmp"

  vault_integration_tests:
    build:
      context: ./vault
    environment:
      VAULT_DEV_ROOT_TOKEN_ID: "root_token"
      VAULT_PIPEDREAM_SCHEDULING_TOKEN: "pd_token"
      VAULT_USER_TOKEN: "user_token"
      SKIP_SETCAP: "true"
    cap_add:
      - IPC_LOCK
    ports:
      - "8200:8200"

  aws-localstack:
    image: localstack/localstack:0.12.1
    ports:
      - "4570:4570"
    environment:
      - SERVICES=sqs:4570
      - DEBUG=1
      - EDGE_PORT=4570
      - DATA_DIR=/tmp/localstack/data
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"

  pipedream_traffic_control:
    image: "docker-registry.zooxlabs.com/pipedream_traffic_control:1.0"
    container_name: pipedream_traffic_control
    cap_add:
      - NET_ADMIN
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/run/netns:/var/run/netns
      - /proc:/procx
    network_mode: host
    privileged: true
