Skip to content

Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.

7.8 KB
Raw Blame
{{- $component := "server" -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "openbot.componentName" (dict "root" . "component" $component) }}
  labels:
{{ include "openbot.componentLabels" (dict "root" . "component" $component) | indent 4 }}
  {{- with .Values.commonAnnotations }}
  annotations:
{{ toYaml . | indent 4 }}
  {{- end }}
spec:
  {{- /* Left unset when the HPA owns it, so a chart upgrade cannot undo a scale the HPA decided. */}}
  {{- if not .Values.server.autoscaling.enabled }}
  replicas: {{ .Values.server.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
{{ include "openbot.componentSelectorLabels" (dict "root" . "component" $component) | indent 6 }}
  template:
    metadata:
      labels:
{{ include "openbot.componentSelectorLabels" (dict "root" . "component" $component) | indent 8 }}
        {{- if .Values.postgresql.enabled }}
        {{- /*
          The bundled database's own policy admits pods carrying this label and nothing else.
          
          Its shipped default is `allowExternal: true`, which renders an ingress rule with no `from`
          at all: any pod in any namespace may open 5432, the Bot's browser container included. That
          is pinned off in this chart's values, which makes this label the thing that lets the API in,
          and the reason a Bot's computer is now refused.
        */}}
        {{ .Release.Name }}-postgresql-client: "true"
        {{- end }}
        {{- with .Values.server.podLabels }}
{{ toYaml . | indent 8 }}
        {{- end }}
      annotations:
        {{- /*
          Roll the pods when configuration changes.

          Without this a `helm upgrade` that only changes the ConfigMap leaves every replica running
          the old values, and the deployment looks upgraded while behaving exactly as it did.
        */}}
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
        {{- if eq .Values.computers.mode "sandbox" }}
        {{- /*
          The shape of a computer, which the server reads once and keeps.

          A mounted ConfigMap does update in place, but the file is read on the first computer request
          and the provider built from it is held for the life of the process. Without this the
          template can change under a running server and every Sandbox it creates is still cut from
          the old one, which is a rollout that looks like it worked and changes nothing.
        */}}
        checksum/computer-template: {{ include (print $.Template.BasePath "/computer/pod-template.yaml") . | sha256sum }}
        {{- end }}
        {{- with .Values.server.podAnnotations }}
{{ toYaml . | indent 8 }}
        {{- end }}
    spec:
      serviceAccountName: {{ include "openbot.serviceAccountName" . }}
      automountServiceAccountToken: {{ include "openbot.automountToken" . }}
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with .Values.podSecurityContext }}
      securityContext:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- $affinity := include "openbot.podAntiAffinity" (dict "root" . "component" $component) }}
      {{- if $affinity }}
      affinity:
{{ $affinity | indent 8 }}
      {{- end }}
      {{- with .Values.server.topologySpreadConstraints }}
      topologySpreadConstraints:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with .Values.server.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with .Values.server.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
      {{- end }}
      containers:
        - name: server
          image: {{ include "openbot.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          {{- with .Values.securityContext }}
          securityContext:
{{ toYaml . | indent 12 }}
          {{- end }}
          ports:
            - name: http
              containerPort: {{ .Values.server.service.port }}
              protocol: TCP
          env:
{{ include "openbot.databaseUrlEnv" . | indent 12 }}
{{ include "openbot.commonEnv" . | indent 12 }}
            {{- /* The server's alone, not commonEnv's: only the API creates Learning containers. */}}
            {{- with (include "openbot.learningServiceTokenEnv" . | trim) }}
            {{- . | nindent 12 }}
            {{- end }}
            {{- /* Also the server's alone: only the API calls Composio, so the CronJobs are not handed the key. */}}
            {{- $composio := include "openbot.secretKeySource" (dict "root" . "key" "composio-api-key" "literal" .Values.secrets.composioApiKey) }}
            {{- if $composio }}
            - name: COMPOSIO_API_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include "openbot.secretName" . }}
                  key: composio-api-key
                  {{- if eq $composio "unknown" }}
                  optional: true
                  {{- end }}
            {{- end }}
          envFrom:
            - configMapRef:
                name: {{ include "openbot.configMapName" . }}
            {{- with .Values.config.extraEnvFrom }}
{{ toYaml . | indent 12 }}
            {{- end }}
          {{- /*
            Three probes, and the startup one is the reason the other two can be impatient.

            A cold start migrates nothing but does read and validate the tenant package, so first
            boot is slower than steady state. Without a startup probe the liveness one has to be
            slack enough for the slowest boot, which means a wedged replica stays in the Service for
            as long as a healthy slow one would.
          */}}
          startupProbe:
            httpGet:
              path: /health
              port: http
            periodSeconds: {{ .Values.server.startupProbe.periodSeconds }}
            failureThreshold: {{ .Values.server.startupProbe.failureThreshold }}
          readinessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: {{ .Values.server.readinessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.server.readinessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.server.readinessProbe.timeoutSeconds }}
            failureThreshold: {{ .Values.server.readinessProbe.failureThreshold }}
          livenessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: {{ .Values.server.livenessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.server.livenessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.server.livenessProbe.timeoutSeconds }}
            failureThreshold: {{ .Values.server.livenessProbe.failureThreshold }}
          {{- $sandbox := eq .Values.computers.mode "sandbox" }}
          {{- if or $sandbox .Values.config.extraVolumeMounts }}
          volumeMounts:
            {{- if $sandbox }}
            {{- /* The shape of a Bot's computer, as a file rather than as a permission to read one. */}}
            - name: sandbox-template
              mountPath: /etc/openbot
              readOnly: true
            {{- end }}
            {{- with (include "openbot.extraVolumeMounts" . | trim) }}
            {{- . | nindent 12 }}
            {{- end }}
          {{- end }}
          {{- with .Values.server.resources }}
          resources:
{{ toYaml . | indent 12 }}
          {{- end }}
      {{- if or (eq .Values.computers.mode "sandbox") .Values.config.extraVolumes }}
      volumes:
        {{- if eq .Values.computers.mode "sandbox" }}
        - name: sandbox-template
          configMap:
            name: {{ include "openbot.componentName" (dict "root" . "component" "computer-template") }}
        {{- end }}
        {{- with (include "openbot.extraVolumes" . | trim) }}
        {{- . | nindent 8 }}
        {{- end }}
      {{- end }}