#!/bin/bash

#
# https://docs.gitlab.com/13.12/ee/api/job_artifacts.html#get-job-artifacts
# https://stackoverflow.com/questions/53837426/gitlab-how-can-i-programatically-download-the-artifacts-issued-at-end-of-ci-pip
# url structure : GET /projects/:id/jobs/:job_id/artifacts
#

BUILD_ENV=$1
OP=$2
SWIFT_FILE=$3
OC_JOB_ID=$4

cat <<EOT >> simplejob.yml
apiVersion: batch/v1
kind: Job
metadata:
  name: simplejob${OC_JOB_ID}
spec:
  parallelism: 1    
  completions: 1    
  template:         
    metadata:
      name: testjob
    spec:
      #securityContext:
      #  supplementalGroups: [1000410000]
      #  seLinuxOptions:
      #    level: s0:c25,c10
      containers:
      - name: simplejob
        image: docker-registry.ebrains.eu/tc/ebrains-spack-build-env:latest
        securityContext:
          runAsUser: 1000410000
        volumeMounts:
          - name: sharedbin
            mountPath: /srv
        command: ["/usr/local/bin/deploy-build-env.sh", "$BUILD_ENV", "$OP", "$SWIFT_FILE"]
      volumes:
        - name: sharedbin
          persistentVolumeClaim:
            claimName: shared-binaries
      restartPolicy: Never    
EOT
