From dfddb236d866dd85247c4a5eb6c514b6293c8bb0 Mon Sep 17 00:00:00 2001
From: k204230 <bergemann@dkrz.de>
Date: Fri, 16 Sep 2022 10:19:42 +0200
Subject: [PATCH] Create Django sites on deployment, add more docs

---
 assets/web/setup_web.sh          |  3 ++
 docs/AfterDeployment.md          | 85 ++++++++++++++++++++++++++++++++
 docs/LegalNotes.md               | 10 ++--
 docs/TuiHowto.md                 | 14 +++---
 src/freva_deployment/__init__.py |  2 +-
 5 files changed, 103 insertions(+), 11 deletions(-)

diff --git a/assets/web/setup_web.sh b/assets/web/setup_web.sh
index 01a4f41..5969079 100644
--- a/assets/web/setup_web.sh
+++ b/assets/web/setup_web.sh
@@ -14,3 +14,6 @@ python manage.py createsuperuser \
     --noinput \
     --username freva-admin \
     --email $DJANGO_SUPERUSER_EMAIL || echo 0
+# python manage.py shell -c 'Site.objects.all().delete()'
+python manage.py shell -c \
+    'from django.contrib.sites.models import Site; Site.objects.create(id=1, domain="example.com", name="example.com").save()' || echo 0
diff --git a/docs/AfterDeployment.md b/docs/AfterDeployment.md
index 5178878..e295e7e 100644
--- a/docs/AfterDeployment.md
+++ b/docs/AfterDeployment.md
@@ -77,3 +77,88 @@ and terms of usage. Those statements can be added as flat-pages in the django
 *admin* panel. All flat-pages starting with the url **/legal** for example
 `/legal/privacy/` will be added as a link to the footer of home page. Examples
 of the content of such flat-pages can be found in the [Appendix III](LegalNotes.html).
+
+## Amending the already existing containers
+Sometimes it might by helpful to change existing containers, such as adding
+extra mount points. One way of doing so is
+[adjusting the playbook](Configure.html#advanced-adjusting-the-playbook) *before*
+deployment. If already existing containers should be amended a different
+strategy can be applied:
+
+- Get the container ID of the service that should be changed:
+```console
+docker ps -aqf "name=<project>-<service>"
+```
+- Commit this ID to a new name (project-service-old)
+```console
+docker commit <container_id> <new_container_name>
+```
+- Stop the service:
+
+```console
+systemclt stop <project>-<service>
+```
+or
+```console
+docker stop <project>-<service>
+```
+- The deployment wrapper creating the containers will log all commands that
+have been used to create containers. To get the container creation command that
+was used check the content of the following file:
+
+```console
+cat /root/.freva_container_commands/<project>-<service>.run
+```
+
+- Replace the container name in the shown command (`<project>-<service>`) by
+(`<new_container_name>`) and add the part that should be amended, like a new
+volume or environment variable. Also replace the `-t image` part by
+`<new_container_name>`. Then run this command.
+
+- Remove the old container:
+```console
+docker rm <project>-<service>
+```
+
+- Rename the new container name (`<new_container_name>`) to the old name:
+
+```console
+docker rename <new_container_name> <project>-<service>
+```
+
+- Restart the service: `systemctl restart <project>-<service>`
+
+Below you can find a real example:
+
+```console
+$: docker ps -aqf "name=clex-web"
+e907fb462deb
+$: docker commit e907fb462deb clex-web-old
+sha256:b5c71c91e30e6424099218af6b83dbd3b7b8e05eb3bdf1404e4716dcc4e3e86d
+$: systemctl stop clex-web
+$: cat /root/.freva_container_commands/clex-web.run
+container clex-web created at 2022-09-16 09:19:28.868972 using command:
+
+/bin/docker run -d -p 8000:8000
+-v /work/freva:/work/freva:ro -v /work/freva/share/slurm:/work/freva/share/slurm:ro
+-v /opt/freva/clex/web_service/static:/opt/freva_web/static:z
+-v /work/freva/share/work:/work/freva/share/work:ro
+-e EVALUATION_SYSTEM_CONFIG_FILE=/work/freva/evaluation_system.conf
+--name freva-dev-web -t registry.gitlab.dkrz.de/freva/freva_web/freva_web:main
+
+$: /bin/docker run -d -p 8000:8000 \
+-v /work/freva:/work/freva:ro -v /work/freva/share/slurm:/work/freva/share/slurm:ro \
+-v /opt/freva/clex/web_service/static:/opt/freva_web/static:z \
+-v /opt/freva/clex/web_service/static:/opt/freva_web/static:z \
+-v /work/freva/share/work:/work/freva/share/work:ro \
+-v /work/new_mount:/work/new_mount:ro \
+-e EVALUATION_SYSTEM_CONFIG_FILE=/work/freva/evaluation_system.conf \
+--name clex-web-old clex-web-old
+991e704b066d3a608504091d243f56cbac67100f54a7a5aeca0c352bbc4f4696
+
+$: docker rm clex-web
+clex-web
+
+$: docker rename clex-web-old clex-web
+$: systemctl restart clex-web
+```
diff --git a/docs/LegalNotes.md b/docs/LegalNotes.md
index 7c9cf57..f4cdee5 100644
--- a/docs/LegalNotes.md
+++ b/docs/LegalNotes.md
@@ -2,10 +2,12 @@
 
 This appendix gives examples of flat pages containing privacy and terms of
 conditions. Such statements should be added as flat-pages in the [django admin
-panel](AfterDeployment.html#the-web-ui-admin-panel). Any flat-page url starting with `/legal/` will
-be added as a link to the footer. For example `/legal/privacy/` which could
-be a flat-page for a privacy statement. Below you'll find examples of a
-privacy statement and terms of use.
+panel](AfterDeployment.html#the-web-ui-admin-panel).
+[Flat-pages](https://docs.djangoproject.com/en/4.1/ref/contrib/flatpages/)
+additional notes that are displayed on the web site. Any flat-page url
+starting with `/legal/` will be added as a link to the footer.
+For example `/legal/privacy/` which could be a flat-page for a privacy
+statement. Below you'll find examples of a privacy statement and terms of use.
 
 ### Privacy statement
 
diff --git a/docs/TuiHowto.md b/docs/TuiHowto.md
index e2d8210..18ee18b 100644
--- a/docs/TuiHowto.md
+++ b/docs/TuiHowto.md
@@ -1,4 +1,4 @@
-# Appendix I: Usage of the text user interface
+# Usage of the text user interface
 We have create a simple text user interface (tui) that helps you setting up a
 Freva instance at your institution. At this stage the documentation assumes that
 you have installed the necessary server infrastructure and pre-requisites.
@@ -133,7 +133,7 @@ essential setup steps:
     [See also django ldap tls config](https://django-auth-ldap.readthedocs.io/en/latest/authentication.html#notes)
 16. Set the user group name that is allowed to logon to the web ui.
 17. Set the ldap user base filters. See also the
-    [djanog ldap authentication for user](https://django-auth-ldap.readthedocs.io/en/latest/users.html)
+    [django ldap authentication for user](https://django-auth-ldap.readthedocs.io/en/latest/users.html)
 18. Set the ldap group base filters. See also the
     [django ldap authentication for groups](https://django-auth-ldap.readthedocs.io/en/latest/groups.html#finding-groups)
 19. Set the distinguished name of the ldap user. This setting is used to make
@@ -177,10 +177,12 @@ The httpd configuration for the reverse proxy will be saved
 `/opt/freva/<project_name>/web_service/`.
 
 During the deployment process of the web ui you will be ask your login
-credentials for the smtp email server. The credentials are needed to connect
-to the email server and send emails. Your credentials won't be saved anywhere
-on disk but securely stored in the vault service that gets deployed when setting
-up the database.
+credentials for the smtp email server. An email server is necessary because
+the web backend has a email sending functionality. This functionality makes
+it easy for users to communicate and share results with other users.
+Login credentials are needed to connect to the email server and send emails.
+Your credentials won't be saved anywhere on disk but securely stored in the
+vault service that gets deployed when setting up the database.
 
 
 
diff --git a/src/freva_deployment/__init__.py b/src/freva_deployment/__init__.py
index a34dca6..3367a95 100644
--- a/src/freva_deployment/__init__.py
+++ b/src/freva_deployment/__init__.py
@@ -1,4 +1,4 @@
-__version__ = "2208.0.7"
+__version__ = "2208.0.8"
 AVAILABLE_PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10"]
 AVAILABLE_CONDA_ARCHS = [
     "Linux-x86_64",
-- 
GitLab