apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: dagger
spec:
  description: Run Dagger pipeline
  workspaces:
  - name: source
  params:
    - name: dagger-cloud-token
      type: string
      description: Dagger Cloud Token
  volumes:
    - name: dagger-socket
      emptyDir: {}
    - name: dagger-storage
      emptyDir: {}
  sidecars:
    - name: dagger-engine
      image: registry.dagger.io/engine:v0.9.1
      args:
        - "--oci-max-parallelism"
        - "num-cpu"
      securityContext:
        privileged: true
        capabilities:
          add:
            - ALL
      readinessProbe:
        exec:
          command: ["buildctl", "debug", "workers"]
      volumeMounts:
        - mountPath: /var/run/buildkit
          name: dagger-socket
        - mountPath: /var/lib/dagger
          name: dagger-storage
      env:
        - name: DAGGER_CLOUD_TOKEN
          value: $(params.dagger-cloud-token)
  steps:
  - name: read
    image: docker:dind
    workingDir: $(workspaces.source.path)
    script: |
      #!/usr/bin/env sh
      apk add nodejs npm curl
      curl https://dl.dagger.io/dagger/install.sh | BIN_DIR=/usr/local/bin sh
      npm i @dagger.io/dagger@latest
      dagger run node ./ci/index.mjs
    volumeMounts:
      - mountPath: /var/run/dagger
        name: dagger-socket
    env:
      - name: _EXPERIMENTAL_DAGGER_RUNNER_HOST
        value: unix:///var/run/dagger/buildkitd.sock
      - name: DAGGER_CLOUD_TOKEN
        value: $(params.dagger-cloud-token)
