stages:
  - upload
  - deploy

variables:
  OPENSHIFT_SERVER: https://okd-dev.hbp.eu
  #BUILD_ENV: int-build
  #BUILD_ENV: ebrains/ for DT
  BUILD_ENV: test-build
  OP: update

copy-files-to-swift:
  stage: upload
  script:
    - curl -H X-Auth-Token: ${OS_TOKEN}' -X DELETE ${OBJSTORE} ebrains-spack-builds.tar.gz
    - tar czf ebrains-spack-builds.tar.gz packages/ repo.yml spack.yaml
    - curl -H 'X-Auth-Token: ${OS_TOKEN}' -i ${OBJSTORE} -X PUT -T ebrains-spack-builds.tar.gz
  tags:
    - shell-runner

deploy-build-environment:
  stage: deploy
  before_script:
    - oc login "$OPENSHIFT_SERVER" --token="$OPENSHIFT_TOKEN"
  script:
    # create job description file
    - chmod a+x create_job.sh
    - ./create_job.sh $BUILD_ENV $OP
    - cat simplejob.yml
    # select the project in openshift
    - oc project jupyterhub-int
    # delete the job (if exist)
    - oc delete job simplejob || true
    # start the deploy job
    - oc create -f simplejob.yml
    # wait for job to finish https://stackoverflow.com/questions/5073453wait-for-kubernetes-job-to-complete-on-either-failure-success-using-command-line
    - oc get job/simplejob -o=jsonpath='{.status}' -w && oc get job/simplejob -o=jsonpath='{.status.conditions[*].type}' | grep -i -E 'failed|complete' || echo 'Failed' 
    - oc logs jobs/simplejob
  tags:
    - shell-runner



