From 1bb3f4b2ad459606a04f45f98598855d7926ecc2 Mon Sep 17 00:00:00 2001
From: Marco Malavolti <marco.malavolti@garr.it>
Date: Sat, 5 Aug 2023 13:54:34 +0200
Subject: [PATCH] Added 'bind mounts' used by ECCS

---
 Dockerfile               |  4 ----
 README-Docker.rst        | 27 ++++++++++++++++++++++++---
 docker-compose-2.1.0.yml | 13 +++++++++++++
 docker-compose.yml       | 13 +++++++++++++
 eccs_cron                |  4 ++--
 pyff_cron                |  2 +-
 setup-eccs-dev.sh        |  8 ++++++++
 7 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index afb62b2..83402f3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -43,11 +43,7 @@ RUN wget "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/${CHROMEDR
 COPY --chown=eccs:eccs pyff-config/ pyff-config/
 
 COPY --chown=eccs:eccs api.py clean7daysOldFiles.sh cleanAndRunEccs.sh eccs.ini eccs.py eccs_properties.py eccs-wsgi.py get-sps-metadata.sh retryFailedChecks.py runEccs.py utils.py .
-COPY --chown=eccs:eccs  html/ html/
 COPY --chown=eccs:eccs  input/ input/
-COPY --chown=eccs:eccs  logs/ logs/
-COPY --chown=eccs:eccs  output/ output/
-COPY --chown=eccs:eccs  selenium-logs/ selenium-logs/
 COPY --chown=eccs:eccs  web/ web/
 
 USER root
diff --git a/README-Docker.rst b/README-Docker.rst
index 7286f7f..efb6e33 100644
--- a/README-Docker.rst
+++ b/README-Docker.rst
@@ -73,12 +73,33 @@ We'll respect `Semantic Versioning`_.
 Use the ECCS Docker container
 -----------------------------
 
-``docker compose -f docker-compose-<ECCS_VERSION>.yml``
+* Create the `eccs` directory with the required directories by bind mounts with:
 
-The ``ECCS_VERSION`` avaliable are:
+  * ``mkdir -p eccs/output eccs/html eccs/logs eccs/selenium-logs``
 
-   * ``2.1.0``
+* Instance ECCS with:
 
+  * ``cd eccs/``
+
+  * ``wget https://gitlab.software.geant.org/edugain/eccs/-/raw/eccs-docker/docker-compose-<ECCS_VERSION>.yml``
+
+  * ``docker compose -f docker-compose-<ECCS_VERSION>.yml up -d``
+
+    * The ``ECCS_VERSION`` avaliable are:
+
+      * ``2.1.0``
+
+* (optional) Delete last results with:
+
+  * ``docker exec -it -w /home/eccs/ eccs rm -rf html/$(date +%Y-%m-%d) output/eccs_$(date +%Y-%m-%d).log logs/*_$(date +%Y-%m-%d).log``
+
+* Run ECCS script:
+
+  * ``docker exec -it -w /home/eccs eccs ./cleanAndRunEccs.sh > logs/eccs-cron.log 2>&1``
+
+* (if needed) Stops containers and removes containers, networks, volumes, and images created by ``up`` compose action:
+
+  * ``docker compose -f docker-compose-<ECCS_VERSION>.yml down``
 
 Authors
 -------
diff --git a/docker-compose-2.1.0.yml b/docker-compose-2.1.0.yml
index 3d386be..4e4e630 100644
--- a/docker-compose-2.1.0.yml
+++ b/docker-compose-2.1.0.yml
@@ -7,3 +7,16 @@ services:
     ports:
       - 80:80
       - 443:443
+    volumes:
+      - type: bind
+        source: ./output
+        target: /home/eccs/output
+      - type: bind
+        source: ./html
+        target: /home/eccs/html
+      - type: bind
+        source: ./logs
+        target: /home/eccs/logs
+      - type: bind
+        source: ./selenium-logs
+        target: /home/eccs/selenium-logs
diff --git a/docker-compose.yml b/docker-compose.yml
index 37e1192..b461c17 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -12,3 +12,16 @@ services:
     ports:
       - 80:80
       - 443:443
+    volumes:
+      - type: bind
+        source: ./output
+        target: /home/eccs/output
+      - type: bind
+        source: ./html
+        target: /home/eccs/html
+      - type: bind
+        source: ./logs
+        target: /home/eccs/logs
+      - type: bind
+        source: ./selenium-logs
+        target: /home/eccs/selenium-logs
diff --git a/eccs_cron b/eccs_cron
index 2753b7f..8680e00 100644
--- a/eccs_cron
+++ b/eccs_cron
@@ -1,3 +1,3 @@
 0 3 * * * /usr/bin/touch /home/eccs/eccs.ini
-0 4 * * * /bin/bash /home/eccs/cleanAndRunEccs.sh > /dev/stdout
-0 10 * * * /bin/bash /home/eccs/clean7daysOldFiles.sh > /dev/stdout
+0 4 * * * /bin/bash /home/eccs/cleanAndRunEccs.sh > /home/eccs/logs/eccs-cron.log 2>&1
+0 10 * * * /bin/bash /home/eccs/clean7daysOldFiles.sh > /home/eccs/logs/clean7daysOldFiles.log 2>&1
diff --git a/pyff_cron b/pyff_cron
index a1c4ee5..efd3bb3 100644
--- a/pyff_cron
+++ b/pyff_cron
@@ -1 +1 @@
-0 3 * * * pyff --logfile=/dev/stdout --loglevel=DEBUG /home/eccs/pyff-config/sps-metadata.xml
+0 3 * * * pyff --logfile=/dev/stdout --loglevel=DEBUG /home/eccs/pyff-config/sps-metadata.xml > /home/eccs/logs/pyff-sps-md.log
diff --git a/setup-eccs-dev.sh b/setup-eccs-dev.sh
index 900bb78..6c3c1c9 100755
--- a/setup-eccs-dev.sh
+++ b/setup-eccs-dev.sh
@@ -47,3 +47,11 @@ echo ""
 echo "Useful command to access the 'eccs' terminal:"
 echo ""
 echo "docker exec -it -u root eccs bash"
+echo ""
+echo "Run ECCS manually for today:"
+echo ""
+echo "docker exec -it -w /home/eccs eccs ./cleanAndRunEccs.sh > logs/eccs-cron.log 2>&1"
+echo ""
+echo "Delete all results of today"
+echo ""
+echo "docker exec -it -w /home/eccs/ eccs rm -rf html/$(date +%Y-%m-%d) output/eccs_$(date +%Y-%m-%d).log logs/*_$(date +%Y-%m-%d).log"
-- 
GitLab