From 66feef2a3da0078e45b06e361dd97ae438f05cc4 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sat, 1 Apr 2023 09:30:47 +0200 Subject: [PATCH] Revert "[SSR-1] Removal of Rendertron (#474)" This reverts commit 7b58985af3a9213f78e34f9caa89f28d97596bd6. --- .../web/rendertron-deployment.yaml | 68 +++++++++++++++++++ .../k3s/templates/networking/ingress.yaml | 5 ++ .../middleware/stripprefix-middleware.yaml | 1 + .../k3s/templates/networking/service.yaml | 18 +++++ webclient/nginx.conf | 41 +++++++++++ 5 files changed, 133 insertions(+) create mode 100644 deployment/k3s/templates/deployments/web/rendertron-deployment.yaml diff --git a/deployment/k3s/templates/deployments/web/rendertron-deployment.yaml b/deployment/k3s/templates/deployments/web/rendertron-deployment.yaml new file mode 100644 index 000000000..fbd8c6e5c --- /dev/null +++ b/deployment/k3s/templates/deployments/web/rendertron-deployment.yaml @@ -0,0 +1,68 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: rendertron + labels: + app: navigatum + deployment: rendertron + namespace: {{ $.Values.namespace }} +spec: + replicas: {{ if eq "nav.tum.de" $.Values.url }}2{{ else }}1{{ end }} + revisionHistoryLimit: 1 + selector: + matchLabels: + app: navigatum + deployment: rendertron + strategy: + rollingUpdate: + maxSurge: {{ if eq "nav.tum.de" $.Values.url }}50%{{ else }}100%{{ end }} + maxUnavailable: {{ if eq "nav.tum.de" $.Values.url }}50%{{ else }}0%{{ end }} + type: RollingUpdate + template: + metadata: + labels: + app: navigatum + deployment: rendertron + spec: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: tileserver + operator: In + values: + - ready + volumes: + - name: tmp-rendertron + emptyDir: {} + containers: + - name: rendertron + image: dockette/rendertron + imagePullPolicy: Always + ports: + - containerPort: 3000 + name: rendertron + volumeMounts: + - mountPath: /tmp + name: tmp-rendertron + securityContext: + readOnlyRootFilesystem: true + resources: + requests: + cpu: 50m + memory: 200Mi + limits: + memory: 500Mi + livenessProbe: + httpGet: + path: /_ah/health + port: rendertron + failureThreshold: 1 + periodSeconds: 60 + startupProbe: + httpGet: + path: /_ah/health + port: rendertron + failureThreshold: 20 + periodSeconds: 5 diff --git a/deployment/k3s/templates/networking/ingress.yaml b/deployment/k3s/templates/networking/ingress.yaml index 5af3aa870..3e53669b5 100644 --- a/deployment/k3s/templates/networking/ingress.yaml +++ b/deployment/k3s/templates/networking/ingress.yaml @@ -37,6 +37,11 @@ spec: services: - name: cdn-svc port: 8000 + - kind: Rule + match: Host(`{{ $.Values.url }}`) && PathPrefix(`/rendertron/`) + services: + - name: rendertron-svc + port: 9100 middlewares: - name: stripprefix - kind: Rule diff --git a/deployment/k3s/templates/networking/middleware/stripprefix-middleware.yaml b/deployment/k3s/templates/networking/middleware/stripprefix-middleware.yaml index b9b77ccc7..17055250e 100644 --- a/deployment/k3s/templates/networking/middleware/stripprefix-middleware.yaml +++ b/deployment/k3s/templates/networking/middleware/stripprefix-middleware.yaml @@ -8,4 +8,5 @@ metadata: spec: stripPrefix: prefixes: + - /rendertron - /maps diff --git a/deployment/k3s/templates/networking/service.yaml b/deployment/k3s/templates/networking/service.yaml index f1dc529ac..5f0f67cce 100644 --- a/deployment/k3s/templates/networking/service.yaml +++ b/deployment/k3s/templates/networking/service.yaml @@ -108,3 +108,21 @@ spec: - name: webclient port: 9000 targetPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: rendertron-svc + labels: + app: navigatum + deployment: rendertron + namespace: {{ $.Values.namespace }} +spec: + type: ClusterIP + selector: + app: navigatum + deployment: rendertron + ports: + - name: rendertron + port: 9100 + targetPort: 3000 diff --git a/webclient/nginx.conf b/webclient/nginx.conf index 34f88e70a..e59504734 100644 --- a/webclient/nginx.conf +++ b/webclient/nginx.conf @@ -44,6 +44,31 @@ http { "de" "de"; } + # bot without js-execution workaround + # see https://github.com/GoogleChrome/rendertron/blob/main/middleware/src/middleware.ts#L24-L41 + map $http_user_agent $no_js_exec { + default 0; + '~*Baiduspider' 1; + '~*bingbot' 1; + '~*Embedly' 1; + '~*facebookexternalhit' 1; + '~*LinkedInBot' 1; + '~*outbrain' 1; + '~*pinterest' 1; + '~*quora link preview' 1; + '~*rogerbot' 1; + '~*showyoubot' 1; + '~*Slackbot' 1; + '~*TelegramBot' 1; + '~*Twitterbot' 1; + '~*vkShare' 1; + '~*W3C_Validator' 1; + '~*WhatsApp' 1; + '~*Discordbot' 1; + '~*googlebot' 1; + '~*SemrushBot' 1; + } + server { # default_server makes nginx not care about HOST, we hande this upstream by Traefik listen 80 default_server; @@ -72,6 +97,22 @@ http { return 200 'healthy'; } + if ($no_js_exec = 1) { + rewrite ^/(((api|search|about|view|campus|site|building|room)/?.*)?)$ /rendertron/$1; + } + # equivalent to: + #if ($uri ~ ^/((\.well-known|assets)/.*|(robots.txt|googlebef9161f1176c5e0.html|adds.txt|app-ads.txt|favicon.ico|health|404.html|50x.html))$){ + # set $no_js_exec 0; + #} + + #render all pages, that could execute js via rendertron + location ^~ /rendertron/ { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header User-Agent 'Rendertron'; + proxy_pass https://rendertron.navigatum-scv.svc.cluster.local/rendertron/render/https://nav.tum.de$request_uri; + } + location / { add_header Cache-Control no-cache; # disable caching, as we do not want to have theme/language related issues expires 360s; # 360s=5min