#!/bin/bash

INSTALLATION_ROOT=$1
SPACKIFIED_ENV=$2
OP=$3
SPACK_ENV_TAR_FILE=$4
OC_JOB_ID=$5
BUILD_ENV_DOCKER_IMAGE=$6
LAB_KERNEL_PATH=$7
OKD_CLUSTER_UID=$8

cat <<EOT >> simplejob.yml
apiVersion: batch/v1
kind: Job
metadata:
  name: simplejob${OC_JOB_ID}
spec:
  parallelism: 1    
  completions: 1
  backoffLimit: 0    
  template:         
    metadata:
      name: testjob
    spec:
      #securityContext:
      #  supplementalGroups: [1000410000]
      #  seLinuxOptions:
      #    level: s0:c25,c10
      containers:
      - name: simplejob
        image: ${BUILD_ENV_DOCKER_IMAGE}
        imagePullPolicy: Always
        securityContext:
          runAsUser: ${OKD_CLUSTER_UID}
        volumeMounts:
          - name: sharedbin
            mountPath: /srv
        command: ["/usr/local/bin/deploy-build-env.sh", "$INSTALLATION_ROOT", "$SPACKIFIED_ENV", "$OP", "$SPACK_ENV_TAR_FILE", "$LAB_KERNEL_PATH"]
      volumes:
        - name: sharedbin
          persistentVolumeClaim:
            claimName: shared-binaries
      restartPolicy: Never
      #nodeSelector:
      #  kubernetes.io/hostname: okd-worker-3.dev.hbp.eu     
EOT
