From 73bbe8a4016e64a9ab06a5211100b204dc0d01ad Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Tue, 14 Sep 2021 15:08:21 +0200
Subject: [PATCH] [ci] Added Jupyter notebook testing.

---
 .gitlab-ci.yml                |  1 +
 ThirdParty/container-maker    |  2 +-
 scripts/ci/jobs/container.yml |  8 -------
 scripts/ci/jobs/jupyter.yml   | 41 +++++++++++++++++++++++++++++++++++
 4 files changed, 43 insertions(+), 9 deletions(-)
 create mode 100644 scripts/ci/jobs/jupyter.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d94fa3f4e88..3a9d6dab86d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -36,6 +36,7 @@ include:
   - local: '/scripts/ci/jobs/build-docs.yml'
   - local: '/scripts/ci/jobs/build-win.yml'
   - local: '/scripts/ci/jobs/build-mac.yml'
+  - local: '/scripts/ci/jobs/jupyter.yml'
   # - template: 'Code-Quality.gitlab-ci.yml' # see !3053
   - local: '/scripts/ci/jobs/code-quality.yml'
   - local: '/scripts/ci/jobs/code-coverage.yml'
diff --git a/ThirdParty/container-maker b/ThirdParty/container-maker
index 15cc228418f..b32a22e17d2 160000
--- a/ThirdParty/container-maker
+++ b/ThirdParty/container-maker
@@ -1 +1 @@
-Subproject commit 15cc228418fc1cf910adad60d154d4129459bc46
+Subproject commit b32a22e17d2a9af486938e308d8aca1c7bce51ed
diff --git a/scripts/ci/jobs/container.yml b/scripts/ci/jobs/container.yml
index e71cc974e36..37fa423bc59 100644
--- a/scripts/ci/jobs/container.yml
+++ b/scripts/ci/jobs/container.yml
@@ -34,14 +34,6 @@ container:
       --cvode --ccache
       --cmake_args ' -DOGS_CPU_ARCHITECTURE=sandybridge -DOGS_BUILD_TESTING=OFF'
       --base_image 'centos:8' --ompi 4.0.5 --mpi_benchmarks
-    # Jupyter container
-    - >
-      poetry run ogscm compiler.py ogs.py ogs_jupyter.py -B -C -R --ogs ../..
-      --build_args ' --progress=plain'
-      --cvode --ccache --mfront
-      --cmake_args ' -DOGS_CPU_ARCHITECTURE=sandybridge -DOGS_BUILD_TESTING=OFF'
-      --runtime_base_image 'jupyter/base-notebook'
-      $DOCKER_TAG_JUPYTER
     # test ogs can run in container
     - |
       for sif in _out/images/*.sif; do
diff --git a/scripts/ci/jobs/jupyter.yml b/scripts/ci/jobs/jupyter.yml
new file mode 100644
index 00000000000..552f2f67aea
--- /dev/null
+++ b/scripts/ci/jobs/jupyter.yml
@@ -0,0 +1,41 @@
+# Built for Sandy Bridge (envinf1) and newer
+build jupyter:
+  stage: build
+  tags: [envinf2-shell]
+  needs: [meta]
+  extends:
+    - .container-maker-setup
+  script:
+    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
+    - >
+      if [[ "$CI_COMMIT_BRANCH" == "master" ]] ; then
+        export DOCKER_TAG_JUPYTER="$CI_REGISTRY/ogs/$CI_PROJECT_NAME/ogs-serial-jupyter:latest"
+        export ON_MASTER_ARGS="--upload -C"
+      else
+        export DOCKER_TAG_JUPYTER="ci-$CI_PROJECT_NAME-$CI_COMMIT_BRANCH-jupyter"
+      fi
+    # Jupyter container
+    - >
+      poetry run ogscm compiler.py ogs.py ogs_jupyter.py -B -R --ogs ../..
+      --build_args ' --progress=plain'
+      --cvode --ccache --mfront
+      --cmake_args ' -DOGS_CPU_ARCHITECTURE=sandybridge -DOGS_BUILD_TESTING=OFF'
+      --runtime_base_image 'jupyter/base-notebook'
+      --tag $DOCKER_TAG_JUPYTER
+      $ON_MASTER_ARGS
+    - cd $CI_PROJECT_DIR
+    # execute notebooks in container
+    - >
+      docker run --rm -v $PWD:/home/jovyan/work --user `id -u $USER` --group-add users
+      --workdir /home/jovyan/work $DOCKER_TAG_JUPYTER
+      bash -c "find Tests/Notebooks -type f -iname '*.ipynb' -not -path \"*.ipynb_checkpoints*\" | xargs -n1 jupyter nbconvert --execute --inplace"
+    - >
+      docker run --rm -v $PWD:/home/jovyan/work --user `id -u $USER` --group-add users
+      --workdir /home/jovyan/work $DOCKER_TAG_JUPYTER
+      bash -c "find Tests/Notebooks -type f -iname '*.ipynb' -not -path \"*.ipynb_checkpoints*\" | xargs -n1 nb2hugo --site-dir web --section docs/benchmarks/notebooks --template Tests/Notebooks/nbconvert_templates/collapsed.md.j2"
+  artifacts:
+    name: container
+    paths:
+      - ThirdParty/container-maker/_out/images/*.sif
+      - web/content/docs/benchmarks/notebooks
+      - web/static/docs/benchmarks/notebooks
-- 
GitLab