services:
  nats:
    container_name: nats
    image: nats:alpine
    ports:
      - "4222:4222"
      - "8222:8222"

  cc-metric-store:
    container_name: cc-metric-store
    build:
      context: ./cc-metric-store
    ports:
      - "8084:8084"
    volumes:
      - ${DATADIR}/cc-metric-store:/data
    depends_on:
      - nats

  influxdb:
    container_name: influxdb
    image: influxdb:latest
    command: ["--reporting-disabled", "--log-level=debug"]
    environment:
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_INIT_USERNAME: devel
      DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_PASSWORD}
      DOCKER_INFLUXDB_INIT_ORG: ${INFLUXDB_ORG}
      DOCKER_INFLUXDB_INIT_BUCKET: ${INFLUXDB_BUCKET}
      DOCKER_INFLUXDB_INIT_RETENTION: 100w
      DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: ${INFLUXDB_ADMIN_TOKEN}
    ports:
      - "127.0.0.1:${INFLUXDB_PORT}:8086"
    volumes:
      - ${DATADIR}/influxdb/data:/var/lib/influxdb2
      - ${DATADIR}/influxdb/config:/etc/influxdb2

  openldap:
    container_name: ldap
    image: osixia/openldap:1.5.0
    command: --copy-service --loglevel debug
    environment:
      - LDAP_ADMIN_PASSWORD=${LDAP_ADMIN_PASSWORD}
      - LDAP_ORGANISATION=${LDAP_ORGANISATION}
      - LDAP_DOMAIN=${LDAP_DOMAIN}
    volumes:
      - ${DATADIR}/ldap:/container/service/slapd/assets/config/bootstrap/ldif/custom

  mariadb:
    container_name: mariadb
    image: mariadb:latest
    command: ["--default-authentication-plugin=mysql_native_password"]
    environment:
      MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
      MARIADB_DATABASE: slurm_acct_db
      MARIADB_USER: slurm
      MARIADB_PASSWORD: demo
    ports:
      - "127.0.0.1:${MARIADB_PORT}:3306"
    volumes:
      - ${DATADIR}/mariadb:/etc/mysql/conf.d
      # - ${DATADIR}/sql-init:/docker-entrypoint-initdb.d
    cap_add:
      - SYS_NICE

  slurmctld:
    container_name: slurmctld
    hostname: slurmctld
    build:
      context: ./slurm/controller
    privileged: true
    volumes:
      - ${DATADIR}/slurm/home:/home
      - ${DATADIR}/slurm/secret:/.secret
      - ./slurm/controller/slurm.conf:/home/config/slurm.conf
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
      - ${DATADIR}/slurm/state:/var/lib/slurm/d
    ports:
      - "6817:6817"

  slurmdbd:
    container_name: slurmdbd
    hostname: slurmdbd
    build:
      context: ./slurm/database
    depends_on:
      - mariadb
      - slurmctld
    privileged: true
    volumes:
      - ${DATADIR}/slurm/home:/home
      - ${DATADIR}/slurm/secret:/.secret
      - ${DATADIR}/slurm/tmp:/tmp:rw
      - ./slurm/database/slurmdbd.conf:/home/config/slurmdbd.conf
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
      - ${DATADIR}/slurm/state:/var/lib/slurm/d
    ports:
      - "6819:6819"

  node01:
    container_name: node01
    hostname: node01
    build:
      context: ./slurm/worker
    depends_on:
      - slurmctld
    privileged: true
    volumes:
      - ${DATADIR}/slurm/home:/home
      - ${DATADIR}/slurm/secret:/.secret
      - ${DATADIR}/slurm/tmp:/tmp:rw
      - ./slurm/worker/cgroup.conf:/home/config/cgroup.conf
      - ./slurm/controller/slurm.conf:/home/config/slurm.conf
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "6818:6818"

  slurmrestd:
    container_name: slurmrestd
    hostname: slurmrestd
    build:
      context: ./slurm/rest
      args:
        uid_u: ${UID_U}
        gid_g: ${GID_G}
    depends_on:
      - slurmctld
    privileged: true
    volumes:
      - ${DATADIR}/slurm/home:/home
      - ${DATADIR}/slurm/secret:/.secret
      - ${DATADIR}/slurm/tmp:/tmp:rw
      - ./slurm/controller/slurm.conf:/home/config/slurm.conf
      - ./slurm/rest/slurmrestd.conf:/home/config/slurmrestd.conf
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "6820:6820"