From c6a19e9564d13c7cb81c46b24539b55cec74b4ee Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Wed, 14 Aug 2024 17:15:22 +0200
Subject: [PATCH] maint: added expiry to responses

---
 .github/workflows/deploy-helm.yml | 29 +++++++++++++++++++++++++----
 .helm/siibra-explorer/values.yaml |  3 +--
 Dockerfile                        |  6 +++---
 backend/app/version_header.py     |  3 +++
 docs/releases/v2.14.9.md          |  5 +++++
 package.json                      |  2 +-
 6 files changed, 38 insertions(+), 10 deletions(-)
 create mode 100644 docs/releases/v2.14.9.md

diff --git a/.github/workflows/deploy-helm.yml b/.github/workflows/deploy-helm.yml
index 59796a18d..0e98465df 100644
--- a/.github/workflows/deploy-helm.yml
+++ b/.github/workflows/deploy-helm.yml
@@ -30,12 +30,19 @@ jobs:
         kubecfg_path=${{ runner.temp }}/.kube_config
         echo "${{ secrets.KUBECONFIG }}" > $kubecfg_path
 
-        helm --kubeconfig=$kubecfg_path \
+        helm ls | awk '{print $1}' | grep -q ${{ inputs.DEPLOYMENT_NAME }} \
+        && helm --kubeconfig=$kubecfg_path \
           upgrade \
           --history-max 3 \
           --reuse-values \
           --set image.tag=${{ inputs.IMAGE_TAG }} \
           --set podLabels.image-digest=${{ inputs.IMAGE_DIGEST }} \
+          ${{ inputs.DEPLOYMENT_NAME }} .helm/siibra-explorer/ \
+        || helm --kubeconfig=$kubecfg_path \
+          install\
+          --set image.tag=${{ inputs.IMAGE_TAG }} \
+          --set podLabels.image-digest=${{ inputs.IMAGE_DIGEST }} \
+          --set envObj.HOST_PATHNAME=/viewer \
           ${{ inputs.DEPLOYMENT_NAME }} .helm/siibra-explorer/
 
         rm $kubecfg_path
@@ -50,14 +57,21 @@ jobs:
         kubecfg_path=${{ runner.temp }}/.kube_config
         echo "${{ secrets.KUBECONFIG }}" > $kubecfg_path
 
-        helm --kubeconfig=$kubecfg_path \
+        helm ls | awk '{print $1}' | grep -q ${{ inputs.DEPLOYMENT_NAME }} \
+        && helm --kubeconfig=$kubecfg_path \
           upgrade \
           --history-max 3 \
           --reuse-values \
           --set image.tag=${{ inputs.IMAGE_TAG }} \
           --set podLabels.image-digest=${{ inputs.IMAGE_DIGEST }} \
+          ${{ inputs.DEPLOYMENT_NAME }} .helm/siibra-explorer/ \
+        || helm --kubeconfig=$kubecfg_path \
+          install\
+          --set image.tag=${{ inputs.IMAGE_TAG }} \
+          --set podLabels.image-digest=${{ inputs.IMAGE_DIGEST }} \
+          --set envObj.HOST_PATHNAME=/viewer-staging \
           ${{ inputs.DEPLOYMENT_NAME }} .helm/siibra-explorer/
-          
+
         rm $kubecfg_path
 
   trigger-deploy-expmt:
@@ -70,12 +84,19 @@ jobs:
         kubecfg_path=${{ runner.temp }}/.kube_config
         echo "${{ secrets.KUBECONFIG }}" > $kubecfg_path
 
-        helm --kubeconfig=$kubecfg_path \
+        helm ls | awk '{print $1}' | grep -q ${{ inputs.DEPLOYMENT_NAME }} \
+        && helm --kubeconfig=$kubecfg_path \
           upgrade \
           --history-max 3 \
           --reuse-values \
           --set image.tag=${{ inputs.IMAGE_TAG }} \
           --set podLabels.image-digest=${{ inputs.IMAGE_DIGEST }} \
+          ${{ inputs.DEPLOYMENT_NAME }} .helm/siibra-explorer/ \
+        || helm --kubeconfig=$kubecfg_path \
+          install\
+          --set image.tag=${{ inputs.IMAGE_TAG }} \
+          --set podLabels.image-digest=${{ inputs.IMAGE_DIGEST }} \
+          --set envObj.HOST_PATHNAME=/viewer-expmt \
           ${{ inputs.DEPLOYMENT_NAME }} .helm/siibra-explorer/
           
         rm $kubecfg_path
diff --git a/.helm/siibra-explorer/values.yaml b/.helm/siibra-explorer/values.yaml
index 602d70a8b..81f4da035 100644
--- a/.helm/siibra-explorer/values.yaml
+++ b/.helm/siibra-explorer/values.yaml
@@ -2,7 +2,7 @@
 # This is a YAML-formatted file.
 # Declare variables to be passed into your templates.
 
-replicaCount: 1
+replicaCount: 2
 
 image:
   repository: docker-registry.ebrains.eu/siibra/siibra-explorer
@@ -96,7 +96,6 @@ tolerations: []
 affinity: {}
 
 envObj:
-  HOSTNAME: https://siibra-explorer.apps.tc.humanbrainproject.eu
   OVERWRITE_SPATIAL_ENDPOINT: https://siibra-spatial-backend.apps.tc.humanbrainproject.eu
   HOST_PATHNAME: /viewer
   OVERWRITE_API_ENDPOINT: https://siibra-api-prod.apps.tc.humanbrainproject.eu/v3_0
diff --git a/Dockerfile b/Dockerfile
index e5669e328..44ff04844 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,8 +1,5 @@
 FROM node:16 as builder
 
-ARG BUILD_HASH
-ENV BUILD_HASH=${BUILD_HASH:-devbuild}
-
 ARG BACKEND_URL
 ENV BACKEND_URL=${BACKEND_URL}
 
@@ -47,6 +44,9 @@ RUN node third_party/matomo/processMatomo.js
 # prod container
 FROM python:3.10-alpine
 
+ARG BUILD_HASH
+ENV BUILD_HASH=${BUILD_HASH:-devbuild}
+
 RUN adduser --disabled-password nonroot
 
 RUN mkdir /common
diff --git a/backend/app/version_header.py b/backend/app/version_header.py
index 8ece7c233..4881e4bd5 100644
--- a/backend/app/version_header.py
+++ b/backend/app/version_header.py
@@ -12,5 +12,8 @@ class VersionHeaderMW(BaseHTTPMiddleware):
             or (300 <= resp.status_code < 400) # if the request is redirect, do not interfere
         ):
             return resp
+        
+        # allow for debugging, cache should be busted every 10 min
         resp.headers["ETag"] = BUILD_HASH
+        resp.headers["Cache-Control"] = "max-age=600"
         return resp
diff --git a/docs/releases/v2.14.9.md b/docs/releases/v2.14.9.md
new file mode 100644
index 000000000..016bd441c
--- /dev/null
+++ b/docs/releases/v2.14.9.md
@@ -0,0 +1,5 @@
+# v2.14.9
+
+## Bugfix
+
+- Fix deployment issues
diff --git a/package.json b/package.json
index 356214b9b..0d8728b4f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "siibra-explorer",
-  "version": "2.14.8",
+  "version": "2.14.9",
   "description": "siibra-explorer - explore brain atlases. Based on humanbrainproject/nehuba & google/neuroglancer. Built with angular",
   "scripts": {
     "lint": "eslint src --ext .ts",
-- 
GitLab