Newer
Older
Athanasios Karmas
committed
# start an OpenShift Job that will build the Spack environment
.deploy-build-environment:
stage: deploy
before_script:
- oc login "$OPENSHIFT_SERVER" --token="$OPENSHIFT_TOKEN"
Athanasios Karmas
committed
- tar czf ${SPACK_ENV_TAR_FILE} packages/ repo.yaml spack.yaml create_JupyterLab_kernel.sh
Athanasios Karmas
committed
- mkdir copy_folder
Athanasios Karmas
committed
- mv ${SPACK_ENV_TAR_FILE} copy_folder
script:
# create job description file
- chmod a+x create_job.sh
- ./create_job.sh $INSTALLATION_ROOT $SPACKIFIED_ENV $OP $SPACK_ENV_TAR_FILE $CI_PIPELINE_ID
Athanasios Karmas
committed
- oc project $OC_PROJECT
Athanasios Karmas
committed
## 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${CI_PIPELINE_ID} -o=jsonpath='{.status}' -w && oc get job/simplejob${CI_PIPELINE_ID} -o=jsonpath='{.status.conditions[*].type}' | grep -i -E 'failed|complete' || echo 'Failed'
Athanasios Karmas
committed
# wait for job's pod to become available so as to copy from the gitlab runner to the OpenShift pod
# the necessary files that define the environment that spack needs to build
- while true; do x=$(oc get pods |grep simplejob${CI_PIPELINE_ID}|awk '{ print $3}');if [ $x == "Running" ]; then break; fi; sleep 1; done
- pod=$(oc get pods |grep simplejob${CI_PIPELINE_ID}|awk '{ print $1}')
- oc rsync copy_folder $pod:/opt/app-root/src
Athanasios Karmas
committed
# when build job finishes get the logs
- while true; do sleep 10; x=$(oc get pods |grep $pod|awk '{ print $3}');if [ $x != "Running" ]; then break; fi; done
Athanasios Karmas
committed
- oc logs jobs/simplejob${CI_PIPELINE_ID} | tee log.txt
# if spack install has failed, fail the pipeline
- if [ $(cat log.txt |grep "Error:"|wc -l) -gt 0 ]; then exit 1;fi;
Athanasios Karmas
committed
# delete the job from OpenShift as we have the logs here
Athanasios Karmas
committed
- oc delete job simplejob${CI_PIPELINE_ID} || true
Athanasios Karmas
committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# deploy on the dev environment
# runs on protected branches only as the token variable is protected
deploy-dev-environment:
extends: .deploy-build-environment
variables:
OPENSHIFT_SERVER: $OPENSHIFT_DEV_SERVER
OPENSHIFT_TOKEN: $OPENSHIFT_DEV_TOKEN
INSTALLATION_ROOT: $INSTALLATION_ROOT_DEV
SPACKIFIED_ENV: $SPACKIFIED_ENV_DEV
OP: $OPERATION_DEV
#SPACK_ENV_TAR_FILE: ebrains-spack-builds${CI_PIPELINE_ID}.tar.gz
SPACK_ENV_TAR_FILE: ebrains-spack-builds.tar.gz
OC_PROJECT: jupyterhub-int
resource_group: shared-NFS-mount-dev
only:
- master
# deploy on the production environment
# runs on protected branches only as the token variable is protected
deploy-prod-environment:
extends: .deploy-build-environment
variables:
OPENSHIFT_SERVER: $OPENSHIFT_PROD_SERVER
OPENSHIFT_TOKEN: $OPENSHIFT_PROD_TOKEN
INSTALLATION_ROOT: $INSTALLATION_ROOT_PROD
SPACKIFIED_ENV: $SPACKIFIED_ENV_PROD
OP: $OPERATION_PROD
#SPACK_ENV_TAR_FILE: ebrains-spack-builds${CI_PIPELINE_ID}.tar.gz
SPACK_ENV_TAR_FILE: ebrains-spack-builds.tar.gz
OC_PROJECT: jupyterhub
resource_group: shared-NFS-mount-prod
rules:
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH && $CI_COMMIT_BRANCH =~ /release/'
when: manual
allow_failure: false