apiVersion: apps/v1
kind: Deployment
metadata:
  name: buildkite-agent
spec:
  replicas: 1
  selector:
    matchLabels:
      app: buildkite-agent
  template:
    metadata:
      labels:
        app: buildkite-agent
    spec:
      containers:
        - name: buildkite
          image: labtools/buildkite-agent
          env:
            - name: DOCKER_HOST
              value: tcp://localhost:2375
            - name: BUILDKITE_AGENT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: buildkite-agent
                  key: token
          volumeMounts:
            - name: buildkite-builds
              mountPath: /buildkite/builds
            - name: ssh-keys
              mountPath: /root/.ssh/id_rsa
              subPath: id_rsa
            - name: ssh-keys
              mountPath: /root/.ssh/id_rsa.pub
              subPath: id_rsa.pub
        - name: dind-daemon
          image: docker:20.10.6-dind
          command:
            - "dockerd"
            - "--host=unix:///var/run/docker.sock"
            - "--host=tcp://0.0.0.0:2375"
          securityContext:
            privileged: true
          volumeMounts:
            - name: buildkite-builds
              mountPath: /buildkite/builds
            - name: docker-graph-storage
              mountPath: /var/lib/docker
      terminationGracePeriodSeconds: 900
      volumes:
        - name: docker-graph-storage
          emptyDir: {}
        - name: buildkite-builds
          emptyDir: {}
        - name: ssh-keys
          secret:
            secretName: buildkite-agent-ssh
            defaultMode: 0400
