# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---

blueprint_name: slurm-docker

vars:
  project_id:  <your project>
  deployment_name: slurm-docker
  region: us-central1
  zone: us-central1-c

deployment_groups:
- group: primary
  modules:
  # Source is an embedded module, denoted by "modules/*" without ./, ../, /
  # as a prefix. To refer to a local or community module, prefix with ./, ../ or /
  # Example - ./modules/network/vpc
  - source: modules/network/vpc
    kind: terraform
    id: network1

  - source: modules/file-system/filestore
    kind: terraform
    id: homefs
    use: [network1]
    settings:
      local_mount: /home

  # This debug_partition will work out of the box without requesting additional GCP quota.
  - source: community/modules/compute/SchedMD-slurm-on-gcp-partition
    kind: terraform
    id: debug_partition
    use:
    - network1
    - homefs
    - docker_install
    settings:
      partition_name: debug
      max_node_count: 4
      enable_placement: false
      exclusive: false
      machine_type: n2-standard-2

  - source: modules/scripts/startup-script
    kind: terraform
    id: docker_install
    settings:
      runners:
      - type: shell
        destination: "/tmp/docker.sh"
        content: |
          #!/bin/sh
          yum install -y yum-utils
          yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
          yum install -y docker-ce docker-ce-cli containerd.io
          systemctl start docker
          systemctl enable docker
          usermod -aG docker <oslogin_user_id>

  # This compute_partition is far more performant than debug_partition but may require requesting GCP quotas first.
  - source: community/modules/compute/SchedMD-slurm-on-gcp-partition
    kind: terraform
    id: compute_partition
    use:
    - network1
    - homefs
    - docker_install
    settings:
      partition_name: compute
      machine_type: c2-standard-4
      max_node_count: 20
    
  - source: community/modules/scheduler/SchedMD-slurm-on-gcp-controller
    kind: terraform
    id: slurm_controller
    use:
    - network1
    - homefs
    - debug_partition  # debug partition will be default as it is listed first
    - compute_partition
    - docker_install
    settings:
      login_node_count: 1
      suspend_time: 60

  - source: community/modules/scheduler/SchedMD-slurm-on-gcp-login-node
    kind: terraform
    id: slurm_login
    use:
    - network1
    - homefs
    - slurm_controller
