Skip to content

Commit

Permalink
Revert "[SSR-1] Removal of Rendertron (#474)"
Browse files Browse the repository at this point in the history
This reverts commit 7b58985.
  • Loading branch information
CommanderStorm authored Apr 1, 2023
1 parent b8cb11d commit 66feef2
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions deployment/k3s/templates/networking/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ metadata:
spec:
stripPrefix:
prefixes:
- /rendertron
- /maps
18 changes: 18 additions & 0 deletions deployment/k3s/templates/networking/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 41 additions & 0 deletions webclient/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 66feef2

Please sign in to comment.