Skip to content

Commit ce191dc

Browse files
committed
print: update browserless to v2
Remove unsupported parameters: https://docs.browserless.io/baas/migrate#removed-parameters-no-replacements Rename changed parameters: https://docs.browserless.io/baas/migrate#changed-parameters closes: ecamp#8028
1 parent 330a122 commit ce191dc

File tree

9 files changed

+84
-34
lines changed

9 files changed

+84
-34
lines changed

.helm/ecamp3/templates/_helpers.tpl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
5656
{{- end }}
5757
{{- end }}
5858

59+
{{/*
60+
Name for all print+browserless resources.
61+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
62+
*/}}
63+
{{- define "print-browserless.name" -}}
64+
{{- $name := default .Chart.Name .Values.chartNameOverride }}
65+
{{- if contains $name (include "app.name" .) }}
66+
{{- printf "%s-print-browserless" (include "app.name" .) | trunc 63 | trimSuffix "-" }}
67+
{{- else }}
68+
{{- printf "%s-%s-print-browserless" (include "app.name" .) $name | trunc 63 | trimSuffix "-" }}
69+
{{- end }}
70+
{{- end }}
71+
5972
{{/*
6073
Name for all dummy-mailserver-related resources.
6174
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
@@ -266,3 +279,28 @@ Create the name of the service account to use
266279
{{- default "default" .Values.serviceAccount.name }}
267280
{{- end }}
268281
{{- end }}
282+
283+
{{/*
284+
Reuse existing secret value, else generate new one
285+
Parameters:
286+
- namespace
287+
- secretName: name of the secret to lookup
288+
- key: the key within the secret to retrieve/generate
289+
*/}}
290+
{{- define "gen.secret" }}
291+
{{- $namespace := .namespace }}
292+
{{- $secretName := .secretName }}
293+
{{- $key := .key }}
294+
{{- $secret := lookup "v1" "Secret" $namespace $secretName }}
295+
{{- if $secret -}}
296+
{{/*
297+
Reusing existing secret data
298+
*/}}
299+
{{- $key }}: {{ index $secret.data $key }}
300+
{{- else -}}
301+
{{/*
302+
Generate new data
303+
*/}}
304+
{{- $key }}: {{ randAlphaNum 20 | b64enc }}
305+
{{- end -}}
306+
{{- end -}}

.helm/ecamp3/templates/browserless_configmap.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ metadata:
66
{{- include "browserless.selectorLabels" . | nindent 4 }}
77
{{- include "app.commonLabels" . | nindent 4 }}
88
data:
9-
MAX_CONCURRENT_SESSIONS: {{ .Values.browserless.maxConcurrentSessions | quote }}
10-
CONNECTION_TIMEOUT: {{ .Values.browserless.connectionTimeout | quote }}
11-
MAX_QUEUE_LENGTH: {{ .Values.browserless.maxQueueLength | quote }}
9+
CONCURRENT: {{ .Values.browserless.maxConcurrentSessions | quote }}
10+
TIMEOUT: {{ .Values.browserless.connectionTimeout | quote }}
11+
QUEUED: {{ .Values.browserless.maxQueueLength | quote }}

.helm/ecamp3/templates/browserless_deployment.yaml

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@ spec:
3535
containerPort: 3000
3636
protocol: TCP
3737
readinessProbe:
38-
httpGet:
39-
scheme: HTTP
40-
path: /pressure
41-
port: 3000
38+
exec:
39+
command:
40+
- sh
41+
- "-c"
42+
- "curl --fail -q localhost:3000/pressure?token=${TOKEN}"
4243
initialDelaySeconds: 20
4344
periodSeconds: 10
4445
timeoutSeconds: 5
4546
livenessProbe:
46-
httpGet:
47-
scheme: HTTP
48-
path: /pressure
49-
port: 3000
47+
exec:
48+
command:
49+
- sh
50+
- "-c"
51+
- "curl --fail -q localhost:3000/pressure?token=${TOKEN}"
5052
initialDelaySeconds: 20
5153
periodSeconds: 10
5254
timeoutSeconds: 5
@@ -56,14 +58,9 @@ spec:
5658
- configMapRef:
5759
name: {{ include "browserless.name" . }}-configmap
5860
env:
59-
- name: PREBOOT_CHROME
60-
value: "true"
61-
- name: KEEP_ALIVE
62-
value: "true"
63-
- name: ENABLE_DEBUGGER
64-
value: "false"
65-
- name: FUNCTION_ENABLE_INCOGNITO_MODE
66-
value: "true"
67-
- name: DISABLED_FEATURES
68-
value: '["downloadEndpoint","functionEndpoint","pdfEndpoint","screencastEndpoint","scrapeEndpoint","statsEndpoint","workspaces"]'
69-
{{- end }}
61+
- name: TOKEN
62+
valueFrom:
63+
secretKeyRef:
64+
key: BROWSERLESS_TOKEN
65+
name: {{ include "print-browserless.name" . }}
66+
{{- end }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{ $secretName := include "print-browserless.name" . }}
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: {{ $secretName }}
6+
labels:
7+
{{- include "print.selectorLabels" . | nindent 4 }}
8+
{{- include "app.commonLabels" . | nindent 4 }}
9+
type: Opaque
10+
data:
11+
{{- include "gen.secret" (dict "namespace" .Release.Namespace "secretName" $secretName "key" "BROWSERLESS_TOKEN") | nindent 2 }}

.helm/ecamp3/templates/print_deployment.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ spec:
7272
secretKeyRef:
7373
name: {{ include "print.name" . }}
7474
key: browser-ws-endpoint
75+
- name: NUXT_BROWSERLESS_TOKEN
76+
valueFrom:
77+
secretKeyRef:
78+
name: {{ include "print-browserless.name" . }}
79+
key: BROWSERLESS_TOKEN
7580
- name: NITRO_PORT
7681
value: "3003"
7782
{{- if and .Values.ingress.enabled .Values.ingress.basicAuth.enabled }}

.helm/ecamp3/values.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ browserless:
112112
enabled: true
113113
domain:
114114
image:
115-
repository: "docker.io/browserless/chrome"
115+
repository: "ghcr.io/browserless/chrome"
116116
pullPolicy: IfNotPresent
117-
# renovate: datasource=docker depName=browserless/chrome
118-
tag: "1.61.1-puppeteer-21.4.1"
117+
# renovate: datasource=docker depName=ghcr.io/browserless/chrome
118+
tag: "v2.34.1"
119119
service:
120120
type: ClusterIP
121121
port: 3000

docker-compose.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,16 @@ services:
169169
restart: on-failure
170170

171171
browserless:
172-
image: browserless/chrome:1.61.1-puppeteer-21.9.0
172+
image: ghcr.io/browserless/chrome:v2.34.1
173173
container_name: 'ecamp3-browserless'
174174
ports:
175175
- '3010:3000'
176176
environment:
177-
- MAX_CONCURRENT_SESSIONS=1
178-
- CONNECTION_TIMEOUT=40000
179-
- MAX_QUEUE_LENGTH=10
180-
- PREBOOT_CHROME=true
181-
- KEEP_ALIVE=true
177+
- TOKEN=1234
178+
- CONCURRENT=1
179+
- TIMEOUT=40000
180+
- QUEUED=10
182181
- ENABLE_DEBUGGER=false
183-
- DISABLED_FEATURES=["downloadEndpoint","functionEndpoint","pdfEndpoint","screencastEndpoint","scrapeEndpoint","statsEndpoint","workspaces"]
184-
- FUNCTION_ENABLE_INCOGNITO_MODE=true
185182

186183
e2e:
187184
image: cypress/included:15.4.0@sha256:2039347f99ef06ba66f8365361b7e869b7ba00e5d9437958f1df4c499909ec14

print/nuxt.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default defineNuxtConfig({
6464
runtimeConfig: {
6565
basicAuthToken: null,
6666
browserWsEndpoint: 'ws://browserless:3000',
67+
browserlessToken: '1234',
6768
printUrl: 'http://print:3003/print',
6869
internalApiRootUrl: 'http://api:3000/api',
6970
cookiePrefix: 'localhost_',

print/server/api/pdf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default defineEventHandler(async (event) => {
4141
const {
4242
basicAuthToken,
4343
browserWsEndpoint,
44+
browserlessToken,
4445
printUrl,
4546
cookiePrefix,
4647
renderHtmlTimeoutMs,
@@ -62,7 +63,7 @@ export default defineEventHandler(async (event) => {
6263

6364
// Connect to browserless.io (puppeteer websocket)
6465
browser = await puppeteer.connect({
65-
browserWSEndpoint: browserWsEndpoint,
66+
browserWSEndpoint: browserWsEndpoint + `/chrome?token=${browserlessToken}`,
6667
})
6768
const context = await browser.createBrowserContext()
6869
measurePerformance(performanceMeasurements, 'puppeteer_connect')

0 commit comments

Comments
 (0)