Skip to content

Commit dc568e7

Browse files
authored
Self-hosting: improved worker and bucket bootstrap (#2209)
1 parent fa6675e commit dc568e7

File tree

7 files changed

+111
-8
lines changed

7 files changed

+111
-8
lines changed

docs/self-hosting/docker.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ You should change these before deploying to production, especially the password.
244244
245245
### Setup
246246
247+
<Note>
248+
The `packets` bucket is created by default. In case this doesn't work, you can create it manually.
249+
</Note>
250+
247251
1. Login to the dashboard: `http://localhost:9001`
248252
249253
2. Create a bucket named `packets`.

docs/upgrade-to-v4.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ You can also now control whether concurrency is released when performing a wait:
761761

762762
```ts
763763
// This will prevent the run from being released back into the queue when the wait starts
764-
await wait.for({ seconds: 10 }, { releaseConcurrency: false });
764+
await wait.for({ seconds: 10, releaseConcurrency: false });
765765
```
766766

767767
The new default behavior allows you to ensure that you can control the number of executing & waiting runs on a queue, and guarantee runs will resume once they are meant to be resumed.

hosting/docker/webapp/docker-compose.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ services:
181181
start_period: 10s
182182

183183
minio:
184-
image: minio/minio:${MINIO_IMAGE_TAG:-latest}
184+
image: bitnami/minio:${MINIO_IMAGE_TAG:-latest}
185185
restart: ${RESTART_POLICY:-unless-stopped}
186186
logging: *logging-config
187187
ports:
@@ -190,11 +190,12 @@ services:
190190
networks:
191191
- webapp
192192
volumes:
193-
- minio:/data
193+
- minio:/bitnami/minio/data
194194
environment:
195195
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-admin}
196196
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-very-safe-password}
197-
command: server --console-address ":9001" /data
197+
MINIO_DEFAULT_BUCKETS: packets
198+
MINIO_BROWSER: "on"
198199
healthcheck:
199200
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
200201
interval: 5s

hosting/k8s/helm/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ apiVersion: v2
22
name: trigger
33
description: The official Trigger.dev Helm chart
44
type: application
5-
version: 4.0.0-beta.7
6-
appVersion: trigger-helm-rc.0
5+
version: 4.0.0-beta.10
6+
appVersion: trigger-helm-rc.1
77
home: https://trigger.dev
88
sources:
99
- https://github.com/triggerdotdev/trigger.dev

hosting/k8s/helm/templates/supervisor.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ spec:
7474
{{- with .Values.supervisor.podSecurityContext }}
7575
{{- toYaml . | nindent 8 }}
7676
{{- end }}
77+
{{- if not .Values.webapp.bootstrap.enabled }}
7778
initContainers:
7879
- name: init-shared
7980
image: busybox:1.35
@@ -83,6 +84,7 @@ spec:
8384
volumeMounts:
8485
- name: shared
8586
mountPath: /home/node/shared
87+
{{- end }}
8688
containers:
8789
- name: supervisor
8890
image: {{ include "trigger-v4.supervisor.image" . }}
@@ -134,8 +136,11 @@ spec:
134136
- name: TRIGGER_API_URL
135137
value: "http://{{ include "trigger-v4.fullname" . }}-webapp:{{ .Values.webapp.service.port }}"
136138
- name: TRIGGER_WORKER_TOKEN
137-
{{- if .Values.supervisor.bootstrap.enabled }}
138-
value: "file://{{ .Values.supervisor.bootstrap.workerTokenPath }}"
139+
{{- if .Values.webapp.bootstrap.enabled }}
140+
valueFrom:
141+
secretKeyRef:
142+
name: {{ include "trigger-v4.fullname" . }}-worker-token
143+
key: token
139144
{{- else if .Values.supervisor.bootstrap.workerToken.secret.name }}
140145
valueFrom:
141146
secretKeyRef:
@@ -234,13 +239,16 @@ spec:
234239
{{- with .Values.supervisor.extraEnvVars }}
235240
{{- toYaml . | nindent 12 }}
236241
{{- end }}
242+
{{- if not .Values.webapp.bootstrap.enabled }}
237243
volumeMounts:
238244
- name: shared
239245
mountPath: /home/node/shared
246+
{{- end }}
240247
{{- with .Values.supervisor.securityContext }}
241248
securityContext:
242249
{{- toYaml . | nindent 12 }}
243250
{{- end }}
251+
{{- if not .Values.webapp.bootstrap.enabled }}
244252
volumes:
245253
- name: shared
246254
{{- if .Values.persistence.shared.enabled }}
@@ -249,6 +257,7 @@ spec:
249257
{{- else }}
250258
emptyDir: {}
251259
{{- end }}
260+
{{- end }}
252261
{{- with .Values.supervisor.nodeSelector }}
253262
nodeSelector:
254263
{{- toYaml . | nindent 8 }}

hosting/k8s/helm/templates/webapp.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: {{ include "trigger-v4.fullname" . }}-webapp
5+
labels:
6+
{{- $component := "webapp" }}
7+
{{- include "trigger-v4.componentLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "component" $component) | nindent 4 }}
8+
---
9+
apiVersion: rbac.authorization.k8s.io/v1
10+
kind: Role
11+
metadata:
12+
name: {{ include "trigger-v4.fullname" . }}-webapp-token-syncer
13+
labels:
14+
{{- $component := "webapp" }}
15+
{{- include "trigger-v4.componentLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "component" $component) | nindent 4 }}
16+
rules:
17+
- apiGroups: [""]
18+
resources: ["secrets"]
19+
verbs: ["create", "get", "update", "patch"]
20+
---
21+
apiVersion: rbac.authorization.k8s.io/v1
22+
kind: RoleBinding
23+
metadata:
24+
name: {{ include "trigger-v4.fullname" . }}-webapp-token-syncer
25+
labels:
26+
{{- $component := "webapp" }}
27+
{{- include "trigger-v4.componentLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "component" $component) | nindent 4 }}
28+
subjects:
29+
- kind: ServiceAccount
30+
name: {{ include "trigger-v4.fullname" . }}-webapp
31+
namespace: {{ .Release.Namespace }}
32+
roleRef:
33+
kind: Role
34+
name: {{ include "trigger-v4.fullname" . }}-webapp-token-syncer
35+
apiGroup: rbac.authorization.k8s.io
36+
---
137
apiVersion: apps/v1
238
kind: Deployment
339
metadata:
@@ -19,6 +55,7 @@ spec:
1955
labels:
2056
{{- include "trigger-v4.componentSelectorLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "component" $component) | nindent 8 }}
2157
spec:
58+
serviceAccountName: {{ include "trigger-v4.fullname" . }}-webapp
2259
{{- with .Values.global.imagePullSecrets }}
2360
imagePullSecrets:
2461
{{- toYaml . | nindent 8 }}
@@ -38,6 +75,55 @@ spec:
3875
- name: shared
3976
mountPath: /home/node/shared
4077
containers:
78+
- name: token-syncer
79+
image: bitnami/kubectl:1.28
80+
securityContext:
81+
runAsUser: 1000
82+
runAsNonRoot: true
83+
command:
84+
- /bin/bash
85+
- -c
86+
- |
87+
TOKEN_FILE="/home/node/shared/worker_token"
88+
SECRET_NAME="{{ include "trigger-v4.fullname" . }}-worker-token"
89+
NAMESPACE="{{ .Release.Namespace }}"
90+
91+
echo "Token syncer starting..."
92+
echo "Monitoring: $TOKEN_FILE"
93+
echo "Target secret: $SECRET_NAME"
94+
95+
while true; do
96+
if [ -f "$TOKEN_FILE" ]; then
97+
TOKEN=$(cat "$TOKEN_FILE")
98+
if [ ! -z "$TOKEN" ]; then
99+
echo "Token file found, creating/updating secret..."
100+
101+
# Create or update the secret
102+
kubectl create secret generic "$SECRET_NAME" \
103+
--from-literal=token="$TOKEN" \
104+
--namespace="$NAMESPACE" \
105+
--dry-run=client -o yaml | kubectl apply -f -
106+
107+
if [ $? -eq 0 ]; then
108+
echo "Secret successfully created/updated"
109+
# Continue monitoring for updates
110+
sleep 30
111+
else
112+
echo "Failed to create/update secret, retrying in 5s..."
113+
sleep 5
114+
fi
115+
else
116+
echo "Token file exists but is empty, waiting..."
117+
sleep 2
118+
fi
119+
else
120+
echo "Waiting for token file..."
121+
sleep 2
122+
fi
123+
done
124+
volumeMounts:
125+
- name: shared
126+
mountPath: /home/node/shared
41127
- name: webapp
42128
securityContext:
43129
{{- toYaml .Values.webapp.securityContext | nindent 12 }}

hosting/k8s/helm/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ s3:
476476
rootUser: "admin"
477477
rootPassword: "very-safe-password"
478478

479+
# The required "packets" bucket is created by default.
480+
defaultBuckets: "packets"
481+
479482
persistence:
480483
enabled: true
481484
size: 10Gi

0 commit comments

Comments
 (0)