From e0fe0a51ce31abab3a2579f8cf5cd9ca6b4599c0 Mon Sep 17 00:00:00 2001
From: Sven Marcus <s.marcus@outlook.de>
Date: Wed, 18 Nov 2020 14:46:13 +0100
Subject: [PATCH] Add new playbook to update Jupyter DockerSpawner image

---
 .gitlab-ci.yml                                |  7 ++-
 ansible/hosts.cfg                             |  4 +-
 ansible/playbook_jupyter_update.yml           | 51 +++++++++++++++++++
 .../{playbook.yml => playbook_vf_deploy.yml}  |  0
 4 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 ansible/playbook_jupyter_update.yml
 rename ansible/{playbook.yml => playbook_vf_deploy.yml} (100%)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 881bcbead..c3deb354b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -139,6 +139,11 @@ msvc_16:
 
 build_singularity_image:
   stage: build
+
+  tags:
+    - priviliged
+    - linux
+
   rules:
     - if: $CI_COMMIT_TAG
 
@@ -418,7 +423,7 @@ vf_to_phoenix:
     - pip3 install ansible
 
   script:
-    - ansible-playbook -i ansible/hosts.cfg -u $REMOTE_USER ansible/playbook.yml
+    - ansible-playbook -i ansible/hosts.cfg -u $REMOTE_USER ansible/playbook_vf_deploy.yml
 
   parallel:
     matrix:
diff --git a/ansible/hosts.cfg b/ansible/hosts.cfg
index 259f123d2..160b8a196 100644
--- a/ansible/hosts.cfg
+++ b/ansible/hosts.cfg
@@ -5,4 +5,6 @@ phoenix.hlr.rz.tu-bs.de ansible_ssh_private_key_file=./private_key
 [gitlab_ci_deploy_cppcheck]
 elladan.irmb.bau.tu-bs.de
 [gitlab_ci_deploy_gcov]
-elladan.irmb.bau.tu-bs.de
\ No newline at end of file
+elladan.irmb.bau.tu-bs.de
+[gitlab_ci_deploy_wheel]
+finrod.irmb.bau.tu-bs.de
\ No newline at end of file
diff --git a/ansible/playbook_jupyter_update.yml b/ansible/playbook_jupyter_update.yml
new file mode 100644
index 000000000..4e5f6a9c5
--- /dev/null
+++ b/ansible/playbook_jupyter_update.yml
@@ -0,0 +1,51 @@
+- hosts: local
+  vars:
+    host_home: "/home/{{ lookup('env', 'jupyter_host') }}"
+
+  tasks:
+
+    - name: Find container IDs with image name
+      become: yes
+      shell: docker ps -a --format {% raw %}'{{.ID}} {{.Image}}'{% endraw %} | grep pyfluids-jupyter | awk '{ print $1 }'
+      register: container_ids
+
+    - name: Stop and remove docker spawner containers
+      become: yes
+      community.general.docker_container:
+        name: "{{ item }}"
+        state: absent
+      loop: "{{ container_ids.stdout_lines }}"
+
+    - name: Remove old docker spawner image
+      become: yes
+      community.general.docker_image:
+        name: pyfluids-jupyter
+        state: absent
+
+    - name: Find pyfluids wheel
+      find:
+        path: "{{ host_home }}/jupyterhub/DockerSpawnerImage/wheels/"
+        patterns: pyfluids*.whl
+      register: find_pyfluids
+
+    - name: Remove old pyfluids wheel
+      file:
+        path: "{{ item }}"
+        state: absent
+      loop: "{{ find_pyfluids.files }}"
+
+    - name: Copy new wheels to docker spawner image
+      synchronize:
+        src: ../dist/
+        dest: "{{ host_home }}/jupyterhub/DockerSpawnerImage/wheels/"
+        rsync_opts:
+          - "--include='*.whl'"
+
+    - name: Build docker spawner image again
+      become: yes
+      community.general.docker_image:
+        name: pyfluids-jupyter
+        source: build
+        build:
+          dockerfile: "{{ host_home }}/jupyterhub/DockerSpawnerImage/Dockerfile"
+          path: "{{ host_home }}/jupyterhub/DockerSpawnerImage/"
diff --git a/ansible/playbook.yml b/ansible/playbook_vf_deploy.yml
similarity index 100%
rename from ansible/playbook.yml
rename to ansible/playbook_vf_deploy.yml
-- 
GitLab