From 25264f56446144540f39cb40602d09a5d14ada69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stephan=20Mei=C3=9Fl?= <stephan.meissl@eox.at>
Date: Wed, 21 Oct 2020 11:59:50 +0200
Subject: [PATCH] adjust init-db.sh loading

---
 chart/README.md                        |  9 +++
 chart/files/init-db.sh                 | 79 +++++++++++++++++++++++++
 chart/templates/init-db-configmap.yaml |  5 +-
 chart/values-init-db.yaml              | 80 --------------------------
 4 files changed, 90 insertions(+), 83 deletions(-)
 create mode 100644 chart/files/init-db.sh
 delete mode 100644 chart/values-init-db.yaml

diff --git a/chart/README.md b/chart/README.md
index 9ef273a0..acc5e453 100644
--- a/chart/README.md
+++ b/chart/README.md
@@ -1 +1,10 @@
 Chart for the View Server (VS) bundling all services
+
+Useful commands:
+
+```bash
+helm dependency update
+
+helm template testing . --output-dir ../tmp/ -f values.yaml
+
+```
diff --git a/chart/files/init-db.sh b/chart/files/init-db.sh
new file mode 100644
index 00000000..5b05895c
--- /dev/null
+++ b/chart/files/init-db.sh
@@ -0,0 +1,79 @@
+# Check if collection exits in database and initialize database only if not
+if python3 manage.py id check "${COLLECTION}"; then
+    echo "Initialize database"
+
+    python3 manage.py coveragetype import /rgbnir_definition.json --traceback
+
+    if [ "${COLLECTION}" == "VHR_IMAGE_2018" ]; then
+        echo "Initializing collection '${COLLECTION}'."
+
+        # PL00
+        python3 manage.py producttype create "${COLLECTION}"_Product_PL00 --traceback \
+            --coverage-type "RGBNir"
+        python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 --traceback \
+            --red "red" \
+            --green "green" \
+            --blue "blue" \
+            --red-range 1000 15000 \
+            --green-range 1000 15000 \
+            --blue-range 1000 15000 \
+            --red-nodata 0 \
+            --green-nodata 0 \
+            --blue-nodata 0
+        python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 "TRUE_COLOR" --traceback \
+            --red "red" \
+            --green "green" \
+            --blue "blue" \
+            --red-range 1000 15000 \
+            --green-range 1000 15000 \
+            --blue-range 1000 15000 \
+            --red-nodata 0 \
+            --green-nodata 0 \
+            --blue-nodata 0
+        python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 "FALSE_COLOR" --traceback \
+            --red "nir" \
+            --green "red" \
+            --blue "green" \
+            --red-range 1000 15000 \
+            --green-range 1000 15000 \
+            --blue-range 1000 15000 \
+            --red-nodata 0 \
+            --green-nodata 0 \
+            --blue-nodata 0
+        python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 "NDVI" --traceback \
+            --grey "(nir-red)/(nir+red)" --grey-range -1 1
+
+
+        python3 manage.py collectiontype create "${COLLECTION}"_Collection --traceback \
+            --coverage-type "RGBNir" \
+            --product-type "${COLLECTION}"_Product_PL00
+
+        # Create collections for all products
+        python3 manage.py collection create "${COLLECTION}" --type "${COLLECTION}"_Collection --traceback
+
+        # Register mask type
+        python3 manage.py masktype create --validity "${COLLECTION}"_Product_PL00 validity
+
+    else
+        echo "Provided collection '${COLLECTION}' not valid."
+    fi
+
+    python3 manage.py storageauth create auth-cloud-ovh "${OS_AUTH_URL_SHORT}" \
+        --type keystone \
+        -p auth-version "${ST_AUTH_VERSION}" \
+        -p identity-api-version="${ST_AUTH_VERSION}" \
+        -p username "${OS_USERNAME}" \
+        -p password "${OS_PASSWORD}" \
+        -p tenant-name "${OS_TENANT_NAME}" \
+        -p tenant-id "${OS_TENANT_ID}" \
+        -p region-name "${OS_REGION_NAME}"
+
+    python3 manage.py storage create \
+        ${UPLOAD_CONTAINER} ${UPLOAD_CONTAINER} \
+        --type swift \
+        --storage-auth auth-cloud-ovh
+
+
+else
+    echo "Using existing database"
+fi
diff --git a/chart/templates/init-db-configmap.yaml b/chart/templates/init-db-configmap.yaml
index a0516d5b..6e130e1c 100644
--- a/chart/templates/init-db-configmap.yaml
+++ b/chart/templates/init-db-configmap.yaml
@@ -1,7 +1,6 @@
 apiVersion: v1
-data:
-  init-db.sh: |
-    {{- .Values.initDb | nindent 4 }}
 kind: ConfigMap
 metadata:
   name: {{ include "vs.fullname" . }}-init-db
+data:
+  {{ (.Files.Glob "files/init-db.sh").AsConfig | nindent 2}}
diff --git a/chart/values-init-db.yaml b/chart/values-init-db.yaml
deleted file mode 100644
index 23118ada..00000000
--- a/chart/values-init-db.yaml
+++ /dev/null
@@ -1,80 +0,0 @@
-initDb: |
-    # Check if collection exits in database and initialize database only if not
-    if python3 manage.py id check "${COLLECTION}"; then
-        echo "Initialize database"
-
-        python3 manage.py coveragetype import /rgbnir_definition.json --traceback
-
-        if [ "${COLLECTION}" == "VHR_IMAGE_2018" ]; then
-            echo "Initializing collection '${COLLECTION}'."
-
-            # PL00
-            python3 manage.py producttype create "${COLLECTION}"_Product_PL00 --traceback \
-                --coverage-type "RGBNir"
-            python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 --traceback \
-                --red "red" \
-                --green "green" \
-                --blue "blue" \
-                --red-range 1000 15000 \
-                --green-range 1000 15000 \
-                --blue-range 1000 15000 \
-                --red-nodata 0 \
-                --green-nodata 0 \
-                --blue-nodata 0
-            python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 "TRUE_COLOR" --traceback \
-                --red "red" \
-                --green "green" \
-                --blue "blue" \
-                --red-range 1000 15000 \
-                --green-range 1000 15000 \
-                --blue-range 1000 15000 \
-                --red-nodata 0 \
-                --green-nodata 0 \
-                --blue-nodata 0
-            python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 "FALSE_COLOR" --traceback \
-                --red "nir" \
-                --green "red" \
-                --blue "green" \
-                --red-range 1000 15000 \
-                --green-range 1000 15000 \
-                --blue-range 1000 15000 \
-                --red-nodata 0 \
-                --green-nodata 0 \
-                --blue-nodata 0
-            python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 "NDVI" --traceback \
-                --grey "(nir-red)/(nir+red)" --grey-range -1 1
-
-
-            python3 manage.py collectiontype create "${COLLECTION}"_Collection --traceback \
-                --coverage-type "RGBNir" \
-                --product-type "${COLLECTION}"_Product_PL00
-
-            # Create collections for all products
-            python3 manage.py collection create "${COLLECTION}" --type "${COLLECTION}"_Collection --traceback
-
-            # Register mask type
-            python3 manage.py masktype create --validity "${COLLECTION}"_Product_PL00 validity
-
-        else
-            echo "Provided collection '${COLLECTION}' not valid."
-        fi
-
-        python3 manage.py storageauth create auth-cloud-ovh "${OS_AUTH_URL_SHORT}" \
-            --type keystone \
-            -p auth-version "${ST_AUTH_VERSION}" \
-            -p identity-api-version="${ST_AUTH_VERSION}" \
-            -p username "${OS_USERNAME}" \
-            -p password "${OS_PASSWORD}" \
-            -p tenant-name "${OS_TENANT_NAME}" \
-            -p tenant-id "${OS_TENANT_ID}" \
-            -p region-name "${OS_REGION_NAME}"
-
-        python3 manage.py storage create \
-            ${UPLOAD_CONTAINER} ${UPLOAD_CONTAINER} \
-            --type swift \
-            --storage-auth auth-cloud-ovh
-
-
-    else
-        echo "Using existing database"
-    fi
-- 
GitLab