# from Dennis: select (default) image and (default) runner
default:
  image:
    name: docker-registry.ebrains.eu/clb-jupyter-image/base
    entrypoint: [""]
  tags:
    - docker-runner

# Generate the "spack pipeline" and build it
stages:
  - generate
  - build

# UHEI spack version and branch
variables:
  SPACK_REPO:  https://github.com/electronicvisions/spack
  # ebrains_testing contains bug fix for failing uid => username lookup in container
  # (was "visionary")
  SPACK_REF: ebrains_testing

generate-pipeline:
  stage: generate
  before_script:
    # clone spack and set checkout to correct ref
    - pip3 install boto3
    - git clone ${SPACK_REPO}
    - pushd spack && git checkout ${SPACK_REF} && git log -n 1 && popd
    - . "./spack/share/spack/setup-env.sh"
  script:
    # add system compiler
    - spack compiler find
    # print some infos about the environment
    - spack compilers
    - spack arch
    # ... system compiler is "gcc@4.8.5"
    # activate env (spack.yaml) and generate pipeline.yml for the build step
    - spack -d env activate --without-view .
    - spack -d ci generate --optimize
      --output-file "${CI_PROJECT_DIR}/jobs_scratch_dir/pipeline.yml"
  artifacts:
    paths:
      - "${CI_PROJECT_DIR}/jobs_scratch_dir/pipeline.yml"

build-jobs:
  stage: build
  trigger:
    include:
      - artifact: "jobs_scratch_dir/pipeline.yml"
        job: generate-pipeline
    strategy: depend
