Skip to content

Commit 32296d0

Browse files
committed
fix(worker): dockerfile + helm updates
1 parent a7c1e51 commit 32296d0

File tree

7 files changed

+203
-2
lines changed

7 files changed

+203
-2
lines changed

apps/sim/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
"load:workflow:baseline": "BASE_URL=${BASE_URL:-http://localhost:3000} WARMUP_DURATION=${WARMUP_DURATION:-10} WARMUP_RATE=${WARMUP_RATE:-2} PEAK_RATE=${PEAK_RATE:-8} HOLD_DURATION=${HOLD_DURATION:-20} bunx artillery run scripts/load/workflow-concurrency.yml",
1818
"load:workflow:waves": "BASE_URL=${BASE_URL:-http://localhost:3000} WAVE_ONE_DURATION=${WAVE_ONE_DURATION:-10} WAVE_ONE_RATE=${WAVE_ONE_RATE:-6} QUIET_DURATION=${QUIET_DURATION:-5} WAVE_TWO_DURATION=${WAVE_TWO_DURATION:-15} WAVE_TWO_RATE=${WAVE_TWO_RATE:-8} WAVE_THREE_DURATION=${WAVE_THREE_DURATION:-20} WAVE_THREE_RATE=${WAVE_THREE_RATE:-10} bunx artillery run scripts/load/workflow-waves.yml",
1919
"load:workflow:isolation": "BASE_URL=${BASE_URL:-http://localhost:3000} ISOLATION_DURATION=${ISOLATION_DURATION:-30} TOTAL_RATE=${TOTAL_RATE:-9} WORKSPACE_A_WEIGHT=${WORKSPACE_A_WEIGHT:-8} WORKSPACE_B_WEIGHT=${WORKSPACE_B_WEIGHT:-1} bunx artillery run scripts/load/workflow-isolation.yml",
20-
"build": "bun run build:pptx-worker && next build",
20+
"build": "bun run build:pptx-worker && bun run build:worker && next build",
2121
"build:pptx-worker": "bun build ./lib/execution/pptx-worker.cjs --target=node --format=cjs --outfile ./dist/pptx-worker.cjs",
22+
"build:worker": "bun build ./worker/index.ts --target=node --format=cjs --packages=external --outfile ./dist/worker.cjs",
2223
"start": "next start",
2324
"worker": "NODE_ENV=production bun run worker/index.ts",
2425
"prepare": "cd ../.. && bun husky",

docker-compose.local.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,38 @@ services:
6767
retries: 3
6868
start_period: 10s
6969

70+
sim-worker:
71+
build:
72+
context: .
73+
dockerfile: docker/app.Dockerfile
74+
command: ['bun', 'apps/sim/dist/worker.cjs']
75+
restart: unless-stopped
76+
profiles:
77+
- worker
78+
deploy:
79+
resources:
80+
limits:
81+
memory: 4G
82+
environment:
83+
- NODE_ENV=development
84+
- DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-simstudio}
85+
- REDIS_URL=${REDIS_URL:-}
86+
- ENCRYPTION_KEY=${ENCRYPTION_KEY:-dev-encryption-key-at-least-32-chars}
87+
- API_ENCRYPTION_KEY=${API_ENCRYPTION_KEY:-}
88+
- INTERNAL_API_SECRET=${INTERNAL_API_SECRET:-dev-internal-api-secret-min-32-chars}
89+
- WORKER_PORT=3001
90+
depends_on:
91+
db:
92+
condition: service_healthy
93+
migrations:
94+
condition: service_completed_successfully
95+
healthcheck:
96+
test: ['CMD', 'wget', '--spider', '--quiet', 'http://127.0.0.1:3001/health/live']
97+
interval: 90s
98+
timeout: 5s
99+
retries: 3
100+
start_period: 10s
101+
70102
migrations:
71103
build:
72104
context: .

docker-compose.prod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ services:
4242

4343
sim-worker:
4444
image: ghcr.io/simstudioai/simstudio:latest
45-
command: ['bun', 'run', 'worker']
45+
command: ['bun', 'apps/sim/dist/worker.cjs']
4646
restart: unless-stopped
4747
deploy:
4848
resources:

docker/app.Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/lib/execution/isolated-v
114114
# Copy the bundled PPTX worker artifact
115115
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/dist/pptx-worker.cjs ./apps/sim/dist/pptx-worker.cjs
116116

117+
# Copy the bundled BullMQ worker artifact
118+
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/dist/worker.cjs ./apps/sim/dist/worker.cjs
119+
117120
# Guardrails setup with pip caching
118121
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/lib/guardrails/requirements.txt ./apps/sim/lib/guardrails/requirements.txt
119122
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/lib/guardrails/validate_pii.py ./apps/sim/lib/guardrails/validate_pii.py

helm/sim/templates/_helpers.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ Ollama selector labels
117117
app.kubernetes.io/component: ollama
118118
{{- end }}
119119

120+
{{/*
121+
Worker specific labels
122+
*/}}
123+
{{- define "sim.worker.labels" -}}
124+
{{ include "sim.labels" . }}
125+
app.kubernetes.io/component: worker
126+
{{- end }}
127+
128+
{{/*
129+
Worker selector labels
130+
*/}}
131+
{{- define "sim.worker.selectorLabels" -}}
132+
{{ include "sim.selectorLabels" . }}
133+
app.kubernetes.io/component: worker
134+
{{- end }}
135+
120136
{{/*
121137
Migrations specific labels
122138
*/}}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{{- if .Values.worker.enabled }}
2+
{{- include "sim.validateSecrets" . }}
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
name: {{ include "sim.fullname" . }}-worker
7+
namespace: {{ .Release.Namespace }}
8+
labels:
9+
{{- include "sim.worker.labels" . | nindent 4 }}
10+
spec:
11+
replicas: {{ .Values.worker.replicaCount }}
12+
selector:
13+
matchLabels:
14+
{{- include "sim.worker.selectorLabels" . | nindent 6 }}
15+
template:
16+
metadata:
17+
annotations:
18+
{{- with .Values.podAnnotations }}
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
{{- include "sim.worker.selectorLabels" . | nindent 8 }}
23+
{{- with .Values.podLabels }}
24+
{{- toYaml . | nindent 8 }}
25+
{{- end }}
26+
spec:
27+
{{- with .Values.global.imagePullSecrets }}
28+
imagePullSecrets:
29+
{{- toYaml . | nindent 8 }}
30+
{{- end }}
31+
serviceAccountName: {{ include "sim.serviceAccountName" . }}
32+
{{- include "sim.podSecurityContext" .Values.worker | nindent 6 }}
33+
{{- include "sim.nodeSelector" .Values.worker | nindent 6 }}
34+
{{- include "sim.tolerations" .Values | nindent 6 }}
35+
{{- include "sim.affinity" .Values | nindent 6 }}
36+
containers:
37+
- name: worker
38+
image: {{ include "sim.image" (dict "context" . "image" .Values.worker.image) }}
39+
imagePullPolicy: {{ .Values.worker.image.pullPolicy }}
40+
command: ["bun", "apps/sim/dist/worker.cjs"]
41+
ports:
42+
- name: health
43+
containerPort: {{ .Values.worker.healthPort }}
44+
protocol: TCP
45+
env:
46+
- name: DATABASE_URL
47+
value: {{ include "sim.databaseUrl" . | quote }}
48+
{{- if .Values.app.env.REDIS_URL }}
49+
- name: REDIS_URL
50+
value: {{ .Values.app.env.REDIS_URL | quote }}
51+
{{- end }}
52+
- name: WORKER_PORT
53+
value: {{ .Values.worker.healthPort | quote }}
54+
{{- if .Values.telemetry.enabled }}
55+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
56+
value: "http://{{ include "sim.fullname" . }}-otel-collector:4318"
57+
- name: OTEL_SERVICE_NAME
58+
value: sim-worker
59+
- name: OTEL_SERVICE_VERSION
60+
value: {{ .Chart.AppVersion | quote }}
61+
- name: OTEL_RESOURCE_ATTRIBUTES
62+
value: "service.name=sim-worker,service.version={{ .Chart.AppVersion }},deployment.environment={{ .Values.worker.env.NODE_ENV }}"
63+
{{- end }}
64+
{{- range $key, $value := .Values.worker.env }}
65+
- name: {{ $key }}
66+
value: {{ $value | quote }}
67+
{{- end }}
68+
{{- with .Values.extraEnvVars }}
69+
{{- toYaml . | nindent 12 }}
70+
{{- end }}
71+
envFrom:
72+
- secretRef:
73+
name: {{ include "sim.appSecretName" . }}
74+
{{- if .Values.postgresql.enabled }}
75+
- secretRef:
76+
name: {{ include "sim.postgresqlSecretName" . }}
77+
{{- else if .Values.externalDatabase.enabled }}
78+
- secretRef:
79+
name: {{ include "sim.externalDbSecretName" . }}
80+
{{- end }}
81+
livenessProbe:
82+
httpGet:
83+
path: /health/live
84+
port: health
85+
initialDelaySeconds: 10
86+
periodSeconds: 30
87+
timeoutSeconds: 5
88+
failureThreshold: 3
89+
readinessProbe:
90+
httpGet:
91+
path: /health
92+
port: health
93+
initialDelaySeconds: 10
94+
periodSeconds: 30
95+
timeoutSeconds: 5
96+
failureThreshold: 3
97+
{{- include "sim.resources" .Values.worker | nindent 10 }}
98+
{{- include "sim.securityContext" .Values.worker | nindent 10 }}
99+
{{- end }}

helm/sim/values.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,56 @@ realtime:
358358
extraVolumes: []
359359
extraVolumeMounts: []
360360

361+
# BullMQ worker configuration (processes background jobs when Redis is available)
362+
# Uses the same image as the main app with a different command
363+
worker:
364+
# Enable/disable the worker deployment (requires REDIS_URL to be set in app.env)
365+
enabled: false
366+
367+
# Image configuration (defaults to same image as app)
368+
image:
369+
repository: simstudioai/simstudio
370+
tag: latest
371+
pullPolicy: Always
372+
373+
# Number of replicas
374+
replicaCount: 1
375+
376+
# Health check port (worker exposes a lightweight HTTP health server)
377+
healthPort: 3001
378+
379+
# Resource limits and requests
380+
resources:
381+
limits:
382+
memory: "4Gi"
383+
cpu: "1000m"
384+
requests:
385+
memory: "2Gi"
386+
cpu: "500m"
387+
388+
# Node selector for pod scheduling
389+
nodeSelector: {}
390+
391+
# Pod security context
392+
podSecurityContext:
393+
fsGroup: 1001
394+
395+
# Container security context
396+
securityContext:
397+
runAsNonRoot: true
398+
runAsUser: 1001
399+
400+
# Environment variables (worker-specific tuning)
401+
env:
402+
NODE_ENV: "production"
403+
WORKER_CONCURRENCY_WORKFLOW: "50"
404+
WORKER_CONCURRENCY_WEBHOOK: "30"
405+
WORKER_CONCURRENCY_SCHEDULE: "20"
406+
WORKER_CONCURRENCY_MOTHERSHIP_JOB: "10"
407+
WORKER_CONCURRENCY_CONNECTOR_SYNC: "5"
408+
WORKER_CONCURRENCY_DOCUMENT_PROCESSING: "20"
409+
WORKER_CONCURRENCY_NOTIFICATION_DELIVERY: "10"
410+
361411
# Database migrations job configuration
362412
migrations:
363413
# Enable/disable migrations job

0 commit comments

Comments
 (0)