# docker swarm init, then you have to do // note version_mpinet is the name of the overlay
# docker network create --driver=overlay --attachable yml_mpinet
# Jan, 17, 2025 - Jean-Michel Batto

services:
  grafana:
    container_name: influxdb_local
    image: philhawthorne/docker-influxdb-grafana:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - usrlocalinfluxdb-foo:/var/lib/influxdb
      - usrlocalgrafana-foo:/var/lib/grafana
    ports: 
      - "3003:3003"
      - "3004:8083"
      - "8086:8086"
    networks:
      - mpinet
  mpihead:
    image: jmbatto/m2chps-mpi41-xmp:latest
    hostname: mpihead
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - usrlocalvarmpi-foo:/usr/local/var/mpishare
    shm_size: '512m'
    ports: 
      - "2022:22"
    links: 
      - mpinode1
      - mpinode2
      - mpinode3
    networks:
      - mpinet
    secrets:                   
      - source: "id_rsa"
        target: "/home/mpiuser/.ssh-source/id_rsa"
      - source: "id_rsa_mpi_pub"
        target: "/home/mpiuser/.ssh-source/id_rsa.pub"
      - source: "authorized_keys"
        target: "/home/mpiuser/.ssh-source/authorized_keys"
      - source: "install_clang_format_go.sh"
        target: "/home/mpiuser/.ssh-source/install_clang_format_go.sh"
    depends_on:
      - grafana
  mpinode1:
    image: jmbatto/m2chps-mpi41-xmp:latest
    hostname: mpinode1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - usrlocalvarmpi-foo:/usr/local/var/mpishare
    shm_size: '512m'
    networks:
      - mpinet
    secrets:                   
      - source: "id_rsa"
        target: "/home/mpiuser/.ssh-source/id_rsa"
      - source: "id_rsa_mpi_pub"
        target: "/home/mpiuser/.ssh-source/id_rsa.pub"
      - source: "authorized_keys"
        target: "/home/mpiuser/.ssh-source/authorized_keys"
    depends_on:
      - grafana
  mpinode2:
    image: jmbatto/m2chps-mpi41-xmp:latest
    hostname: mpinode2
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - usrlocalvarmpi-foo:/usr/local/var/mpishare
    shm_size: '512m'
    networks:
      - mpinet
    secrets:                   
      - source: "id_rsa"
        target: "/home/mpiuser/.ssh-source/id_rsa"
      - source: "id_rsa_mpi_pub"
        target: "/home/mpiuser/.ssh-source/id_rsa.pub"
      - source: "authorized_keys"
        target: "/home/mpiuser/.ssh-source/authorized_keys"
    depends_on:
      - grafana
  mpinode3:
    image: jmbatto/m2chps-mpi41-xmp:latest
    hostname: mpinode3
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - usrlocalvarmpi-foo:/usr/local/var/mpishare
    shm_size: '512m'
    networks:
      - mpinet
    secrets:                   
      - source: "id_rsa"
        target: "/home/mpiuser/.ssh-source/id_rsa"
      - source: "id_rsa_mpi_pub"
        target: "/home/mpiuser/.ssh-source/id_rsa.pub"
      - source: "authorized_keys"
        target: "/home/mpiuser/.ssh-source/authorized_keys"
    depends_on:
      - grafana
  vscode:
    image: codercom/code-server:latest
    container_name: vscode
    hostname: vscode
    ports: 
      - "8081:8080" 
    deploy:
     resources:
      limits:
       memory: 512M
    restart: always
    volumes:
        - /var/run/docker.sock:/var/run/docker.sock
        - usrlocalvarmpi-foo:/usr/local/var/mpishare
    environment:
        - PASSWORD=XXXXXXXX
        - DOCKER_USER=votrelogin
        - CODER_ACCESS_URL="http://localhost:8081"
    user: "1001:1001"
    networks:
        - mpinet
    secrets:
      - source: "id_rsa"
        target: "/home/coder/.ssh-source/id_rsa"
      - source: "id_rsa_mpi_pub"
        target: "/home/coder/.ssh-source/id_rsa.pub"
      - source: "authorized_keys"
        target: "/home/coder/.ssh-source/authorized_keys"
      - source: "certif.sh"
        target: "/home/coder/.ssh-source/certif.sh"
      - source: "install_clang_format_go.sh"
        target: "/home/coder/.ssh-source/install_clang_format_go.sh"
  mysql:
    image: mariadb:10.10
    hostname: mysql
    container_name: mysql
    environment:
      MARIADB_ROOT_PASSWORD: password
      MARIADB_DATABASE: slurm_acct_db
      MARIADB_USER: slurm
      MARIADB_PASSWORD: password
    volumes:
      - var_lib_mysql:/var/lib/mysql
    ports:
      - "3306:3306"
    networks:
      - mpinet

  slurmdbd:
    image: jmbatto/m2chps-slurm-cluster:latest
    command: ["slurmdbd"]
    container_name: slurmdbd
    hostname: slurmdbd
    volumes:
      - etc_munge:/etc/munge
#      - etc_slurm:/etc/slurm
      - var_log_slurm:/var/log/slurm
    expose:
      - "6819"
    depends_on:
      - mysql
    shm_size: '512m'
    networks:
      - mpinet

  slurmctld:
    image: jmbatto/m2chps-slurm-cluster:latest
    command: ["slurmctld"]
    container_name: slurmctld
    hostname: slurmctld
    volumes:
      - etc_munge:/etc/munge
#      - etc_slurm:/etc/slurm
      - slurm_jobdir:/data
      - var_log_slurm:/var/log/slurm
      - usrlocalvarmpi-foo:/usr/local/var/mpishare
    expose:
      - "6817"
    depends_on:
      - "slurmdbd"
    shm_size: '512m'
    networks:
      - mpinet

  c1:
    image: jmbatto/m2chps-slurm-cluster:latest
    command: ["slurmd"]
    hostname: c1
    container_name: c1
    volumes:
      - etc_munge:/etc/munge
#      - etc_slurm:/etc/slurm
      - slurm_jobdir:/data
      - var_log_slurm:/var/log/slurm
      - usrlocalvarmpi-foo:/usr/local/var/mpishare
    expose:
      - "6818"
    depends_on:
      - "slurmctld"
    shm_size: '512m'
    networks:
      - mpinet
  c2:
    image: jmbatto/m2chps-slurm-cluster:latest
    command: ["slurmd"]
    hostname: c2
    container_name: c2
    volumes:
      - etc_munge:/etc/munge
#      - etc_slurm:/etc/slurm
      - slurm_jobdir:/data
      - var_log_slurm:/var/log/slurm
      - usrlocalvarmpi-foo:/usr/local/var/mpishare
    expose:
      - "6818"
    depends_on:
      - "slurmctld"
    shm_size: '512m'
    networks:
      - mpinet

secrets:
  id_rsa_mpi_pub:
    file: ssh/id_rsa.mpi.pub
  id_rsa:
    file: ssh/id_rsa.mpi
  authorized_keys:
    file: ssh/id_rsa.mpi.pub
  certif.sh:
    file: ssh/certif.sh
  install_clang_format_go.sh:
    file: ssh/install_clang_format_go.sh      
networks:
  mpinet:
    external: true
    name : yml_mpinet
# bridge by default
#    driver: overlay
volumes:
  etc_munge:
#  etc_slurm:
  slurm_jobdir:
  var_lib_mysql:
  var_log_slurm:
  usrlocalvarmpi-foo:
  usrlocalgrafana-foo:
  usrlocalinfluxdb-foo:
